Merge "Remove our urlparse wrapper"
This commit is contained in:
commit
f21fe6f479
@ -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):
|
||||
|
@ -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, \
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user