parameters: (filename, archive_format)
docstring: Open a tar or zip archive for write, with the given format, and return it.
  
      The type of archive is determined by the "archive_format" parameter, which should be
      "tar", "tgz" (for gzipped tar) or "zip".
docstring_summary: Open a tar or zip archive for write, with the given format, and return it.
docstring_tokens: Open a tar or zip archive for write with the given format and return it .
function: def open_archive_for_write(filename, archive_format):
      '''Open a tar or zip archive for write, with the given format, and return it.
  
      The type of archive is determined by the "archive_format" parameter, which should be
      "tar", "tgz" (for gzipped tar) or "zip".
      '''
  
      if archive_format in ('tar', 'tgz'):
          import tarfile
          mode = 'w'
          if archive_format is 'tgz':
              mode += '|gz'
          return tarfile.open(filename, mode)
      if archive_format is 'zip':
          import zipfile
          # Infuriatingly, Zipfile calls the "add" method "write", but they're otherwise identical,
          # for our purposes.  WrappedZipFile is a minimal adapter class.
          class WrappedZipFile(zipfile.ZipFile):
              def add(self, filename, arcname):
                  return self.write(filename, arcname)
          return WrappedZipFile(filename, 'w', zipfile.ZIP_DEFLATED)
      raise ValueError('Unsupported archive format "%s"' % archive_format)
function_tokens: def open_archive_for_write ( filename , archive_format ) : if archive_format in ( 'tar' , 'tgz' ) : import tarfile mode = 'w' if archive_format is 'tgz' : mode += '|gz' return tarfile . open ( filename , mode ) if archive_format is 'zip' : import zipfile # Infuriatingly, Zipfile calls the "add" method "write", but they're otherwise identical, # for our purposes.  WrappedZipFile is a minimal adapter class. class WrappedZipFile ( zipfile . ZipFile ) : def add ( self , filename , arcname ) : return self . write ( filename , arcname ) return WrappedZipFile ( filename , 'w' , zipfile . ZIP_DEFLATED ) raise ValueError ( 'Unsupported archive format "%s"' % archive_format )