From cdc08d03f3743a116d834d94e192fe69bd8e8da0 Mon Sep 17 00:00:00 2001 From: hamed Date: Fri, 4 Aug 2023 09:28:27 +0300 Subject: [PATCH] version-1.7 - eliminate python 2 support --- README.rst | 4 ++++ purl/__init__.py | 2 +- purl/template.py | 6 +----- purl/url.py | 31 ++++++++----------------------- requirements.txt | 8 ++++---- setup.py | 10 +++++----- tox.ini | 2 +- 7 files changed, 24 insertions(+), 39 deletions(-) diff --git a/README.rst b/README.rst index 951eb9e..8b4011f 100644 --- a/README.rst +++ b/README.rst @@ -165,6 +165,10 @@ A wide variety of expansions are possible - refer to the RFC_ for more details. Changelog --------- +v1.7 - 2023-08-03 +~~~~~~~~~~~~~~~~~ +- eliminate python 2 support +- eliminate six as requirements v1.6 - 2021-05-15 ~~~~~~~~~~~~~~~~~ diff --git a/purl/__init__.py b/purl/__init__.py index a75efc2..0bf63b5 100644 --- a/purl/__init__.py +++ b/purl/__init__.py @@ -1,6 +1,6 @@ from .url import URL # noqa from .template import expand, Template # noqa -__version__ = '1.6' +__version__ = '1.7' __all__ = ['URL', 'expand', 'Template'] diff --git a/purl/template.py b/purl/template.py index b9a2f6b..05290a6 100644 --- a/purl/template.py +++ b/purl/template.py @@ -1,11 +1,7 @@ import re import functools -try: - from urllib.parse import quote -except ImportError: - # Python 2 - from urllib import quote +from urllib.parse import quote from . import url diff --git a/purl/url.py b/purl/url.py index 46d3e6a..45df7fc 100644 --- a/purl/url.py +++ b/purl/url.py @@ -1,14 +1,8 @@ from __future__ import unicode_literals -try: - from urllib.parse import parse_qs, urlencode, urlparse, quote, unquote -except ImportError: - from urllib import urlencode, quote, unquote - from urlparse import parse_qs, urlparse +from urllib.parse import parse_qs, urlencode, urlparse, quote, unquote from collections import namedtuple -import six - # To minimise memory consumption, we use a namedtuple to store all instance # variables, as well as using the __slots__ attribute. @@ -23,12 +17,10 @@ def to_unicode(string): """ Ensure a passed string is unicode """ - if isinstance(string, six.binary_type): + if isinstance(string, bytes): return string.decode('utf8') - if isinstance(string, six.text_type): + if isinstance(string, str): return string - if six.PY2: - return unicode(string) return str(string) @@ -37,9 +29,9 @@ def to_utf8(string): Encode a string as a UTF8 bytestring. This function could be passed a bytestring or unicode string so must distinguish between the two. """ - if isinstance(string, six.text_type): + if isinstance(string, str): return string.encode('utf8') - if isinstance(string, six.binary_type): + if isinstance(string, bytes): return string return str(string) @@ -72,9 +64,7 @@ def unicode_quote_path_segment(string): def unicode_unquote(string): if string is None: return None - if six.PY3: - return unquote(string) - return to_unicode(unquote(to_utf8(string))) + return unquote(string) def unicode_urlencode(query, doseq=True): @@ -126,7 +116,8 @@ def parse(url_str): 'port': result.port, 'path': result.path, 'query': result.query, - 'fragment': result.fragment} + 'fragment': result.fragment, + } class URL(object): @@ -485,12 +476,6 @@ def query_params(self, value=None): return URL._mutate(self, query=unicode_urlencode(value, doseq=True)) query = '' if self._tuple.query is None else self._tuple.query - # In Python 2.6, urlparse needs a bytestring so we encode and then - # decode the result. - if not six.PY3: - result = parse_qs(to_utf8(query), True) - return dict_to_unicode(result) - return parse_qs(query, True) def remove_query_param(self, key, value=None): diff --git a/requirements.txt b/requirements.txt index f3fbf13..b7ab90a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ # Packaging -pip==19.0.3 -setuptools==40.8.0 -wheel==0.33.1 +pip +setuptools +wheel # Testing pytest -tox==3.7.0 +tox diff --git a/setup.py b/setup.py index 801858d..e622138 100755 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='purl', - version='1.6', + version='1.7', description=( "An immutable URL class for easy URL-building and manipulation"), long_description=open('README.rst').read(), @@ -12,21 +12,21 @@ author="David Winterbottom", author_email="david.winterbottom@gmail.com", packages=find_packages(exclude=['tests']), - install_requires=['six'], + install_requires=[], include_package_data=True, classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 2', 'Programming Language :: Python', - 'Programming Language :: Python :: 2.6', - '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', + 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Software Development :: Libraries :: Python Modules', ], diff --git a/tox.ini b/tox.ini index 763285a..9e36823 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py26, py27, py36, py37, py38, pypy, pypy3 +envlist = py36, py37, py38, py39,py310, py311, pypy, pypy3 [testenv] commands = pytest