From 4190788e9885737ce912f0401b03e194139ec684 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 15 Dec 2021 14:12:25 -0800 Subject: [PATCH 01/16] Fix support for unpacking wheels that contain files with commas in their names --- src/wheel/wheelfile.py | 3 +++ tests/conftest.py | 2 +- .../commasinfilenames.dist/mypackage/__init__.py | 0 .../commasinfilenames.dist/mypackage/data/1,2,3.txt | 0 .../mypackage/data/__init__.py | 0 tests/testdata/commasinfilenames.dist/setup.py | 12 ++++++++++++ .../testrepo-0.1.0/mypackage/__init__.py | 0 7 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/testdata/commasinfilenames.dist/mypackage/__init__.py create mode 100644 tests/testdata/commasinfilenames.dist/mypackage/data/1,2,3.txt create mode 100644 tests/testdata/commasinfilenames.dist/mypackage/data/__init__.py create mode 100644 tests/testdata/commasinfilenames.dist/setup.py create mode 100644 tests/testdata/commasinfilenames.dist/testrepo-0.1.0/mypackage/__init__.py diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 3ee97ddd..2545e899 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -75,6 +75,9 @@ def __init__(self, file, mode='r', compression=ZIP_DEFLATED): 'Weak hash algorithm ({}) is not permitted by PEP 427' .format(algorithm)) + if path.startswith('"') and path.endswith('"'): + path = path[1:-1] + self._file_hashes[path] = ( algorithm, urlsafe_b64decode(hash_sum.encode('ascii'))) diff --git a/tests/conftest.py b/tests/conftest.py index 7c3698c6..d9821b83 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,7 +12,7 @@ @pytest.fixture(scope='session') def wheels_and_eggs(tmpdir_factory): """Build wheels and eggs from test distributions.""" - test_distributions = "complex-dist", "simple.dist", "headers.dist" + test_distributions = "complex-dist", "simple.dist", "headers.dist", "commasinfilenames.dist" if sys.version_info >= (3, 6): # Only Python 3.6+ can handle packaging unicode file names reliably # across different platforms diff --git a/tests/testdata/commasinfilenames.dist/mypackage/__init__.py b/tests/testdata/commasinfilenames.dist/mypackage/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/testdata/commasinfilenames.dist/mypackage/data/1,2,3.txt b/tests/testdata/commasinfilenames.dist/mypackage/data/1,2,3.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/testdata/commasinfilenames.dist/mypackage/data/__init__.py b/tests/testdata/commasinfilenames.dist/mypackage/data/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/testdata/commasinfilenames.dist/setup.py b/tests/testdata/commasinfilenames.dist/setup.py new file mode 100644 index 00000000..8cf9e4ec --- /dev/null +++ b/tests/testdata/commasinfilenames.dist/setup.py @@ -0,0 +1,12 @@ +from setuptools import setup + +setup( + name='testrepo', + version='0.1', + packages=["mypackage"], + description='A test package with commas in file names', + include_package_data=True, + package_data={ + "mypackage.data": ["*"] + }, +) diff --git a/tests/testdata/commasinfilenames.dist/testrepo-0.1.0/mypackage/__init__.py b/tests/testdata/commasinfilenames.dist/testrepo-0.1.0/mypackage/__init__.py new file mode 100644 index 00000000..e69de29b From a92e4ce440df5f7365da042532aae92715e6185e Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 15 Dec 2021 14:56:46 -0800 Subject: [PATCH 02/16] Use csv library instead of hand parsing csv file --- src/wheel/util.py | 3 ++- src/wheel/wheelfile.py | 39 ++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/wheel/util.py b/src/wheel/util.py index 3ae2b445..dc59e159 100644 --- a/src/wheel/util.py +++ b/src/wheel/util.py @@ -7,6 +7,7 @@ text_type = unicode # noqa: F821 StringIO = io.BytesIO + TextIOWrapper = lambda bytes_io: bytes_io def native(s, encoding='utf-8'): if isinstance(s, unicode): # noqa: F821 @@ -16,13 +17,13 @@ def native(s, encoding='utf-8'): text_type = str StringIO = io.StringIO + TextIOWrapper = io.TextIOWrapper def native(s, encoding='utf-8'): if isinstance(s, bytes): return s.decode(encoding) return s - def urlsafe_b64encode(data): """urlsafe_b64encode without padding""" return base64.urlsafe_b64encode(data).rstrip(b'=') diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 2545e899..a820429f 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -11,7 +11,7 @@ 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 +from wheel.util import urlsafe_b64decode, as_unicode, native, urlsafe_b64encode, as_bytes, StringIO, TextIOWrapper # Non-greedy matching of an optional build number may be too clever (more # invalid wheel filenames will match). Separate regex for .dist-info? @@ -60,26 +60,23 @@ def __init__(self, file, mode='r', compression=ZIP_DEFLATED): 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)) - - if path.startswith('"') and path.endswith('"'): - path = path[1:-1] - - self._file_hashes[path] = ( - algorithm, urlsafe_b64decode(hash_sum.encode('ascii'))) + for line in csv.reader(TextIOWrapper(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): From 5565024969ec0bed358aeaab02bc77df561aeeb7 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 15 Dec 2021 14:59:01 -0800 Subject: [PATCH 03/16] Formatting --- src/wheel/wheelfile.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index a820429f..1f243794 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -64,6 +64,7 @@ def __init__(self, file, mode='r', compression=ZIP_DEFLATED): path, hash_sum, size = line if not hash_sum: continue + algorithm, hash_sum = hash_sum.split(u'=') try: hashlib.new(algorithm) @@ -74,6 +75,7 @@ def __init__(self, file, mode='r', compression=ZIP_DEFLATED): raise WheelError( 'Weak hash algorithm ({}) is not permitted by PEP 427' .format(algorithm)) + self._file_hashes[path] = ( algorithm, urlsafe_b64decode(hash_sum.encode('ascii'))) From f418f976d68f3492e86a42747c932a4f8bbc677e Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 15 Dec 2021 15:12:53 -0800 Subject: [PATCH 04/16] Fix formatter errors --- src/wheel/util.py | 5 ++++- src/wheel/wheelfile.py | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/wheel/util.py b/src/wheel/util.py index dc59e159..7509839e 100644 --- a/src/wheel/util.py +++ b/src/wheel/util.py @@ -7,7 +7,9 @@ text_type = unicode # noqa: F821 StringIO = io.BytesIO - TextIOWrapper = lambda bytes_io: bytes_io + + def TextIOWrapper(bytes_io): + return bytes_io def native(s, encoding='utf-8'): if isinstance(s, unicode): # noqa: F821 @@ -24,6 +26,7 @@ def native(s, encoding='utf-8'): return s.decode(encoding) return s + def urlsafe_b64encode(data): """urlsafe_b64encode without padding""" return base64.urlsafe_b64encode(data).rstrip(b'=') diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 1f243794..82007473 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -11,7 +11,15 @@ 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, TextIOWrapper +from wheel.util import ( + urlsafe_b64decode, + as_unicode, + native, + urlsafe_b64encode, + as_bytes, + StringIO, + TextIOWrapper +) # Non-greedy matching of an optional build number may be too clever (more # invalid wheel filenames will match). Separate regex for .dist-info? @@ -79,7 +87,6 @@ def __init__(self, file, mode='r', compression=ZIP_DEFLATED): 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): if eof is None: From edb731e6dab444285e3d5aea75fdd7d2edcfb732 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 15 Dec 2021 15:15:52 -0800 Subject: [PATCH 05/16] Remove trailing whitespace --- src/wheel/util.py | 2 +- src/wheel/wheelfile.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/wheel/util.py b/src/wheel/util.py index 7509839e..785ce45a 100644 --- a/src/wheel/util.py +++ b/src/wheel/util.py @@ -8,7 +8,7 @@ StringIO = io.BytesIO - def TextIOWrapper(bytes_io): + def TextIOWrapper(bytes_io): return bytes_io def native(s, encoding='utf-8'): diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 82007473..114d1ddd 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -12,12 +12,12 @@ from wheel.cli import WheelError from wheel.util import ( - urlsafe_b64decode, - as_unicode, - native, - urlsafe_b64encode, - as_bytes, - StringIO, + urlsafe_b64decode, + as_unicode, + native, + urlsafe_b64encode, + as_bytes, + StringIO, TextIOWrapper ) From 21a73b3c3a92c8f631ac80d29bba6837594820a0 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 15 Dec 2021 15:37:34 -0800 Subject: [PATCH 06/16] Update src/wheel/wheelfile.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alex Grönholm --- src/wheel/wheelfile.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 114d1ddd..3ec00024 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -12,14 +12,7 @@ from wheel.cli import WheelError from wheel.util import ( - urlsafe_b64decode, - as_unicode, - native, - urlsafe_b64encode, - as_bytes, - StringIO, - TextIOWrapper -) + urlsafe_b64decode, as_unicode, native, urlsafe_b64encode, as_bytes, StringIO, TextIOWrapper) # Non-greedy matching of an optional build number may be too clever (more # invalid wheel filenames will match). Separate regex for .dist-info? From 99fbb41c18182ccfaf8ca434c1a5b59a9cfb7681 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 15 Dec 2021 15:40:44 -0800 Subject: [PATCH 07/16] Remove unneeded TextIOWrapper Python 2 shim --- setup.cfg | 71 ------------------------------------------ src/wheel/util.py | 4 --- src/wheel/wheelfile.py | 1 + tests/conftest.py | 9 +++--- 4 files changed, 6 insertions(+), 79 deletions(-) delete mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 7f1a86fb..00000000 --- a/setup.cfg +++ /dev/null @@ -1,71 +0,0 @@ -[metadata] -name = wheel -version = attr: wheel.__version__ -description = A built-package format for Python -long_description = file: README.rst -classifiers = - Development Status :: 5 - Production/Stable - Intended Audience :: Developers - Topic :: System :: Archiving :: Packaging - License :: OSI Approved :: MIT License - Programming Language :: Python - Programming Language :: Python :: 2 - Programming Language :: Python :: 2.7 - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.5 - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 -author = Daniel Holth -author_email = dholth@fastmail.fm -maintainer = Alex Gronholm -maintainer_email = alex.gronholm@nextday.fi -url = https://github.com/pypa/wheel -project_urls = - Documentation = https://wheel.readthedocs.io/ - Changelog = https://wheel.readthedocs.io/en/stable/news.html - Issue Tracker = https://github.com/pypa/wheel/issues -keywords = wheel, packaging -license = MIT - -[options] -package_dir= - = src -packages = find: -python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* -setup_requires = setuptools >= 40.9.0 -zip_safe = False - -[options.packages.find] -where = src - -[options.extras_require] -test = - pytest >= 3.0.0 - pytest-cov - -[options.entry_points] -console_scripts = - wheel = wheel.cli:main -distutils.commands = - bdist_wheel = wheel.bdist_wheel:bdist_wheel - -[tool:pytest] -addopts = --cov --cov-config=setup.cfg -testpaths = tests - -[coverage:run] -source = wheel -omit = */vendored/* - -[coverage:report] -show_missing = true - -[flake8] -max-line-length = 99 - -[bdist_wheel] -# use py2.py3 tag for pure-python dist: -universal = 1 diff --git a/src/wheel/util.py b/src/wheel/util.py index 785ce45a..3ae2b445 100644 --- a/src/wheel/util.py +++ b/src/wheel/util.py @@ -8,9 +8,6 @@ StringIO = io.BytesIO - def TextIOWrapper(bytes_io): - return bytes_io - def native(s, encoding='utf-8'): if isinstance(s, unicode): # noqa: F821 return s.encode(encoding) @@ -19,7 +16,6 @@ def native(s, encoding='utf-8'): text_type = str StringIO = io.StringIO - TextIOWrapper = io.TextIOWrapper def native(s, encoding='utf-8'): if isinstance(s, bytes): diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 3ec00024..ff230735 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -2,6 +2,7 @@ import csv import hashlib +from io import TextIOWrapper import os.path import re import stat diff --git a/tests/conftest.py b/tests/conftest.py index d9821b83..c9eae617 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,20 +7,21 @@ import sys import pytest +sys.path.insert(0, "src") @pytest.fixture(scope='session') def wheels_and_eggs(tmpdir_factory): """Build wheels and eggs from test distributions.""" - test_distributions = "complex-dist", "simple.dist", "headers.dist", "commasinfilenames.dist" + test_distributions = ("commasinfilenames.dist",) if sys.version_info >= (3, 6): # Only Python 3.6+ can handle packaging unicode file names reliably # across different platforms test_distributions += ("unicode.dist",) - if sys.platform != 'win32': - # ABI3 extensions don't really work on Windows - test_distributions += ("abi3extension.dist",) + # if sys.platform != 'win32': + # # ABI3 extensions don't really work on Windows + # test_distributions += ("abi3extension.dist",) pwd = os.path.abspath(os.curdir) this_dir = os.path.dirname(__file__) From c460ea8d2a395005571da7687f2d123d40d69424 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 15 Dec 2021 15:47:18 -0800 Subject: [PATCH 08/16] Put back accidentally changed files --- setup.cfg | 71 +++++++++++++++++++++++++++++++++++++++++++++++ tests/conftest.py | 9 +++--- 2 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..7f1a86fb --- /dev/null +++ b/setup.cfg @@ -0,0 +1,71 @@ +[metadata] +name = wheel +version = attr: wheel.__version__ +description = A built-package format for Python +long_description = file: README.rst +classifiers = + Development Status :: 5 - Production/Stable + Intended Audience :: Developers + Topic :: System :: Archiving :: Packaging + License :: OSI Approved :: MIT License + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 +author = Daniel Holth +author_email = dholth@fastmail.fm +maintainer = Alex Gronholm +maintainer_email = alex.gronholm@nextday.fi +url = https://github.com/pypa/wheel +project_urls = + Documentation = https://wheel.readthedocs.io/ + Changelog = https://wheel.readthedocs.io/en/stable/news.html + Issue Tracker = https://github.com/pypa/wheel/issues +keywords = wheel, packaging +license = MIT + +[options] +package_dir= + = src +packages = find: +python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.* +setup_requires = setuptools >= 40.9.0 +zip_safe = False + +[options.packages.find] +where = src + +[options.extras_require] +test = + pytest >= 3.0.0 + pytest-cov + +[options.entry_points] +console_scripts = + wheel = wheel.cli:main +distutils.commands = + bdist_wheel = wheel.bdist_wheel:bdist_wheel + +[tool:pytest] +addopts = --cov --cov-config=setup.cfg +testpaths = tests + +[coverage:run] +source = wheel +omit = */vendored/* + +[coverage:report] +show_missing = true + +[flake8] +max-line-length = 99 + +[bdist_wheel] +# use py2.py3 tag for pure-python dist: +universal = 1 diff --git a/tests/conftest.py b/tests/conftest.py index c9eae617..d9821b83 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,21 +7,20 @@ import sys import pytest -sys.path.insert(0, "src") @pytest.fixture(scope='session') def wheels_and_eggs(tmpdir_factory): """Build wheels and eggs from test distributions.""" - test_distributions = ("commasinfilenames.dist",) + test_distributions = "complex-dist", "simple.dist", "headers.dist", "commasinfilenames.dist" if sys.version_info >= (3, 6): # Only Python 3.6+ can handle packaging unicode file names reliably # across different platforms test_distributions += ("unicode.dist",) - # if sys.platform != 'win32': - # # ABI3 extensions don't really work on Windows - # test_distributions += ("abi3extension.dist",) + if sys.platform != 'win32': + # ABI3 extensions don't really work on Windows + test_distributions += ("abi3extension.dist",) pwd = os.path.abspath(os.curdir) this_dir = os.path.dirname(__file__) From 0ecc07747e06ddac7df548b7c2b6c73735c94b56 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 15 Dec 2021 15:49:12 -0800 Subject: [PATCH 09/16] Fix broken import --- src/wheel/wheelfile.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index ff230735..d23b442a 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -12,8 +12,7 @@ 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, TextIOWrapper) +from wheel.util import (urlsafe_b64decode, as_unicode, native, urlsafe_b64encode, as_bytes, StringIO) # Non-greedy matching of an optional build number may be too clever (more # invalid wheel filenames will match). Separate regex for .dist-info? From 267c3dd2315062873645bb7b00b891619592b32e Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Wed, 15 Dec 2021 16:11:40 -0800 Subject: [PATCH 10/16] Address agronholm's review comments --- src/wheel/wheelfile.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index d23b442a..6e1db4e1 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -2,17 +2,18 @@ import csv import hashlib -from io import TextIOWrapper import os.path import re import stat import time + from collections import OrderedDict from distutils import log as logger +from io import TextIOWrapper 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) +from wheel.util import urlsafe_b64decode, as_unicode, native, urlsafe_b64encode, as_bytes, StringIO # Non-greedy matching of an optional build number may be too clever (more # invalid wheel filenames will match). Separate regex for .dist-info? From d44a2a52b3735de20011c3a48e5407543616645e Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 16 Dec 2021 00:36:32 -0800 Subject: [PATCH 11/16] Add newline='' for cross-platform line ending handling as advised by pfmoore --- src/wheel/wheelfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 6e1db4e1..7fbb1a96 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -62,7 +62,7 @@ def __init__(self, file, mode='r', compression=ZIP_DEFLATED): raise WheelError('Missing {} file'.format(self.record_path)) with record: - for line in csv.reader(TextIOWrapper(record)): + for line in csv.reader(TextIOWrapper(record), newline=''): path, hash_sum, size = line if not hash_sum: continue From 9733e096a089d3e4ca7e6caea83f46d1968161a2 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Thu, 16 Dec 2021 00:56:45 -0800 Subject: [PATCH 12/16] Pass newline='' to the right function --- src/wheel/wheelfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 7fbb1a96..eed796bc 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -62,7 +62,7 @@ def __init__(self, file, mode='r', compression=ZIP_DEFLATED): raise WheelError('Missing {} file'.format(self.record_path)) with record: - for line in csv.reader(TextIOWrapper(record), newline=''): + for line in csv.reader(TextIOWrapper(record, newline='')): path, hash_sum, size = line if not hash_sum: continue From e2dd05d455810c9fcd166ff80fcc6a4bd2038286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Fri, 17 Dec 2021 00:28:26 +0200 Subject: [PATCH 13/16] Update src/wheel/wheelfile.py --- src/wheel/wheelfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index eed796bc..bdc14b6b 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -6,7 +6,6 @@ import re import stat import time - from collections import OrderedDict from distutils import log as logger from io import TextIOWrapper From 9e1088c3a32ddb414258116e7002a667a15ef2f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Fri, 17 Dec 2021 01:02:49 +0200 Subject: [PATCH 14/16] Use a unicode newline arg --- src/wheel/wheelfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index bdc14b6b..074396a5 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -61,7 +61,7 @@ def __init__(self, file, mode='r', compression=ZIP_DEFLATED): raise WheelError('Missing {} file'.format(self.record_path)) with record: - for line in csv.reader(TextIOWrapper(record, newline='')): + for line in csv.reader(TextIOWrapper(record, newline=u'')): path, hash_sum, size = line if not hash_sum: continue From 04b933a58373e37e3d91a02f908fb390a5851aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Wed, 22 Dec 2021 00:24:11 +0200 Subject: [PATCH 15/16] Fixed errors on Python 2.7 --- src/wheel/wheelfile.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 074396a5..953cb152 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -5,15 +5,25 @@ import os.path import re import stat +import sys import time from collections import OrderedDict from distutils import log as logger -from io import TextIOWrapper 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='')) +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( @@ -61,7 +71,7 @@ def __init__(self, file, mode='r', compression=ZIP_DEFLATED): raise WheelError('Missing {} file'.format(self.record_path)) with record: - for line in csv.reader(TextIOWrapper(record, newline=u'')): + for line in read_csv(record): path, hash_sum, size = line if not hash_sum: continue From 363ba2f5b423eaf9a5e3bd12006d5a43484b9b79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Wed, 22 Dec 2021 11:40:19 +0200 Subject: [PATCH 16/16] Always use utf-8 encoding with TextIOWrapper --- src/wheel/wheelfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wheel/wheelfile.py b/src/wheel/wheelfile.py index 953cb152..21e73619 100644 --- a/src/wheel/wheelfile.py +++ b/src/wheel/wheelfile.py @@ -18,7 +18,7 @@ from io import TextIOWrapper def read_csv(fp): - return csv.reader(TextIOWrapper(fp, newline='')) + return csv.reader(TextIOWrapper(fp, newline='', encoding='utf-8')) else: def read_csv(fp): for line in csv.reader(fp):