diff options
author | Cyril Roelandt <cyril.roelandt@enovance.com> | 2014-02-10 16:25:24 +0100 |
---|---|---|
committer | Cyril Roelandt <cyril.roelandt@enovance.com> | 2014-02-10 17:45:23 +0100 |
commit | 23a2292b9dc3e68529cd9045f564b79f4e84f036 (patch) | |
tree | 5ec1b53bbdff4e2e3b8e0685a0eecf1b80e9fb12 | |
parent | 3f289a1dd904874c0fc6afe0c6dd14ecb5da4c04 (diff) | |
download | python-ceilometerclient-23a2292b9dc3e68529cd9045f564b79f4e84f036.tar.gz |
Sync with Oslo
This fixes a bunch os Python3-related issues, linked to iteritems(), urllib,
encoding, etc.
This is now up-to-date with 6827012438c7c88e0f54803f33c612684cf34e86 in Oslo.
Change-Id: Id8c265d76abfd8ede5575d3903f612ad1ea46643
9 files changed, 26 insertions, 40 deletions
diff --git a/ceilometerclient/openstack/common/apiclient/__init__.py b/ceilometerclient/openstack/common/apiclient/__init__.py index f3d0cde..e69de29 100644 --- a/ceilometerclient/openstack/common/apiclient/__init__.py +++ b/ceilometerclient/openstack/common/apiclient/__init__.py @@ -1,14 +0,0 @@ -# Copyright 2013 OpenStack Foundation -# 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/ceilometerclient/openstack/common/apiclient/auth.py b/ceilometerclient/openstack/common/apiclient/auth.py index d33cdda..df9b674 100644 --- a/ceilometerclient/openstack/common/apiclient/auth.py +++ b/ceilometerclient/openstack/common/apiclient/auth.py @@ -58,7 +58,7 @@ def load_auth_system_opts(parser): """ group = parser.add_argument_group("Common auth options") BaseAuthPlugin.add_common_opts(group) - for name, auth_plugin in _discovered_plugins.iteritems(): + for name, auth_plugin in six.iteritems(_discovered_plugins): group = parser.add_argument_group( "Auth-system '%s' options" % name, conflict_handler="resolve") diff --git a/ceilometerclient/openstack/common/apiclient/base.py b/ceilometerclient/openstack/common/apiclient/base.py index 74c186e..1920b86 100644 --- a/ceilometerclient/openstack/common/apiclient/base.py +++ b/ceilometerclient/openstack/common/apiclient/base.py @@ -24,11 +24,11 @@ Base utilities to build API operation managers and objects on top of. # pylint: disable=E1102 import abc -import urllib import six from ceilometerclient.openstack.common.apiclient import exceptions +from ceilometerclient.openstack.common.py3kcompat import urlutils from ceilometerclient.openstack.common import strutils @@ -291,7 +291,7 @@ class CrudManager(BaseManager): def _filter_kwargs(self, kwargs): """Drop null values and handle ids.""" - for key, ref in kwargs.copy().iteritems(): + for key, ref in six.iteritems(kwargs.copy()): if ref is None: kwargs.pop(key) else: @@ -327,7 +327,7 @@ class CrudManager(BaseManager): return self._list( '%(base_url)s%(query)s' % { 'base_url': self.build_url(base_url=base_url, **kwargs), - 'query': '?%s' % urllib.urlencode(kwargs) if kwargs else '', + 'query': '?%s' % urlutils.urlencode(kwargs) if kwargs else '', }, self.collection_key) @@ -366,7 +366,7 @@ class CrudManager(BaseManager): rl = self._list( '%(base_url)s%(query)s' % { 'base_url': self.build_url(base_url=base_url, **kwargs), - 'query': '?%s' % urllib.urlencode(kwargs) if kwargs else '', + 'query': '?%s' % urlutils.urlencode(kwargs) if kwargs else '', }, self.collection_key) num = len(rl) @@ -445,7 +445,7 @@ class Resource(object): return None def _add_details(self, info): - for (k, v) in info.iteritems(): + for (k, v) in six.iteritems(info): try: setattr(self, k, v) self._info[k] = v diff --git a/ceilometerclient/openstack/common/apiclient/exceptions.py b/ceilometerclient/openstack/common/apiclient/exceptions.py index b364d60..4776d58 100644 --- a/ceilometerclient/openstack/common/apiclient/exceptions.py +++ b/ceilometerclient/openstack/common/apiclient/exceptions.py @@ -60,6 +60,11 @@ class AuthorizationFailure(ClientException): pass +class ConnectionRefused(ClientException): + """Cannot connect to API service.""" + pass + + class AuthPluginOptionsMissing(AuthorizationFailure): """Auth plugin misses some options.""" def __init__(self, opt_names): diff --git a/ceilometerclient/openstack/common/apiclient/fake_client.py b/ceilometerclient/openstack/common/apiclient/fake_client.py index 7233652..2e816e9 100644 --- a/ceilometerclient/openstack/common/apiclient/fake_client.py +++ b/ceilometerclient/openstack/common/apiclient/fake_client.py @@ -27,6 +27,7 @@ places where actual behavior differs from the spec. import json import requests +import six from ceilometerclient.openstack.common.apiclient import client from ceilometerclient.openstack.common.py3kcompat import urlutils @@ -61,6 +62,8 @@ class TestResponse(requests.Response): else: self._content = text default_headers = {} + if six.PY3 and isinstance(self._content, six.string_types): + self._content = self._content.encode('utf-8', 'strict') self.headers = data.get('headers') or default_headers else: self.status_code = data diff --git a/ceilometerclient/openstack/common/cliutils.py b/ceilometerclient/openstack/common/cliutils.py index 540d332..96725ed 100644 --- a/ceilometerclient/openstack/common/cliutils.py +++ b/ceilometerclient/openstack/common/cliutils.py @@ -173,7 +173,7 @@ def print_dict(dct, dict_property="Property", wrap=0): """ pt = prettytable.PrettyTable([dict_property, 'Value'], caching=False) pt.align = 'l' - for k, v in dct.iteritems(): + for k, v in six.iteritems(dct): # convert dict to str to check length if isinstance(v, dict): v = str(v) diff --git a/ceilometerclient/openstack/common/py3kcompat/__init__.py b/ceilometerclient/openstack/common/py3kcompat/__init__.py index 97ae4e3..e69de29 100644 --- a/ceilometerclient/openstack/common/py3kcompat/__init__.py +++ b/ceilometerclient/openstack/common/py3kcompat/__init__.py @@ -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/ceilometerclient/openstack/common/py3kcompat/urlutils.py b/ceilometerclient/openstack/common/py3kcompat/urlutils.py index 51e1811..6200271 100644 --- a/ceilometerclient/openstack/common/py3kcompat/urlutils.py +++ b/ceilometerclient/openstack/common/py3kcompat/urlutils.py @@ -32,6 +32,7 @@ if six.PY3: 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 @@ -49,6 +50,7 @@ else: urlencode = urllib.urlencode quote = urllib.quote unquote = urllib.unquote + unquote_plus = urllib.unquote_plus parse = urlparse parse_qsl = parse.parse_qsl diff --git a/ceilometerclient/openstack/common/strutils.py b/ceilometerclient/openstack/common/strutils.py index bf2a1c0..23b117e 100644 --- a/ceilometerclient/openstack/common/strutils.py +++ b/ceilometerclient/openstack/common/strutils.py @@ -23,7 +23,7 @@ import unicodedata import six -from ceilometerclient.openstack.common.gettextutils import _ # noqa +from ceilometerclient.openstack.common.gettextutils import _ # Used for looking up extensions of text @@ -152,11 +152,17 @@ def safe_encode(text, incoming=None, sys.getdefaultencoding()) if isinstance(text, six.text_type): - return text.encode(encoding, errors) + if six.PY3: + return text.encode(encoding, errors).decode(incoming) + else: + return text.encode(encoding, errors) elif text and encoding != incoming: # Decode text before encoding it with `encoding` text = safe_decode(text, incoming, errors) - return text.encode(encoding, errors) + if six.PY3: + return text.encode(encoding, errors).decode(incoming) + else: + return text.encode(encoding, errors) return text |