def close(self):
if self.fp is None:<EOL><INDENT>return<EOL><DEDENT>if self.mode in ("<STR_LIT:w>", "<STR_LIT:a>") and self._didModify: <EOL><INDENT>count = <NUM_LIT:0><EOL>pos1 = self.fp.tell()<EOL>for zinfo in self.filelist:         <EOL><INDENT>count = count + <NUM_LIT:1><EOL>dt = zinfo.date_time<EOL>dosdate = (dt[<NUM_LIT:0>] - <NUM_LIT>) << <NUM_LIT:9> | dt[<NUM_LIT:1>] << <NUM_LIT:5> | dt[<NUM_LIT:2>]<EOL>dostime = dt[<NUM_LIT:3>] << <NUM_LIT:11> | dt[<NUM_LIT:4>] << <NUM_LIT:5> | (dt[<NUM_LIT:5>] // <NUM_LIT:2>)<EOL>extra = []<EOL>if zinfo.file_size > ZIP64_LIMITor zinfo.compress_size > ZIP64_LIMIT:<EOL><INDENT>extra.append(zinfo.file_size)<EOL>extra.append(zinfo.compress_size)<EOL>file_size = <NUM_LIT><EOL>compress_size = <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>file_size = zinfo.file_size<EOL>compress_size = zinfo.compress_size<EOL><DEDENT>if zinfo.header_offset > ZIP64_LIMIT:<EOL><INDENT>extra.append(zinfo.header_offset)<EOL>header_offset = <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>header_offset = zinfo.header_offset<EOL><DEDENT>extra_data = zinfo.extra<EOL>if extra:<EOL><INDENT>extra_data = struct.pack(<EOL>'<STR_LIT>' + '<STR_LIT>'*len(extra),<EOL><NUM_LIT:1>, <NUM_LIT:8>*len(extra), *extra) + extra_data<EOL>extract_version = max(<NUM_LIT>, zinfo.extract_version)<EOL>create_version = max(<NUM_LIT>, zinfo.create_version)<EOL><DEDENT>else:<EOL><INDENT>extract_version = zinfo.extract_version<EOL>create_version = zinfo.create_version<EOL><DEDENT>try:<EOL><INDENT>filename, flag_bits = zinfo._encodeFilenameFlags()<EOL>centdir = struct.pack(structCentralDir,<EOL>stringCentralDir, create_version,<EOL>zinfo.create_system, extract_version, zinfo.reserved,<EOL>flag_bits, zinfo.compress_type, dostime, dosdate,<EOL>zinfo.CRC, compress_size, file_size,<EOL>len(filename), len(extra_data), len(zinfo.comment),<EOL><NUM_LIT:0>, zinfo.internal_attr, zinfo.external_attr,<EOL>header_offset)<EOL><DEDENT>except DeprecationWarning:<EOL><INDENT>print((structCentralDir,<EOL>stringCentralDir, create_version,<EOL>zinfo.create_system, extract_version, zinfo.reserved,<EOL>zinfo.flag_bits, zinfo.compress_type, dostime, dosdate,<EOL>zinfo.CRC, compress_size, file_size,<EOL>len(zinfo.filename), len(extra_data), len(zinfo.comment),<EOL><NUM_LIT:0>, zinfo.internal_attr, zinfo.external_attr,<EOL>header_offset), file=sys.stderr)<EOL>raise<EOL><DEDENT>self.fp.write(centdir)<EOL>self.fp.write(filename)<EOL>self.fp.write(extra_data)<EOL>self.fp.write(zinfo.comment)<EOL><DEDENT>pos2 = self.fp.tell()<EOL>centDirCount = count<EOL>centDirSize = pos2 - pos1<EOL>centDirOffset = pos1<EOL>if (centDirCount >= ZIP_FILECOUNT_LIMIT or<EOL>centDirOffset > ZIP64_LIMIT or<EOL>centDirSize > ZIP64_LIMIT):<EOL><INDENT>zip64endrec = struct.pack(<EOL>structEndArchive64, stringEndArchive64,<EOL><NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT:0>, <NUM_LIT:0>, centDirCount, centDirCount,<EOL>centDirSize, centDirOffset)<EOL>self.fp.write(zip64endrec)<EOL>zip64locrec = struct.pack(<EOL>structEndArchive64Locator,<EOL>stringEndArchive64Locator, <NUM_LIT:0>, pos2, <NUM_LIT:1>)<EOL>self.fp.write(zip64locrec)<EOL>centDirCount = min(centDirCount, <NUM_LIT>)<EOL>centDirSize = min(centDirSize, <NUM_LIT>)<EOL>centDirOffset = min(centDirOffset, <NUM_LIT>)<EOL><DEDENT>if len(self.comment) >= ZIP_MAX_COMMENT:<EOL><INDENT>if self.debug > <NUM_LIT:0>:<EOL><INDENT>msg = '<STR_LIT>'% ZIP_MAX_COMMENT<EOL><DEDENT>self.comment = self.comment[:ZIP_MAX_COMMENT]<EOL><DEDENT>endrec = struct.pack(structEndArchive, stringEndArchive,<EOL><NUM_LIT:0>, <NUM_LIT:0>, centDirCount, centDirCount,<EOL>centDirSize, centDirOffset, len(self.comment))<EOL>self.fp.write(endrec)<EOL>self.fp.write(self.comment)<EOL>self.fp.flush()<EOL><DEDENT>if not self._filePassed:<EOL><INDENT>self.fp.close()<EOL><DEDENT>self.fp = None<EOL>
Close the file, and for mode "w" and "a" write the ending
        records.