Import urlutils module from openstack-common

urlutils defines a series of urllib/urlparse modules for Python 2&3
compatability.

Partial implements: blueprint py33-support

Change-Id: I55c2c5d479d2f7a86d3a0c207dc40794006d951c
This commit is contained in:
Kui Shi 2013-10-15 15:43:23 +08:00
parent 4ff4fa0661
commit b60095f92f
8 changed files with 85 additions and 18 deletions

View File

@ -4,6 +4,7 @@
module=apiclient
module=strutils
module=install_venv_common
module=py3kcompat
# The base module to hold the copy of openstack.common
base=troveclient
base=troveclient

View File

@ -0,0 +1,17 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# 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.
#

View File

@ -0,0 +1,51 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# 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.parse
urlencode = urllib.parse.urlencode
urljoin = urllib.parse.urljoin
quote = urllib.parse.quote
parse_qsl = urllib.parse.parse_qsl
unquote = urllib.parse.unquote
urlparse = urllib.parse.urlparse
urlsplit = urllib.parse.urlsplit
urlunsplit = urllib.parse.urlunsplit
else:
# python2
import urllib
import urlparse
urlencode = urllib.urlencode
quote = urllib.quote
unquote = urllib.unquote
parse = urlparse
parse_qsl = parse.parse_qsl
urljoin = parse.urljoin
urlparse = parse.urlparse
urlsplit = parse.urlsplit
urlunsplit = parse.urlunsplit

View File

@ -2,7 +2,7 @@ from troveclient import base
from troveclient.common import check_for_exceptions
from troveclient.common import limit_url
from troveclient.common import Paginated
import urlparse
from troveclient.openstack.common.py3kcompat import urlutils
class Database(base.Resource):
@ -47,8 +47,8 @@ class Databases(base.ManagerWithFind):
next_marker = None
for link in next_links:
# Extract the marker from the url.
parsed_url = urlparse.urlparse(link)
query_dict = dict(urlparse.parse_qsl(parsed_url.query))
parsed_url = urlutils.urlparse(link)
query_dict = dict(urlutils.parse_qsl(parsed_url.query))
next_marker = query_dict.get('marker', None)
databases = body[response_key]
databases = [self.resource_class(self, res) for res in databases]

View File

@ -15,12 +15,11 @@
from troveclient import base
import urlparse
from troveclient.common import check_for_exceptions
from troveclient.common import limit_url
from troveclient.common import Paginated
from troveclient.openstack.common.apiclient import exceptions
from troveclient.openstack.common.py3kcompat import urlutils
REBOOT_SOFT, REBOOT_HARD = 'SOFT', 'HARD'
@ -86,8 +85,8 @@ class Instances(base.ManagerWithFind):
next_marker = None
for link in next_links:
# Extract the marker from the url.
parsed_url = urlparse.urlparse(link)
query_dict = dict(urlparse.parse_qsl(parsed_url.query))
parsed_url = urlutils.urlparse(link)
query_dict = dict(urlutils.parse_qsl(parsed_url.query))
next_marker = query_dict.get('marker', None)
instances = body[response_key]
instances = [self.resource_class(self, res) for res in instances]

View File

@ -14,11 +14,11 @@
# under the License.
from troveclient import base
import urlparse
from troveclient.common import check_for_exceptions
from troveclient.common import limit_url
from troveclient.common import Paginated
from troveclient.openstack.common.py3kcompat import urlutils
from troveclient.v1.instances import Instance
from troveclient.v1.flavors import Flavor
@ -48,8 +48,8 @@ class Management(base.ManagerWithFind):
next_marker = None
for link in next_links:
# Extract the marker from the url.
parsed_url = urlparse.urlparse(link)
query_dict = dict(urlparse.parse_qsl(parsed_url.query))
parsed_url = urlutils.urlparse(link)
query_dict = dict(urlutils.parse_qsl(parsed_url.query))
next_marker = query_dict.get('marker', None)
instances = body[response_key]
instances = [self.resource_class(self, res) for res in instances]

View File

@ -16,11 +16,10 @@
from troveclient import base
import urlparse
from troveclient.common import limit_url
from troveclient.common import Paginated
from troveclient.openstack.common.apiclient import exceptions
from troveclient.openstack.common.py3kcompat import urlutils
class SecurityGroup(base.Resource):
@ -46,8 +45,8 @@ class SecurityGroups(base.ManagerWithFind):
next_marker = None
for link in next_links:
# Extract the marker from the url.
parsed_url = urlparse.urlparse(link)
query_dict = dict(urlparse.parse_qsl(parsed_url.query))
parsed_url = urlutils.urlparse(link)
query_dict = dict(urlutils.parse_qsl(parsed_url.query))
next_marker = query_dict.get('marker', None)
instances = body[response_key]
instances = [self.resource_class(self, res) for res in instances]

View File

@ -19,7 +19,7 @@ from troveclient.common import check_for_exceptions
from troveclient.common import limit_url
from troveclient.common import Paginated
from troveclient.common import quote_user_host
import urlparse
from troveclient.openstack.common.py3kcompat import urlutils
class User(base.Resource):
@ -63,8 +63,8 @@ class Users(base.ManagerWithFind):
next_marker = None
for link in next_links:
# Extract the marker from the url.
parsed_url = urlparse.urlparse(link)
query_dict = dict(urlparse.parse_qsl(parsed_url.query))
parsed_url = urlutils.urlparse(link)
query_dict = dict(urlutils.parse_qsl(parsed_url.query))
next_marker = query_dict.get('marker', None)
users = [self.resource_class(self, res) for res in body[response_key]]
return Paginated(users, next_marker=next_marker, links=links)