|
5 | 5 | import os.path |
6 | 6 | import re |
7 | 7 | import stat |
| 8 | +import sys |
8 | 9 | import time |
9 | 10 | from collections import OrderedDict |
10 | 11 | from distutils import log as logger |
|
13 | 14 | from wheel.cli import WheelError |
14 | 15 | from wheel.util import urlsafe_b64decode, as_unicode, native, urlsafe_b64encode, as_bytes, StringIO |
15 | 16 |
|
| 17 | +if sys.version_info >= (3,): |
| 18 | + from io import TextIOWrapper |
| 19 | + |
| 20 | + def read_csv(fp): |
| 21 | + return csv.reader(TextIOWrapper(fp, newline='', encoding='utf-8')) |
| 22 | +else: |
| 23 | + def read_csv(fp): |
| 24 | + for line in csv.reader(fp): |
| 25 | + yield [column.decode('utf-8') for column in line] |
| 26 | + |
16 | 27 | # Non-greedy matching of an optional build number may be too clever (more |
17 | 28 | # invalid wheel filenames will match). Separate regex for .dist-info? |
18 | 29 | WHEEL_INFO_RE = re.compile( |
@@ -60,23 +71,24 @@ def __init__(self, file, mode='r', compression=ZIP_DEFLATED): |
60 | 71 | raise WheelError('Missing {} file'.format(self.record_path)) |
61 | 72 |
|
62 | 73 | with record: |
63 | | - for line in record: |
64 | | - line = line.decode('utf-8') |
65 | | - path, hash_sum, size = line.rsplit(u',', 2) |
66 | | - if hash_sum: |
67 | | - algorithm, hash_sum = hash_sum.split(u'=') |
68 | | - try: |
69 | | - hashlib.new(algorithm) |
70 | | - except ValueError: |
71 | | - raise WheelError('Unsupported hash algorithm: {}'.format(algorithm)) |
72 | | - |
73 | | - if algorithm.lower() in {'md5', 'sha1'}: |
74 | | - raise WheelError( |
75 | | - 'Weak hash algorithm ({}) is not permitted by PEP 427' |
76 | | - .format(algorithm)) |
77 | | - |
78 | | - self._file_hashes[path] = ( |
79 | | - algorithm, urlsafe_b64decode(hash_sum.encode('ascii'))) |
| 74 | + for line in read_csv(record): |
| 75 | + path, hash_sum, size = line |
| 76 | + if not hash_sum: |
| 77 | + continue |
| 78 | + |
| 79 | + algorithm, hash_sum = hash_sum.split(u'=') |
| 80 | + try: |
| 81 | + hashlib.new(algorithm) |
| 82 | + except ValueError: |
| 83 | + raise WheelError('Unsupported hash algorithm: {}'.format(algorithm)) |
| 84 | + |
| 85 | + if algorithm.lower() in {'md5', 'sha1'}: |
| 86 | + raise WheelError( |
| 87 | + 'Weak hash algorithm ({}) is not permitted by PEP 427' |
| 88 | + .format(algorithm)) |
| 89 | + |
| 90 | + self._file_hashes[path] = ( |
| 91 | + algorithm, urlsafe_b64decode(hash_sum.encode('ascii'))) |
80 | 92 |
|
81 | 93 | def open(self, name_or_info, mode="r", pwd=None): |
82 | 94 | def _update_crc(newdata, eof=None): |
|
0 commit comments