Remove dependent module py3kcompat

Module py3kcompat was removed from oslo-incubator, we can use
six directly.

Syncing module network_utils:
162e850 Remove import workaround of SplitResult
897aa7c urlsplit issues with IPv6 addresses in python26
35dc1d7 py3kcompat: remove

Change-Id: I71446362209c306c7e8858f4713a59b84fbcc1b2
Closes-Bug: #1280033
This commit is contained in:
Eric Guo 2014-02-14 07:24:42 +08:00 committed by ChangBo Guo(gcb)
parent 06ab616d8f
commit 13608437bb
5 changed files with 27 additions and 90 deletions

@ -6,7 +6,6 @@ module=gettextutils
module=importutils module=importutils
module=jsonutils module=jsonutils
module=network_utils module=network_utils
module=py3kcompat
module=timeutils module=timeutils
script = tools/run_cross_tests.sh script = tools/run_cross_tests.sh

@ -17,7 +17,7 @@
Network-related utilities and helper functions. 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): 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)) 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): def urlsplit(url, scheme='', allow_fragments=True):
"""Parse a URL using urlparse.urlsplit(), splitting query and fragments. """Parse a URL using urlparse.urlsplit(), splitting query and fragments.
This function papers over Python issue9374 when needed. This function papers over Python issue9374 when needed.
The parameters are the same as urlparse.urlsplit. 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) url, scheme, allow_fragments)
if allow_fragments and '#' in path: if allow_fragments and '#' in path:
path, fragment = path.split('#', 1) path, fragment = path.split('#', 1)
if '?' in path: if '?' in path:
path, query = path.split('?', 1) path, query = path.split('?', 1)
return urlutils.SplitResult(scheme, netloc, path, query, fragment) return ModifiedSplitResult(scheme, netloc,
path, query, fragment)

@ -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.
#

@ -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

@ -29,10 +29,10 @@ __all__ = [
from oslo.config import cfg from oslo.config import cfg
import six import six
from six.moves.urllib import parse
from stevedore import driver from stevedore import driver
from oslo.messaging import exceptions from oslo.messaging import exceptions
from oslo.messaging.openstack.common.py3kcompat import urlutils
_transport_opts = [ _transport_opts = [
@ -295,9 +295,9 @@ class TransportURL(object):
# Build the username and password portion of the transport URL # 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 or password is not None:
if username is not None: if username is not None:
netloc += urlutils.quote(username, '') netloc += parse.quote(username, '')
if password is not None: if password is not None:
netloc += ':%s' % urlutils.quote(password, '') netloc += ':%s' % parse.quote(password, '')
netloc += '@' netloc += '@'
# Build the network location portion of the transport URL # Build the network location portion of the transport URL
@ -315,7 +315,7 @@ class TransportURL(object):
url = '%s://%s/' % (self.transport, ','.join(netlocs)) url = '%s://%s/' % (self.transport, ','.join(netlocs))
if self.virtual_host: if self.virtual_host:
url += urlutils.quote(self.virtual_host) url += parse.quote(self.virtual_host)
return url return url
@ -367,7 +367,7 @@ class TransportURL(object):
if not isinstance(url, six.string_types): if not isinstance(url, six.string_types):
raise InvalidTransportURL(url, 'Wrong URL type') 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 # Make sure there's not a query string; that could identify
# requirements we can't comply with (e.g., ssl), so reject it if # requirements we can't comply with (e.g., ssl), so reject it if