MCPcopy Index your code
hub / github.com/python/cpython / close

Method close

Lib/zipfile/__init__.py:2061–2081  ·  view source on GitHub ↗

Close the file, and for mode 'w', 'x' and 'a' write the ending records.

(self)

Source from the content-addressed store, hash-verified

2059 self.close()
2060
2061 def close(self):
2062 """Close the file, and for mode 'w', 'x' and 'a' write the ending
2063 records."""
2064 if self.fp is None:
2065 return
2066
2067 if self._writing:
2068 raise ValueError("Can't close the ZIP file while there is "
2069 "an open writing handle on it. "
2070 "Close the writing handle before closing the zip.")
2071
2072 try:
2073 if self.mode in ('w', 'x', 'a') and self._didModify: # write ending records
2074 with self._lock:
2075 if self._seekable:
2076 self.fp.seek(self.start_dir)
2077 self._write_end_record()
2078 finally:
2079 fp = self.fp
2080 self.fp = None
2081 self._fpclose(fp)
2082
2083 def _write_end_record(self):
2084 for zinfo in self.filelist: # write central directory

Callers 15

_unpack_zipfileFunction · 0.95
test_getdata_zipfileMethod · 0.95
test_too_many_filesMethod · 0.95
test_empty_zipfileMethod · 0.95
__exit__Method · 0.95
__del__Method · 0.95
closeMethod · 0.45
closeMethod · 0.45

Calls 3

_write_end_recordMethod · 0.95
_fpcloseMethod · 0.95
seekMethod · 0.45