Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/virtualenv/util/zipapp.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
| author | shellac |
|---|---|
| date | Mon, 22 Mar 2021 18:12:50 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4f3585e2f14b |
|---|---|
| 1 from __future__ import absolute_import, unicode_literals | |
| 2 | |
| 3 import logging | |
| 4 import os | |
| 5 import zipfile | |
| 6 | |
| 7 from virtualenv.info import IS_WIN, ROOT | |
| 8 from virtualenv.util.six import ensure_text | |
| 9 | |
| 10 | |
| 11 def read(full_path): | |
| 12 sub_file = _get_path_within_zip(full_path) | |
| 13 with zipfile.ZipFile(ROOT, "r") as zip_file: | |
| 14 with zip_file.open(sub_file) as file_handler: | |
| 15 return file_handler.read().decode("utf-8") | |
| 16 | |
| 17 | |
| 18 def extract(full_path, dest): | |
| 19 logging.debug("extract %s to %s", full_path, dest) | |
| 20 sub_file = _get_path_within_zip(full_path) | |
| 21 with zipfile.ZipFile(ROOT, "r") as zip_file: | |
| 22 info = zip_file.getinfo(sub_file) | |
| 23 info.filename = dest.name | |
| 24 zip_file.extract(info, ensure_text(str(dest.parent))) | |
| 25 | |
| 26 | |
| 27 def _get_path_within_zip(full_path): | |
| 28 full_path = os.path.abspath(str(full_path)) | |
| 29 sub_file = full_path[len(ROOT) + 1 :] | |
| 30 if IS_WIN: | |
| 31 # paths are always UNIX separators, even on Windows, though __file__ still follows platform default | |
| 32 sub_file = sub_file.replace(os.sep, "/") | |
| 33 return sub_file |
