Use six.text_type and six.reraise

partial blueprint heat-python34-support

Change-Id: Idce66792a43368c78002683cf8cf1d8759729658
This commit is contained in:
Sirushti Murugesan 2015-04-22 01:39:18 +05:30
parent 8257306624
commit 796680c9c7
7 changed files with 15 additions and 12 deletions

View File

@ -939,7 +939,7 @@ class CloudLoadBalancer(resource.Resource):
def _public_ip(self, lb):
for ip in lb.virtual_ips:
if ip.type == 'PUBLIC':
return unicode(ip.address)
return six.text_type(ip.address)
def _resolve_attribute(self, key):
if self.resource_id:

View File

@ -22,6 +22,7 @@ from heat.engine import constraints
from heat.engine import properties
from heat.engine import resource
from heat.engine import support
import six
try:
from pyrax.exceptions import NetworkInUse # noqa
@ -161,7 +162,7 @@ class CloudNetwork(resource.Resource):
def _resolve_attribute(self, name):
net = self.network()
if net:
return unicode(getattr(net, name))
return six.text_type(getattr(net, name))
return ""

View File

@ -21,6 +21,7 @@ import sys
from oslo_log import log as logging
import six
from six.moves.urllib import parse as urlparse
from six import reraise as raise_
from heat.common.i18n import _
from heat.common.i18n import _LE
@ -86,7 +87,7 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None,
payload)
# re-raise original exception since it may have been clobbered
raise exc_info[0], exc_info[1], exc_info[2]
raise_(exc_info[0], exc_info[1], exc_info[2])
return six.wraps(f)(wrapped)
return inner
@ -116,13 +117,13 @@ class HeatException(Exception):
LOG.error("%s: %s" % (name, value)) # noqa
if _FATAL_EXCEPTION_FORMAT_ERRORS:
raise exc_info[0], exc_info[1], exc_info[2]
raise_(exc_info[0], exc_info[1], exc_info[2])
def __str__(self):
return unicode(self.message).encode('UTF-8')
return six.text_type(self.message).encode('UTF-8')
def __unicode__(self):
return unicode(self.message)
return six.text_type(self.message)
def __deepcopy__(self, memo):
return self.__class__(**self.kwargs)

View File

@ -245,7 +245,7 @@ def _decrypt(enc_value, method):
decryptor = getattr(crypt, method)
value = decryptor(enc_value)
if value is not None:
return unicode(value, 'utf-8')
return six.text_type(value, 'utf-8')
def resource_data_get_by_key(context, resource_id, key):

View File

@ -447,7 +447,7 @@ class Replace(function.Function):
raise TypeError(_('"%s" params must be strings or numbers') %
self.fn_name)
return string.replace(placeholder, unicode(value))
return string.replace(placeholder, six.text_type(value))
return reduce(replace, six.iteritems(mapping), template)

View File

@ -153,7 +153,7 @@ def dependencies(snippet, path=''):
elif isinstance(snippet, collections.Mapping):
def mkpath(key):
return '.'.join([path, unicode(key)])
return '.'.join([path, six.text_type(key)])
deps = (dependencies(value,
mkpath(key)) for key, value in snippet.items())

View File

@ -22,6 +22,7 @@ from oslo_log import log as logging
from oslo_utils import encodeutils
from oslo_utils import excutils
import six
from six import reraise as raise_
from heat.common.i18n import _
from heat.common.i18n import _LI
@ -118,8 +119,8 @@ class ExceptionGroup(Exception):
self.exceptions = list(exceptions)
def __str__(self):
return unicode([unicode(ex).encode('utf-8')
for ex in self.exceptions]).encode('utf-8')
return six.text_type([six.text_type(ex).encode('utf-8')
for ex in self.exceptions]).encode('utf-8')
def __unicode__(self):
return six.text_type(map(six.text_type, self.exceptions))
@ -397,7 +398,7 @@ class DependencyTaskGroup(object):
raise ExceptionGroup(v for t, v, tb in raised_exceptions)
else:
exc_type, exc_val, traceback = raised_exceptions[0]
raise exc_type, exc_val, traceback
raise_(exc_type, exc_val, traceback)
def cancel_all(self, grace_period=None):
for r in six.itervalues(self._runners):