From 76c6de7d7cdcd2e8853c43488b811f382b9dfc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 26 Sep 2014 22:55:08 +0000 Subject: [PATCH 1/5] random fixes to setup.py --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 28a4e26..7dca2c7 100755 --- a/setup.py +++ b/setup.py @@ -31,13 +31,11 @@ setup( long_description=readme + '\n\n' + history, author='Ian Cordasco', author_email='ian.cordasco@rackspace.com', - url='https://rfc3986.rtfd.org', + url='https://rfc3986.readthedocs.org', packages=packages, package_data={'': ['LICENSE']}, - package_dir={'requests': 'requests'}, include_package_data=True, license='Apache 2.0', - zip_safe=False, classifiers=( 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', From 5a604ce0a802b154b6a0a980bace4c9f6503a511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 26 Sep 2014 23:27:51 +0000 Subject: [PATCH 2/5] use .replace() for modifications --- rfc3986/uri.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/rfc3986/uri.py b/rfc3986/uri.py index 872f5d2..1de3a1a 100644 --- a/rfc3986/uri.py +++ b/rfc3986/uri.py @@ -308,14 +308,14 @@ class URIReference(namedtuple('URIReference', URI_COMPONENTS)): resolving = self if not strict and resolving.scheme == base_uri.scheme: - resolving = resolving._replace(scheme=None) + resolving = resolving.replace(scheme=None) # http://tools.ietf.org/html/rfc3986#page-32 if resolving.scheme is not None: - target = resolving._replace(path=normalize_path(resolving.path)) + target = resolving.replace(path=normalize_path(resolving.path)) else: if resolving.authority is not None: - target = resolving._replace( + target = resolving.replace( scheme=base_uri.scheme, path=normalize_path(resolving.path) ) @@ -325,7 +325,7 @@ class URIReference(namedtuple('URIReference', URI_COMPONENTS)): query = resolving.query else: query = base_uri.query - target = resolving._replace( + target = resolving.replace( scheme=base_uri.scheme, authority=base_uri.authority, path=base_uri.path, @@ -338,7 +338,7 @@ class URIReference(namedtuple('URIReference', URI_COMPONENTS)): path = normalize_path( merge_paths(base_uri, resolving.path) ) - target = resolving._replace( + target = resolving.replace( scheme=base_uri.scheme, authority=base_uri.authority, path=path, @@ -366,6 +366,9 @@ class URIReference(namedtuple('URIReference', URI_COMPONENTS)): result_list.extend(['#', self.fragment]) return ''.join(result_list) + def replace(self, **kwargs): + return self._replace(**kwargs) + def valid_ipv4_host_address(host): # If the host exists, and it might be IPv4, check each byte in the From 46ff5a4dae8d5797dcaeaa833b49eda1830a38d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 26 Sep 2014 23:30:35 +0000 Subject: [PATCH 3/5] use the cls parameter of the classmethod --- rfc3986/uri.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/rfc3986/uri.py b/rfc3986/uri.py index 1de3a1a..7d16c8a 100644 --- a/rfc3986/uri.py +++ b/rfc3986/uri.py @@ -69,11 +69,10 @@ class URIReference(namedtuple('URIReference', URI_COMPONENTS)): uri_string = to_str(uri_string, encoding) split_uri = URI_MATCHER.match(uri_string).groupdict() - return URIReference(split_uri['scheme'], split_uri['authority'], - encode_component(split_uri['path'], encoding), - encode_component(split_uri['query'], encoding), - encode_component(split_uri['fragment'], encoding), - encoding) + return cls(split_uri['scheme'], split_uri['authority'], + encode_component(split_uri['path'], encoding), + encode_component(split_uri['query'], encoding), + encode_component(split_uri['fragment'], encoding), encoding) def authority_info(self): """Returns a dictionary with the ``userinfo``, ``host``, and ``port``. From 0f0b4ee73e526a5d196f02eba3c7ac337b244901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 26 Sep 2014 23:38:05 +0000 Subject: [PATCH 4/5] remove superfluous if block --- rfc3986/uri.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rfc3986/uri.py b/rfc3986/uri.py index 7d16c8a..818512e 100644 --- a/rfc3986/uri.py +++ b/rfc3986/uri.py @@ -147,9 +147,7 @@ class URIReference(namedtuple('URIReference', URI_COMPONENTS)): :returns: ``True`` if it is an absolute URI, ``False`` otherwise. :rtype: bool """ - if ABSOLUTE_URI_MATCHER.match(self.unsplit()): - return True - return False + return bool(ABSOLUTE_URI_MATCHER.match(self.unsplit())) def is_valid(self, **kwargs): """Determines if the URI is valid. From a66bb6b0c5d4c2c51b2ac0a93000309cf910c7d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 26 Sep 2014 23:41:46 +0000 Subject: [PATCH 5/5] simplify --- rfc3986/uri.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/rfc3986/uri.py b/rfc3986/uri.py index 818512e..6458fb9 100644 --- a/rfc3986/uri.py +++ b/rfc3986/uri.py @@ -370,13 +370,4 @@ class URIReference(namedtuple('URIReference', URI_COMPONENTS)): def valid_ipv4_host_address(host): # If the host exists, and it might be IPv4, check each byte in the # address. - for byte in host.split('.'): - byte_val = int(byte, base=10) - if byte_val < 0 or byte_val > 255: - # If the value is not in the correct range it is invalid. - # Return False immediately - return False - - # If we haven't returned yet, the host existed, and appeared to be - # IPv4, then it should be a valid IPv4 - return True + return all([0 <= int(byte, base=10) <= 255 for byte in host.split('.')])