Unpack zip `filename` to `extract_dir`
(filename, extract_dir)
| 1234 | os.makedirs(dirname) |
| 1235 | |
| 1236 | def _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 | |
| 1266 | def _unpack_tarfile(filename, extract_dir, *, filter=None): |
| 1267 | """Unpack tar/tar.gz/tar.bz2/tar.xz `filename` to `extract_dir` |
nothing calls this directly
no test coverage detected