From becb8d266366edbcaf204ebaa7bbef6cf82e4d86 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 6 Sep 2018 16:56:39 +0300 Subject: Drop support for EOL Python --- uritemplate/variable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'uritemplate/variable.py') diff --git a/uritemplate/variable.py b/uritemplate/variable.py index 1842830..7fb02ff 100644 --- a/uritemplate/variable.py +++ b/uritemplate/variable.py @@ -18,9 +18,9 @@ What do you do? import collections import sys -if (2, 6) <= sys.version_info < (2, 8): +if sys.version_info.major == 2: import urllib -elif (3, 3) <= sys.version_info < (4, 0): +elif sys.version_info.major == 3: import urllib.parse as urllib -- cgit v1.2.3 From 910f60597444da9b9ffc680f73050f6d67083403 Mon Sep 17 00:00:00 2001 From: Hugo Date: Thu, 6 Sep 2018 16:59:32 +0300 Subject: Upgrade Python syntax with pyupgrade https://github.com/asottile/pyupgrade --- uritemplate/variable.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'uritemplate/variable.py') diff --git a/uritemplate/variable.py b/uritemplate/variable.py index 7fb02ff..0d2e695 100644 --- a/uritemplate/variable.py +++ b/uritemplate/variable.py @@ -149,11 +149,11 @@ class URIVariable(object): return None if explode: return self.join_str.join( - '%s=%s' % (name, quote(v, safe)) for v in value + '{}={}'.format(name, quote(v, safe)) for v in value ) else: value = ','.join(quote(v, safe) for v in value) - return '%s=%s' % (name, value) + return '{}={}'.format(name, value) if dict_test(value) or tuples: if not value: @@ -161,21 +161,21 @@ class URIVariable(object): items = items or sorted(value.items()) if explode: return self.join_str.join( - '%s=%s' % ( + '{}={}'.format( quote(k, safe), quote(v, safe) ) for k, v in items ) else: value = ','.join( - '%s,%s' % ( + '{},{}'.format( quote(k, safe), quote(v, safe) ) for k, v in items ) - return '%s=%s' % (name, value) + return '{}={}'.format(name, value) if value: value = value[:prefix] if prefix else value - return '%s=%s' % (name, quote(value, safe)) + return '{}={}'.format(name, quote(value, safe)) return name + '=' def _label_path_expansion(self, name, value, explode, prefix): @@ -234,35 +234,35 @@ class URIVariable(object): if list_test(value) and not tuples: if explode: expanded = join_str.join( - '%s=%s' % ( + '{}={}'.format( name, quote(v, safe) ) for v in value if v is not None ) return expanded if expanded else None else: value = ','.join(quote(v, safe) for v in value) - return '%s=%s' % (name, value) + return '{}={}'.format(name, value) if dict_test(value) or tuples: items = items or sorted(value.items()) if explode: return join_str.join( - '%s=%s' % ( + '{}={}'.format( quote(k, safe), quote(v, safe) ) for k, v in items if v is not None ) else: expanded = ','.join( - '%s,%s' % ( + '{},{}'.format( quote(k, safe), quote(v, safe) ) for k, v in items if v is not None ) - return '%s=%s' % (name, expanded) + return '{}={}'.format(name, expanded) value = value[:prefix] if prefix else value if value: - return '%s=%s' % (name, quote(value, safe)) + return '{}={}'.format(name, quote(value, safe)) return name -- cgit v1.2.3 From 255c70115059c0d3347f6fbe3776031d4a52d009 Mon Sep 17 00:00:00 2001 From: "John T. Wodder II" Date: Mon, 29 Oct 2018 19:50:49 +0000 Subject: Import ABCs from collections.abc if possible Quoting Python 3.7's DeprecationWarning: "Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working" --- uritemplate/variable.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'uritemplate/variable.py') diff --git a/uritemplate/variable.py b/uritemplate/variable.py index 0d2e695..a3bd4ce 100644 --- a/uritemplate/variable.py +++ b/uritemplate/variable.py @@ -15,9 +15,13 @@ What do you do? """ -import collections import sys +try: + import collections.abc as collections_abc +except ImportError: + import collections as collections_abc + if sys.version_info.major == 2: import urllib elif sys.version_info.major == 3: @@ -360,7 +364,7 @@ def list_test(value): def dict_test(value): - return isinstance(value, (dict, collections.MutableMapping)) + return isinstance(value, (dict, collections_abc.MutableMapping)) try: -- cgit v1.2.3 From abb1308fa8b7c50eb79e9f07ee448a76c7449847 Mon Sep 17 00:00:00 2001 From: Tommy Yu Date: Thu, 11 Jul 2019 22:27:22 +1200 Subject: Correct handling of empty/undef in list values - Expansion of a list including `None` values, violating 3.2.1 as the undefined value is not ignored, e.g. >>> expand('/test{/x*}', x=['one', None, 'three']) '/test/one/None/three' - A list with empty string was ignored, violating 2.3 as this should not be tread as undefined, example: >>> expand('/test{/x}', x=[]) '/test' >>> expand('/test{/x}', x='') '/test/' >>> expand('/test{/x}', x=['']) '/test' # should be /test/ >>> expand('/test{/x}', x=['', '']) '/test/,' >>> expand('/test{/x*}', x=['', '']) '/test//' >>> expand('/test{/x*}', x=['']) '/test' --- uritemplate/variable.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'uritemplate/variable.py') diff --git a/uritemplate/variable.py b/uritemplate/variable.py index a3bd4ce..ce3f652 100644 --- a/uritemplate/variable.py +++ b/uritemplate/variable.py @@ -200,10 +200,8 @@ class URIVariable(object): if not explode: join_str = ',' - expanded = join_str.join( - quote(v, safe) for v in value if value is not None - ) - return expanded if expanded else None + fragments = [quote(v, safe) for v in value if v is not None] + return join_str.join(fragments) if fragments else None if dict_test(value) or tuples: items = items or sorted(value.items()) -- cgit v1.2.3