MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _unpack_zipfile

Function _unpack_zipfile

tools/python-3.11.9-amd64/Lib/shutil.py:1236–1264  ·  view source on GitHub ↗

Unpack zip `filename` to `extract_dir`

(filename, extract_dir)

Source from the content-addressed store, hash-verified

1234 os.makedirs(dirname)
1235
1236def _unpack_zipfile(filename, extract_dir):
1237 """Unpack zip `filename` to `extract_dir`
1238 """
1239 import zipfile # late import for breaking circular dependency
1240
1241 if not zipfile.is_zipfile(filename):
1242 raise ReadError("%s is not a zip file" % filename)
1243
1244 zip = zipfile.ZipFile(filename)
1245 try:
1246 for info in zip.infolist():
1247 name = info.filename
1248
1249 # don't extract absolute paths or ones with .. in them
1250 if name.startswith('/') or '..' in name:
1251 continue
1252
1253 targetpath = os.path.join(extract_dir, *name.split('/'))
1254 if not targetpath:
1255 continue
1256
1257 _ensure_directory(targetpath)
1258 if not name.endswith('/'):
1259 # file
1260 with zip.open(name, 'r') as source, \
1261 open(targetpath, 'wb') as target:
1262 copyfileobj(source, target)
1263 finally:
1264 zip.close()
1265
1266def _unpack_tarfile(filename, extract_dir, *, filter=None):
1267 """Unpack tar/tar.gz/tar.bz2/tar.xz `filename` to `extract_dir`

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected