diff --git a/openstack-common.conf b/openstack-common.conf index 8858fc49a..695e2862b 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -6,7 +6,6 @@ module=gettextutils module=importutils module=jsonutils module=network_utils -module=py3kcompat module=timeutils script = tools/run_cross_tests.sh diff --git a/oslo/messaging/openstack/common/network_utils.py b/oslo/messaging/openstack/common/network_utils.py index 401763838..490f5a69e 100644 --- a/oslo/messaging/openstack/common/network_utils.py +++ b/oslo/messaging/openstack/common/network_utils.py @@ -17,7 +17,7 @@ Network-related utilities and helper functions. """ -from oslo.messaging.openstack.common.py3kcompat import urlutils +from six.moves.urllib import parse def parse_host_port(address, default_port=None): @@ -64,16 +64,35 @@ def parse_host_port(address, default_port=None): return (host, None if port is None else int(port)) +class ModifiedSplitResult(parse.SplitResult): + """Split results class for urlsplit.""" + + # NOTE(dims): The functions below are needed for Python 2.6.x. + # We can remove these when we drop support for 2.6.x. + @property + def hostname(self): + netloc = self.netloc.split('@', 1)[-1] + host, port = parse_host_port(netloc) + return host + + @property + def port(self): + netloc = self.netloc.split('@', 1)[-1] + host, port = parse_host_port(netloc) + return port + + def urlsplit(url, scheme='', allow_fragments=True): """Parse a URL using urlparse.urlsplit(), splitting query and fragments. This function papers over Python issue9374 when needed. The parameters are the same as urlparse.urlsplit. """ - scheme, netloc, path, query, fragment = urlutils.urlsplit( + scheme, netloc, path, query, fragment = parse.urlsplit( url, scheme, allow_fragments) if allow_fragments and '#' in path: path, fragment = path.split('#', 1) if '?' in path: path, query = path.split('?', 1) - return urlutils.SplitResult(scheme, netloc, path, query, fragment) + return ModifiedSplitResult(scheme, netloc, + path, query, fragment) diff --git a/oslo/messaging/openstack/common/py3kcompat/__init__.py b/oslo/messaging/openstack/common/py3kcompat/__init__.py deleted file mode 100644 index 97ae4e34a..000000000 --- a/oslo/messaging/openstack/common/py3kcompat/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright 2013 Canonical Ltd. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# diff --git a/oslo/messaging/openstack/common/py3kcompat/urlutils.py b/oslo/messaging/openstack/common/py3kcompat/urlutils.py deleted file mode 100644 index 6200271f3..000000000 --- a/oslo/messaging/openstack/common/py3kcompat/urlutils.py +++ /dev/null @@ -1,65 +0,0 @@ -# -# Copyright 2013 Canonical Ltd. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# - -""" -Python2/Python3 compatibility layer for OpenStack -""" - -import six - -if six.PY3: - # python3 - import urllib.error - import urllib.parse - import urllib.request - - urlencode = urllib.parse.urlencode - urljoin = urllib.parse.urljoin - quote = urllib.parse.quote - parse_qsl = urllib.parse.parse_qsl - unquote = urllib.parse.unquote - unquote_plus = urllib.parse.unquote_plus - urlparse = urllib.parse.urlparse - urlsplit = urllib.parse.urlsplit - urlunsplit = urllib.parse.urlunsplit - SplitResult = urllib.parse.SplitResult - - urlopen = urllib.request.urlopen - URLError = urllib.error.URLError - pathname2url = urllib.request.pathname2url -else: - # python2 - import urllib - import urllib2 - import urlparse - - urlencode = urllib.urlencode - quote = urllib.quote - unquote = urllib.unquote - unquote_plus = urllib.unquote_plus - - parse = urlparse - parse_qsl = parse.parse_qsl - urljoin = parse.urljoin - urlparse = parse.urlparse - urlsplit = parse.urlsplit - urlunsplit = parse.urlunsplit - SplitResult = parse.SplitResult - - urlopen = urllib2.urlopen - URLError = urllib2.URLError - pathname2url = urllib.pathname2url diff --git a/oslo/messaging/transport.py b/oslo/messaging/transport.py index 16e6f49bd..02891c1d1 100644 --- a/oslo/messaging/transport.py +++ b/oslo/messaging/transport.py @@ -29,10 +29,10 @@ __all__ = [ from oslo.config import cfg import six +from six.moves.urllib import parse from stevedore import driver from oslo.messaging import exceptions -from oslo.messaging.openstack.common.py3kcompat import urlutils _transport_opts = [ @@ -295,9 +295,9 @@ class TransportURL(object): # Build the username and password portion of the transport URL if username is not None or password is not None: if username is not None: - netloc += urlutils.quote(username, '') + netloc += parse.quote(username, '') if password is not None: - netloc += ':%s' % urlutils.quote(password, '') + netloc += ':%s' % parse.quote(password, '') netloc += '@' # Build the network location portion of the transport URL @@ -315,7 +315,7 @@ class TransportURL(object): url = '%s://%s/' % (self.transport, ','.join(netlocs)) if self.virtual_host: - url += urlutils.quote(self.virtual_host) + url += parse.quote(self.virtual_host) return url @@ -367,7 +367,7 @@ class TransportURL(object): if not isinstance(url, six.string_types): raise InvalidTransportURL(url, 'Wrong URL type') - url = urlutils.urlparse(url) + url = parse.urlparse(url) # Make sure there's not a query string; that could identify # requirements we can't comply with (e.g., ssl), so reject it if