parameters: (self)
docstring: Close the file, and for mode "w" and "a" write the ending
      records.
  
      Overwritten to compact overwritten entries.
docstring_summary: Close the file, and for mode "w" and "a" write the ending
      records.
docstring_tokens: Close the file and for mode w and a write the ending records .
function: def close(self):
      """Close the file, and for mode "w" and "a" write the ending
      records.
  
      Overwritten to compact overwritten entries.
      """
      if not self._remove:
        # we don't have anything special to do, let's just call base
        r = zipfile.ZipFile.close(self)
        self.lockfile = None
        return r
  
      if self.fp.mode != 'r+b':
        # adjust file mode if we originally just wrote, now we rewrite
        self.fp.close()
        self.fp = open(self.filename, 'r+b')
      all = map(lambda zi: (zi, True), self.filelist) + \
          map(lambda zi: (zi, False), self._remove)
      all.sort(lambda l, r: cmp(l[0].header_offset, r[0].header_offset))
      # empty _remove for multiple closes
      self._remove = []
  
      lengths = [all[i+1][0].header_offset - all[i][0].header_offset
                 for i in xrange(len(all)-1)]
      lengths.append(self.end - all[-1][0].header_offset)
      to_pos = 0
      for (zi, keep), length in zip(all, lengths):
        if not keep:
          continue
        oldoff = zi.header_offset
        # python <= 2.4 has file_offset
        if hasattr(zi, 'file_offset'):
          zi.file_offset = zi.file_offset + to_pos - oldoff
        zi.header_offset = to_pos
        self.fp.seek(oldoff)
        content = self.fp.read(length)
        self.fp.seek(to_pos)
        self.fp.write(content)
        to_pos += length
      self.fp.truncate()
      zipfile.ZipFile.close(self)
      self.lockfile = None
function_tokens: def close ( self ) : if not self . _remove : # we don't have anything special to do, let's just call base r = zipfile . ZipFile . close ( self ) self . lockfile = None return r if self . fp . mode != 'r+b' : # adjust file mode if we originally just wrote, now we rewrite self . fp . close ( ) self . fp = open ( self . filename , 'r+b' ) all = map ( lambda zi : ( zi , True ) , self . filelist ) + map ( lambda zi : ( zi , False ) , self . _remove ) all . sort ( lambda l , r : cmp ( l [ 0 ] . header_offset , r [ 0 ] . header_offset ) ) # empty _remove for multiple closes self . _remove = [ ] lengths = [ all [ i + 1 ] [ 0 ] . header_offset - all [ i ] [ 0 ] . header_offset for i in xrange ( len ( all ) - 1 ) ] lengths . append ( self . end - all [ - 1 ] [ 0 ] . header_offset ) to_pos = 0 for ( zi , keep ) , length in zip ( all , lengths ) : if not keep : continue oldoff = zi . header_offset # python <= 2.4 has file_offset if hasattr ( zi , 'file_offset' ) : zi . file_offset = zi . file_offset + to_pos - oldoff zi . header_offset = to_pos self . fp . seek ( oldoff ) content = self . fp . read ( length ) self . fp . seek ( to_pos ) self . fp . write ( content ) to_pos += length self . fp . truncate ( ) zipfile . ZipFile . close ( self ) self . lockfile = None