Python3: replace 'unicode' with 'six.text_type'
In Python 3, 'unicode' does not exist; 'six.text_type' should be used instead. Change-Id: I71011b4beee9817a61278eb473804cfb798de74a Blueprint: neutron-python3
This commit is contained in:
parent
0fb46a0580
commit
fd85b3ead3
@ -20,6 +20,7 @@ from neutronclient.v2_0 import client
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import oslo_messaging
|
||||
import six
|
||||
import six.moves.urllib.parse as urlparse
|
||||
import webob
|
||||
|
||||
@ -116,7 +117,8 @@ class MetadataProxyHandler(object):
|
||||
LOG.exception(_LE("Unexpected error."))
|
||||
msg = _('An unknown error has occurred. '
|
||||
'Please try your request again.')
|
||||
return webob.exc.HTTPInternalServerError(explanation=unicode(msg))
|
||||
explanation = six.text_type(msg)
|
||||
return webob.exc.HTTPInternalServerError(explanation=explanation)
|
||||
|
||||
def _get_ports_from_server(self, router_id=None, ip_address=None,
|
||||
networks=None):
|
||||
@ -257,7 +259,8 @@ class MetadataProxyHandler(object):
|
||||
'Remote metadata server experienced an internal server error.'
|
||||
)
|
||||
LOG.warn(msg)
|
||||
return webob.exc.HTTPInternalServerError(explanation=unicode(msg))
|
||||
explanation = six.text_type(msg)
|
||||
return webob.exc.HTTPInternalServerError(explanation=explanation)
|
||||
else:
|
||||
raise Exception(_('Unexpected response code: %s') % resp.status)
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
import httplib2
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
import six
|
||||
import six.moves.urllib.parse as urlparse
|
||||
import webob
|
||||
|
||||
@ -56,7 +57,8 @@ class NetworkMetadataProxyHandler(object):
|
||||
LOG.exception(_LE("Unexpected error."))
|
||||
msg = _('An unknown error has occurred. '
|
||||
'Please try your request again.')
|
||||
return webob.exc.HTTPInternalServerError(explanation=unicode(msg))
|
||||
explanation = six.text_type(msg)
|
||||
return webob.exc.HTTPInternalServerError(explanation=explanation)
|
||||
|
||||
def _proxy_request(self, remote_address, method, path_info,
|
||||
query_string, body):
|
||||
@ -103,7 +105,8 @@ class NetworkMetadataProxyHandler(object):
|
||||
'Remote metadata server experienced an internal server error.'
|
||||
)
|
||||
LOG.debug(msg)
|
||||
return webob.exc.HTTPInternalServerError(explanation=unicode(msg))
|
||||
explanation = six.text_type(msg)
|
||||
return webob.exc.HTTPInternalServerError(explanation=explanation)
|
||||
else:
|
||||
raise Exception(_('Unexpected response code: %s') % resp.status)
|
||||
|
||||
|
@ -506,7 +506,8 @@ class ExtensionManager(object):
|
||||
LOG.debug('Ext namespace: %s', extension.get_namespace())
|
||||
LOG.debug('Ext updated: %s', extension.get_updated())
|
||||
except AttributeError as ex:
|
||||
LOG.exception(_LE("Exception loading extension: %s"), unicode(ex))
|
||||
LOG.exception(_LE("Exception loading extension: %s"),
|
||||
six.text_type(ex))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -18,6 +18,7 @@ Neutron base exception handling.
|
||||
"""
|
||||
|
||||
from oslo_utils import excutils
|
||||
import six
|
||||
|
||||
|
||||
class NeutronException(Exception):
|
||||
@ -40,6 +41,7 @@ class NeutronException(Exception):
|
||||
# at least get the core message out if something happened
|
||||
super(NeutronException, self).__init__(self.message)
|
||||
|
||||
if six.PY2:
|
||||
def __unicode__(self):
|
||||
return unicode(self.msg)
|
||||
|
||||
|
@ -313,7 +313,7 @@ class OwnerCheck(policy.Check):
|
||||
f)
|
||||
match = self.match % target
|
||||
if self.kind in creds:
|
||||
return match == unicode(creds[self.kind])
|
||||
return match == six.text_type(creds[self.kind])
|
||||
return False
|
||||
|
||||
|
||||
|
@ -929,7 +929,9 @@ class JSONV2TestCase(APIv2TestBase, testlib_api.WebTestCase):
|
||||
return_value.update(initial_input['port'])
|
||||
|
||||
instance = self.plugin.return_value
|
||||
instance.get_network.return_value = {'tenant_id': unicode(tenant_id)}
|
||||
instance.get_network.return_value = {
|
||||
'tenant_id': six.text_type(tenant_id)
|
||||
}
|
||||
instance.get_ports_count.return_value = 1
|
||||
instance.create_port.return_value = return_value
|
||||
res = self.api.post(_get_path('ports', fmt=self.fmt),
|
||||
|
@ -412,7 +412,7 @@ class JSONDictSerializer(DictSerializer):
|
||||
|
||||
def default(self, data):
|
||||
def sanitizer(obj):
|
||||
return unicode(obj)
|
||||
return six.text_type(obj)
|
||||
return jsonutils.dumps(data, default=sanitizer)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user