Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion purl/__init__.py
Original file line number Diff line number Diff line change
@@ -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']
6 changes: 1 addition & 5 deletions purl/template.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
31 changes: 8 additions & 23 deletions purl/url.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)


Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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',
],
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down