diff options
author | Tzu-ping Chung <uranusjr@gmail.com> | 2020-08-03 14:59:42 +0800 |
---|---|---|
committer | Tzu-ping Chung <uranusjr@gmail.com> | 2020-08-03 15:00:58 +0800 |
commit | a12e2f147997dd0932727150ae596ca489a41e78 (patch) | |
tree | 08f740b9ff59ae4aebc705bb8d5b027976de9d97 | |
parent | d4995cb89eed0a2d348e220c6ef061b3d816e0f4 (diff) | |
download | pip-a12e2f147997dd0932727150ae596ca489a41e78.tar.gz |
PEP 427 mandates UTF-8, we don't need the fallback
-rw-r--r-- | news/8684.bugfix | 4 | ||||
-rw-r--r-- | src/pip/_internal/operations/install/wheel.py | 21 |
2 files changed, 6 insertions, 19 deletions
diff --git a/news/8684.bugfix b/news/8684.bugfix index 18e6ed9bc..528291d73 100644 --- a/news/8684.bugfix +++ b/news/8684.bugfix @@ -1,2 +1,2 @@ -Use the same encoding logic from Python 3 to handle ZIP archive entries on -Python 2, so non-ASCII paths can be resolved as expected. +Use UTF-8 to handle ZIP archive entries on Python 2 according to PEP 427, so +non-ASCII paths can be resolved as expected. diff --git a/src/pip/_internal/operations/install/wheel.py b/src/pip/_internal/operations/install/wheel.py index f2fde0b08..e91b1b8d5 100644 --- a/src/pip/_internal/operations/install/wheel.py +++ b/src/pip/_internal/operations/install/wheel.py @@ -425,23 +425,10 @@ class ZipBackedFile(object): # type: () -> ZipInfo if not PY2: return self._zip_file.getinfo(self.src_record_path) - - # Python 2 does not expose a way to detect a ZIP's encoding, so we - # "guess" with the heuristics below: - # 1. Try encoding the path with UTF-8. - # 2. Check the matching info's flags for language encoding (bit 11). - # 3. If the flag is set, assume UTF-8 is correct. - # 4. If any of the above steps fails, fallback to getting an info with - # CP437 (matching Python 3). - try: - arcname = self.src_record_path.encode("utf-8") - info = self._zip_file.getinfo(arcname) - if info.flag_bits & 0x800: - return info - except (KeyError, UnicodeEncodeError): - pass - arcname = self.src_record_path.encode("cp437") - return self._zip_file.getinfo(arcname) + # Python 2 does not expose a way to detect a ZIP's encoding, but the + # wheel specification (PEP 427) explicitly mandates that paths should + # use UTF-8, so we assume it is true. + return self._zip_file.getinfo(self.src_record_path.encode("utf-8")) def save(self): # type: () -> None |