Unpack zip `filename` to `extract_dir`
(filename, extract_dir)
| 1307 | os.makedirs(dirname) |
| 1308 | |
| 1309 | def _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 | |
| 1339 | def _unpack_tarfile(filename, extract_dir, *, filter=None): |
| 1340 | """Unpack tar/tar.gz/tar.bz2/tar.xz/tar.zst `filename` to `extract_dir` |
nothing calls this directly
no test coverage detected