summaryrefslogtreecommitdiff
path: root/src/wheel
diff options
context:
space:
mode:
authorHood Chatham <roberthoodchatham@gmail.com>2021-12-22 02:13:50 -0800
committerGitHub <noreply@github.com>2021-12-22 12:13:50 +0200
commit5846dacf8d4d48ad9278ded327cbb5f0917a238b (patch)
tree6e037a324271f7a903ccd212d038e67a2194cfbb /src/wheel
parent0acd203cd896afec7f715aa2ff5980a403459a3b (diff)
downloadwheel-git-5846dacf8d4d48ad9278ded327cbb5f0917a238b.tar.gz
Support unpacking wheels that contain files with commas in their names (#427)
The csv module is now being used to read RECORD. Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
Diffstat (limited to 'src/wheel')
-rw-r--r--src/wheel/wheelfile.py46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py
index 3ee97dd..21e7361 100644
--- a/src/wheel/wheelfile.py
+++ b/src/wheel/wheelfile.py
@@ -5,6 +5,7 @@ import hashlib
import os.path
import re
import stat
+import sys
import time
from collections import OrderedDict
from distutils import log as logger
@@ -13,6 +14,16 @@ from zipfile import ZIP_DEFLATED, ZipInfo, ZipFile
from wheel.cli import WheelError
from wheel.util import urlsafe_b64decode, as_unicode, native, urlsafe_b64encode, as_bytes, StringIO
+if sys.version_info >= (3,):
+ from io import TextIOWrapper
+
+ def read_csv(fp):
+ return csv.reader(TextIOWrapper(fp, newline='', encoding='utf-8'))
+else:
+ def read_csv(fp):
+ for line in csv.reader(fp):
+ yield [column.decode('utf-8') for column in line]
+
# Non-greedy matching of an optional build number may be too clever (more
# invalid wheel filenames will match). Separate regex for .dist-info?
WHEEL_INFO_RE = re.compile(
@@ -60,23 +71,24 @@ class WheelFile(ZipFile):
raise WheelError('Missing {} file'.format(self.record_path))
with record:
- for line in record:
- line = line.decode('utf-8')
- path, hash_sum, size = line.rsplit(u',', 2)
- if hash_sum:
- algorithm, hash_sum = hash_sum.split(u'=')
- try:
- hashlib.new(algorithm)
- except ValueError:
- raise WheelError('Unsupported hash algorithm: {}'.format(algorithm))
-
- if algorithm.lower() in {'md5', 'sha1'}:
- raise WheelError(
- 'Weak hash algorithm ({}) is not permitted by PEP 427'
- .format(algorithm))
-
- self._file_hashes[path] = (
- algorithm, urlsafe_b64decode(hash_sum.encode('ascii')))
+ for line in read_csv(record):
+ path, hash_sum, size = line
+ if not hash_sum:
+ continue
+
+ algorithm, hash_sum = hash_sum.split(u'=')
+ try:
+ hashlib.new(algorithm)
+ except ValueError:
+ raise WheelError('Unsupported hash algorithm: {}'.format(algorithm))
+
+ if algorithm.lower() in {'md5', 'sha1'}:
+ raise WheelError(
+ 'Weak hash algorithm ({}) is not permitted by PEP 427'
+ .format(algorithm))
+
+ self._file_hashes[path] = (
+ algorithm, urlsafe_b64decode(hash_sum.encode('ascii')))
def open(self, name_or_info, mode="r", pwd=None):
def _update_crc(newdata, eof=None):