py3.x: Use six.text_type() instead of unicode()

Python 3 doesn't support unicode(), use six.text_type instead.

Related-Bug: #1547712
Change-Id: I4bd774ec728fea042e64d766acb37409007aed35
This commit is contained in:
dharmendra 2016-03-17 15:06:22 +05:30 committed by dharmendra kushwaha
parent 8b0d413b1c
commit 957e4eb62b
5 changed files with 15 additions and 8 deletions

View File

@ -522,7 +522,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(_("Exception loading extension: %s"), unicode(ex))
LOG.exception(_("Exception loading extension: %s"),
six.text_type(ex))
return False
return True

View File

@ -17,6 +17,8 @@
Tacker base exception handling.
"""
import six
from tacker.openstack.common import excutils
@ -41,7 +43,7 @@ class TackerException(Exception):
super(TackerException, self).__init__(self.message)
def __unicode__(self):
return unicode(self.msg)
return six.text_type(self.msg)
def use_fatal_exceptions(self):
return False

View File

@ -22,6 +22,7 @@ import itertools
import re
from oslo_config import cfg
import six
from tacker.api.v1 import attributes
from tacker.common import exceptions
@ -280,7 +281,7 @@ class OwnerCheck(policy.Check):
LOG.exception(_('Policy check error while calling %s!'), 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

View File

@ -19,6 +19,7 @@ import os
import mock
from oslo_config import cfg
import six
import six.moves.urllib.parse as urlparse
import webob
from webob import exc
@ -929,7 +930,8 @@ 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),

View File

@ -33,6 +33,7 @@ import eventlet.wsgi
# eventlet.patcher.monkey_patch(all=False, socket=True, thread=True)
from oslo_config import cfg
import routes.middleware
import six
import webob.dec
import webob.exc
@ -395,7 +396,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)
@ -535,9 +536,9 @@ class XMLDictSerializer(DictSerializer):
{'data': data,
'type': type(data)})
if isinstance(data, str):
result.text = unicode(data, 'utf-8')
result.text = six.text_type(data, encoding='utf-8')
else:
result.text = unicode(data)
result.text = six.text_type(data)
return result
def _create_link_nodes(self, xml_doc, links):
@ -1090,7 +1091,7 @@ class Resource(Application):
try:
action_result = self.dispatch(request, action, args)
except webob.exc.HTTPException as ex:
LOG.info(_("HTTP exception thrown: %s"), unicode(ex))
LOG.info(_("HTTP exception thrown: %s"), six.text_type(ex))
action_result = Fault(ex,
self._xmlns,
self._fault_body_function)