MCPcopy Index your code
hub / github.com/RustPython/RustPython / _unpack_zipfile

Function _unpack_zipfile

Lib/shutil.py:1309–1337  ·  view source on GitHub ↗

Unpack zip `filename` to `extract_dir`

(filename, extract_dir)

Source from the content-addressed store, hash-verified

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