Sync latest network_utils module from Oslo

Syncs the latest network_utils from Oslo to help simplify the fix
needed for bug #1216247. Also adds network_utils to
openstack-common.conf.

This also includes the following commits to network_utils:

897aa7c urlsplit issues with IPv6 addresses in python26
35dc1d7 py3kcompat: remove
12bcdb7 Remove vim header
4c22556 Use py3kcompat urlutils functions instead of urlparse
0bf03b7 Add network_utils.urlsplit
e456727 Remove useless logging in networks_utils
7119e29 Enable hacking H404 test.

Change-Id: I63325c9b677c2192d24e7eb73adac272bffd4e0b
This commit is contained in:
Brian Cline 2014-04-11 03:52:44 -05:00
parent cc1bc181e0
commit 1207b51be1
2 changed files with 47 additions and 7 deletions

View File

@ -1,5 +1,3 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 OpenStack Foundation.
# All Rights Reserved.
#
@ -19,15 +17,22 @@
Network-related utilities and helper functions.
"""
from glance.openstack.common import log as logging
# TODO(jd) Use six.moves once
# https://bitbucket.org/gutworth/six/pull-request/28
# is merged
try:
import urllib.parse
SplitResult = urllib.parse.SplitResult
except ImportError:
import urlparse
SplitResult = urlparse.SplitResult
LOG = logging.getLogger(__name__)
from six.moves.urllib import parse
def parse_host_port(address, default_port=None):
"""
Interpret a string as a host:port pair.
"""Interpret a string as a host:port pair.
An IPv6 address MUST be escaped if accompanied by a port,
because otherwise ambiguity ensues: 2001:db8:85a3::8a2e:370:7334
means both [2001:db8:85a3::8a2e:370:7334] and
@ -67,3 +72,37 @@ def parse_host_port(address, default_port=None):
port = default_port
return (host, None if port is None else int(port))
class ModifiedSplitResult(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 = 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 ModifiedSplitResult(scheme, netloc,
path, query, fragment)

View File

@ -11,6 +11,7 @@ module=jsonutils
module=local
module=lockutils
module=log
module=network_utils
module=policy
module=strutils
module=test