Replace unicode with six.text_type
The Unicode type is 'unicode' in Python 2 and 'str' on Python 3: replace unicode with six.text_type to make Nova compatible with Python 2 and Python 3. This patch was generated by the following tool (revision e760664379c3) with the operation "unicode": https://bitbucket.org/haypo/misc/src/tip/python/sixer.py Manual change: * Replace "isinstance(value, str) or isinstance(value, unicode)" with "isinstance(value, six.string_types)" in nova/api/ec2/ec2utils.py * Revert changes in strings in: - nova/compute/api.py - nova/hacking/checks.py - nova/tests/unit/api/openstack/test_wsgi.py - nova/utils.py * Revert changes in nova/tests/unit/test_hacking.py: tests must use "unicode()". The nova.hacking module will probably need other changes to support Python 3. * Reformat nova/tests/unit/objects/test_instance_action.py and nova/tests/unit/virt/hyperv/test_hypervapi.py to 80 columns Blueprint nova-python3 Change-Id: I7ced236b6f8f8b6a5d2e7fee3c4f0ba4d72c21fb
This commit is contained in:
@@ -424,7 +424,7 @@ def utf8(value):
|
||||
http://github.com/facebook/tornado/blob/master/tornado/escape.py
|
||||
|
||||
"""
|
||||
if isinstance(value, unicode):
|
||||
if isinstance(value, six.text_type):
|
||||
return value.encode('utf-8')
|
||||
assert isinstance(value, str)
|
||||
return value
|
||||
@@ -600,7 +600,7 @@ def make_dev_path(dev, partition=None, base='/dev'):
|
||||
|
||||
def sanitize_hostname(hostname):
|
||||
"""Return a hostname which conforms to RFC-952 and RFC-1123 specs."""
|
||||
if isinstance(hostname, unicode):
|
||||
if isinstance(hostname, six.text_type):
|
||||
hostname = hostname.encode('latin-1', 'ignore')
|
||||
|
||||
hostname = re.sub('[ _]', '-', hostname)
|
||||
@@ -1076,7 +1076,7 @@ def get_system_metadata_from_image(image_meta, flavor=None):
|
||||
prefix_format = SM_IMAGE_PROP_PREFIX + '%s'
|
||||
|
||||
for key, value in image_meta.get('properties', {}).iteritems():
|
||||
new_value = safe_truncate(unicode(value), 255)
|
||||
new_value = safe_truncate(six.text_type(value), 255)
|
||||
system_meta[prefix_format % key] = new_value
|
||||
|
||||
for key in SM_INHERITABLE_KEYS:
|
||||
|
||||
Reference in New Issue
Block a user