Unpack zip `filename` to `extract_dir`
(filename, extract_dir)
| 1310 | os.makedirs(dirname) |
| 1311 | |
| 1312 | def _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 | |
| 1342 | def _unpack_tarfile(filename, extract_dir, *, filter=None): |
| 1343 | """Unpack tar/tar.gz/tar.bz2/tar.xz/tar.zst `filename` to `extract_dir` |
nothing calls this directly
no test coverage detected
searching dependent graphs…