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

Function _unpack_zipfile

Lib/shutil.py:1312–1340  ·  view source on GitHub ↗

Unpack zip `filename` to `extract_dir`

(filename, extract_dir)

Source from the content-addressed store, hash-verified

1310 os.makedirs(dirname)
1311
1312def _unpack_zipfile(filename, extract_dir):
1313 """Unpack zip `filename` to `extract_dir`
1314 """
1315 import zipfile # late import for breaking circular dependency
1316
1317 if not zipfile.is_zipfile(filename):
1318 raise ReadError("%s is not a zip file" % filename)
1319
1320 zip = zipfile.ZipFile(filename)
1321 try:
1322 for info in zip.infolist():
1323 name = info.filename
1324
1325 # don't extract absolute paths or ones with .. in them
1326 if name.startswith('/') or '..' in name:
1327 continue
1328
1329 targetpath = os.path.join(extract_dir, *name.split('/'))
1330 if not targetpath:
1331 continue
1332
1333 _ensure_directory(targetpath)
1334 if not name.endswith('/'):
1335 # file
1336 with zip.open(name, 'r') as source, \
1337 open(targetpath, 'wb') as target:
1338 copyfileobj(source, target)
1339 finally:
1340 zip.close()
1341
1342def _unpack_tarfile(filename, extract_dir, *, filter=None):
1343 """Unpack tar/tar.gz/tar.bz2/tar.xz/tar.zst `filename` to `extract_dir`

Callers

nothing calls this directly

Calls 11

infolistMethod · 0.95
openMethod · 0.95
closeMethod · 0.95
_ensure_directoryFunction · 0.85
ReadErrorClass · 0.70
openFunction · 0.70
copyfileobjFunction · 0.70
startswithMethod · 0.45
joinMethod · 0.45
splitMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…