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
This commit is contained in:
Cyril Roelandt
2014-02-10 16:25:24 +01:00
parent 3f289a1dd9
commit 23a2292b9d
9 changed files with 26 additions and 40 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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