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

Method mkdir

Lib/zipfile/__init__.py:2022–2055  ·  view source on GitHub ↗

Creates a directory inside the zip archive.

(self, zinfo_or_directory_name, mode=511)

Source from the content-addressed store, hash-verified

2020 dest.write(data)
2021
2022 def mkdir(self, zinfo_or_directory_name, mode=511):
2023 """Creates a directory inside the zip archive."""
2024 if isinstance(zinfo_or_directory_name, ZipInfo):
2025 zinfo = zinfo_or_directory_name
2026 if not zinfo.is_dir():
2027 raise ValueError("The given ZipInfo does not describe a directory")
2028 elif isinstance(zinfo_or_directory_name, str):
2029 directory_name = zinfo_or_directory_name
2030 if not directory_name.endswith("/"):
2031 directory_name += "/"
2032 zinfo = ZipInfo(directory_name)
2033 zinfo.compress_size = 0
2034 zinfo.CRC = 0
2035 zinfo.external_attr = ((0o40000 | mode) & 0xFFFF) << 16
2036 zinfo.file_size = 0
2037 zinfo.external_attr |= 0x10
2038 else:
2039 raise TypeError("Expected type str or ZipInfo")
2040
2041 with self._lock:
2042 if self._seekable:
2043 self.fp.seek(self.start_dir)
2044 zinfo.header_offset = self.fp.tell() # Start of header bytes
2045 if zinfo.compress_type == ZIP_LZMA:
2046 # Compressed data includes an end-of-stream (EOS) marker
2047 zinfo.flag_bits |= _MASK_COMPRESS_OPTION_1
2048
2049 self._writecheck(zinfo)
2050 self._didModify = True
2051
2052 self.filelist.append(zinfo)
2053 self.NameToInfo[zinfo.filename] = zinfo
2054 self.fp.write(zinfo.FileHeader(False))
2055 self.start_dir = self.fp.tell()
2056
2057 def __del__(self):
2058 """Call the "close()" method in case the user forgot."""

Callers 3

writeMethod · 0.95
_extract_memberMethod · 0.45

Calls 9

is_dirMethod · 0.95
_writecheckMethod · 0.95
FileHeaderMethod · 0.95
ZipInfoClass · 0.85
endswithMethod · 0.45
seekMethod · 0.45
tellMethod · 0.45
appendMethod · 0.45
writeMethod · 0.45

Tested by 1