parameters: (self, zinfo_or_arcname, data,
                   compress_type=None, compresslevel=None)
docstring: Write a file into the archive.  The contents is 'data', which
          may be either a 'str' or a 'bytes' instance; if it is a 'str',
          it is encoded as UTF-8 first.
          'zinfo_or_arcname' is either a ZipInfo instance or
          the name of the file in the archive.
docstring_summary: Write a file into the archive.  The contents is 'data', which
          may be either a 'str' or a 'bytes' instance; if it is a 'str',
          it is encoded as UTF-8 first.
          'zinfo_or_arcname' is either a ZipInfo instance or
          the name of the file in the archive.
docstring_tokens: Write a file into the archive . The contents is data which may be either a str or a bytes instance ; if it is a str it is encoded as UTF - 8 first . zinfo_or_arcname is either a ZipInfo instance or the name of the file in the archive .
function: def writestr(self, zinfo_or_arcname, data,
                   compress_type=None, compresslevel=None):
          """Write a file into the archive.  The contents is 'data', which
          may be either a 'str' or a 'bytes' instance; if it is a 'str',
          it is encoded as UTF-8 first.
          'zinfo_or_arcname' is either a ZipInfo instance or
          the name of the file in the archive."""
          if isinstance(data, str):
              data = data.encode("utf-8")
          if not isinstance(zinfo_or_arcname, ZipInfo):
              zinfo = ZipInfo(filename=zinfo_or_arcname,
                              date_time=time.localtime(time.time())[:6])
              zinfo.compress_type = self.compression
              zinfo._compresslevel = self.compresslevel
              if zinfo.filename[-1] == '/':
                  zinfo.external_attr = 0o40775 << 16   # drwxrwxr-x
                  zinfo.external_attr |= 0x10           # MS-DOS directory flag
              else:
                  zinfo.external_attr = 0o600 << 16     # ?rw-------
          else:
              zinfo = zinfo_or_arcname
  
          if not self.fp:
              raise ValueError(
                  "Attempt to write to ZIP archive that was already closed")
          if self._writing:
              raise ValueError(
                  "Can't write to ZIP archive while an open writing handle exists."
              )
  
          if compress_type is not None:
              zinfo.compress_type = compress_type
  
          if compresslevel is not None:
              zinfo._compresslevel = compresslevel
  
          zinfo.file_size = len(data)            # Uncompressed size
          with self._lock:
              with self.open(zinfo, mode='w') as dest:
                  dest.write(data)
function_tokens: def writestr ( self , zinfo_or_arcname , data , compress_type = None , compresslevel = None ) : if isinstance ( data , str ) : data = data . encode ( "utf-8" ) if not isinstance ( zinfo_or_arcname , ZipInfo ) : zinfo = ZipInfo ( filename = zinfo_or_arcname , date_time = time . localtime ( time . time ( ) ) [ : 6 ] ) zinfo . compress_type = self . compression zinfo . _compresslevel = self . compresslevel if zinfo . filename [ - 1 ] == '/' : zinfo . external_attr = 0o40775 << 16 # drwxrwxr-x zinfo . external_attr |= 0x10 # MS-DOS directory flag else : zinfo . external_attr = 0o600 << 16 # ?rw------- else : zinfo = zinfo_or_arcname if not self . fp : raise ValueError ( "Attempt to write to ZIP archive that was already closed" ) if self . _writing : raise ValueError ( "Can't write to ZIP archive while an open writing handle exists." ) if compress_type is not None : zinfo . compress_type = compress_type if compresslevel is not None : zinfo . _compresslevel = compresslevel zinfo . file_size = len ( data ) # Uncompressed size with self . _lock : with self . open ( zinfo , mode = 'w' ) as dest : dest . write ( data )