From 049e56a5d03fb8b801bbd31557fc559912cd799e Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Mon, 8 Apr 2019 14:52:42 -0700 Subject: [PATCH] Remove our urlparse wrapper It has not been necessary since we dropped support for Python 2.6. See https://github.com/python/cpython/commit/8c6d9d7 and https://bugs.python.org/issue2987. Be sure to keep a `urlparse` name in utils, though; swauth (at least) still expects there to be a swift.common.utils.urlparse. Change-Id: If2502868f251b8a83aa929ee22b10046e708d111 --- swift/common/middleware/acl.py | 4 +--- swift/common/middleware/staticweb.py | 4 +++- swift/common/utils.py | 35 +--------------------------- swift/container/sync.py | 3 ++- test/unit/common/test_utils.py | 22 ----------------- 5 files changed, 7 insertions(+), 61 deletions(-) diff --git a/swift/common/middleware/acl.py b/swift/common/middleware/acl.py index 8333bbab67..cef7022642 100644 --- a/swift/common/middleware/acl.py +++ b/swift/common/middleware/acl.py @@ -15,9 +15,7 @@ import json import six -from six.moves.urllib.parse import unquote - -from swift.common.utils import urlparse +from six.moves.urllib.parse import unquote, urlparse def clean_acl(name, value): diff --git a/swift/common/middleware/staticweb.py b/swift/common/middleware/staticweb.py index d01c753b34..b87885c9d0 100644 --- a/swift/common/middleware/staticweb.py +++ b/swift/common/middleware/staticweb.py @@ -127,8 +127,10 @@ import cgi import json import time +from six.moves.urllib.parse import urlparse + from swift.common.utils import human_readable, split_path, config_true_value, \ - quote, register_swift_info, get_logger, urlparse + quote, register_swift_info, get_logger from swift.common.wsgi import make_env, WSGIContext from swift.common.http import is_success, is_redirection, HTTP_NOT_FOUND from swift.common.swob import Response, HTTPMovedPermanently, HTTPNotFound, \ diff --git a/swift/common/utils.py b/swift/common/utils.py index 2413eecd15..9ce71fa0b7 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -75,9 +75,8 @@ from six.moves import cPickle as pickle from six.moves.configparser import (ConfigParser, NoSectionError, NoOptionError, RawConfigParser) from six.moves import range, http_client -from six.moves.urllib.parse import ParseResult from six.moves.urllib.parse import quote as _quote -from six.moves.urllib.parse import urlparse as stdlib_urlparse +from six.moves.urllib.parse import urlparse from swift import gettext_ as _ import swift.common.exceptions @@ -3244,38 +3243,6 @@ class StreamingPile(GreenAsyncPile): self.pool.__exit__(type, value, traceback) -class ModifiedParseResult(ParseResult): - """Parse results class for urlparse.""" - - @property - def hostname(self): - netloc = self.netloc.split('@', 1)[-1] - if netloc.startswith('['): - return netloc[1:].split(']')[0] - elif ':' in netloc: - return netloc.rsplit(':')[0] - return netloc - - @property - def port(self): - netloc = self.netloc.split('@', 1)[-1] - if netloc.startswith('['): - netloc = netloc.rsplit(']')[1] - if ':' in netloc: - return int(netloc.rsplit(':')[1]) - return None - - -def urlparse(url): - """ - urlparse augmentation. - This is necessary because urlparse can't handle RFC 2732 URLs. - - :param url: URL to parse. - """ - return ModifiedParseResult(*stdlib_urlparse(url)) - - def validate_sync_to(value, allowed_sync_hosts, realms_conf): """ Validates an X-Container-Sync-To header value, returning the diff --git a/swift/container/sync.py b/swift/container/sync.py index b498b2c2c8..a17c28612c 100644 --- a/swift/container/sync.py +++ b/swift/container/sync.py @@ -23,6 +23,7 @@ from random import choice, random from struct import unpack_from from eventlet import sleep, Timeout +from six.moves.urllib.parse import urlparse import swift.common.db from swift.common.db import DatabaseConnectionError @@ -37,7 +38,7 @@ from swift.common.ring import Ring from swift.common.ring.utils import is_local_device from swift.common.utils import ( clean_content_type, config_true_value, - FileLikeIter, get_logger, hash_path, quote, urlparse, validate_sync_to, + FileLikeIter, get_logger, hash_path, quote, validate_sync_to, whataremyips, Timestamp, decode_timestamps) from swift.common.daemon import Daemon from swift.common.http import HTTP_UNAUTHORIZED, HTTP_NOT_FOUND diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index 70861ebcd0..d26decfc5f 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -2463,28 +2463,6 @@ log_name = %(yarr)s''' self.verify_under_pseudo_time(testfunc, target_runtime_ms=900) - def test_urlparse(self): - parsed = utils.urlparse('http://127.0.0.1/') - self.assertEqual(parsed.scheme, 'http') - self.assertEqual(parsed.hostname, '127.0.0.1') - self.assertEqual(parsed.path, '/') - - parsed = utils.urlparse('http://127.0.0.1:8080/') - self.assertEqual(parsed.port, 8080) - - parsed = utils.urlparse('https://127.0.0.1/') - self.assertEqual(parsed.scheme, 'https') - - parsed = utils.urlparse('http://[::1]/') - self.assertEqual(parsed.hostname, '::1') - - parsed = utils.urlparse('http://[::1]:8080/') - self.assertEqual(parsed.hostname, '::1') - self.assertEqual(parsed.port, 8080) - - parsed = utils.urlparse('www.example.com') - self.assertEqual(parsed.hostname, '') - def test_search_tree(self): # file match & ext miss with temptree(['asdf.conf', 'blarg.conf', 'asdf.cfg']) as t: