]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Replace unicode with six.text_type
authorVictor Stinner <vstinner@redhat.com>
Wed, 10 Jun 2015 12:39:37 +0000 (14:39 +0200)
committerVictor Stinner <vstinner@redhat.com>
Wed, 10 Jun 2015 13:00:46 +0000 (15:00 +0200)
The "unicode" type was renamed to "str" in Python 3. Use six.text_type
to make Cinder compatible with Python 3.

The initial patch was generated by the unicode operation of sixer tool:
https://pypi.python.org/pypi/sixer

Manual changes:

* cinder/volume/drivers/san/hp/hp_3par_iscsi.py:
  replace "isinstance(value, str) or isinstance(value, unicode)"
  with "isinstance(value, six.string_types)"
* cinder/volume/drivers/san/hp/hp_3par_iscsi.py:
  bump the version to 2.0.17
* Revert changes on hacking: hacking explicitly searchs the "unicode"
  pattern for Python 2. Hacking may require more work to be ported to
  Python 3.
* Revert changes on docstrings and strings

Change-Id: I68ea8a81a66c9377b2fe20e3f545dce8b691c398

cinder/utils.py
cinder/volume/drivers/emc/emc_vmax_https.py
cinder/volume/drivers/ibm/storwize_svc/helpers.py
cinder/volume/drivers/san/hp/hp_3par_iscsi.py

index ecc8572f51ab834fa4092bf988ecda971a4908d5..1b2baa59daaecefe6fe34043151cc06099992c07 100644 (file)
@@ -459,7 +459,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)
index ea08ebfc003d140b20950d4ace58488415fb82d3..0aabb3177ddb8bf7a2ea085ad1fd2723e8303153 100644 (file)
@@ -274,7 +274,7 @@ def wbem_request(url, data, creds, headers=None, debug=0, x509=None,
     localAuthHeader = None
     tryLimit = 5
 
-    if isinstance(data, unicode):
+    if isinstance(data, six.text_type):
         data = data.encode('utf-8')
     data = '<?xml version="1.0" encoding="utf-8" ?>\n' + data
 
@@ -309,7 +309,7 @@ def wbem_request(url, data, creds, headers=None, debug=0, x509=None,
             h.putheader('PegasusAuthorization', 'Local "%s"' % locallogin)
 
         for hdr in headers:
-            if isinstance(hdr, unicode):
+            if isinstance(hdr, six.text_type):
                 hdr = hdr.encode('utf-8')
             s = map(lambda x: string.strip(x), string.split(hdr, ":", 1))
             h.putheader(urllib.quote(s[0]), urllib.quote(s[1]))
index ccfa0c6f4c273318339d96073c601cbbe0cdca67..fe129535bae424578dc4961dfc21421b949c7b11 100644 (file)
@@ -267,7 +267,7 @@ class StorwizeHelpers(object):
             raise exception.VolumeDriverException(message=msg)
 
         # Build a host name for the Storwize host - first clean up the name
-        if isinstance(host_name, unicode):
+        if isinstance(host_name, six.text_type):
             host_name = unicodedata.normalize('NFKD', host_name).encode(
                 'ascii', 'replace').decode('ascii')
 
index a85dbe9f8f7a2b5cf71f27a1382a515b0f2b23d1..70472f12df030dea132132b1ae1bba4f4e12c2f3 100644 (file)
@@ -36,6 +36,7 @@ except ImportError:
     hpexceptions = None
 
 from oslo_log import log as logging
+import six
 
 from cinder import exception
 from cinder.i18n import _, _LE, _LW
@@ -85,10 +86,11 @@ class HP3PARISCSIDriver(cinder.volume.driver.ISCSIDriver):
                  used during live-migration.  bug #1423958
         2.0.15 - Added support for updated detach_volume attachment.
         2.0.16 - Added encrypted property to initialize_connection #1439917
+        2.0.17 - Python 3 fixes
 
     """
 
-    VERSION = "2.0.16"
+    VERSION = "2.0.17"
 
     def __init__(self, *args, **kwargs):
         super(HP3PARISCSIDriver, self).__init__(*args, **kwargs)
@@ -392,7 +394,7 @@ class HP3PARISCSIDriver(cinder.volume.driver.ISCSIDriver):
         if host_found is not None:
             return host_found
         else:
-            if isinstance(iscsi_iqn, str) or isinstance(iscsi_iqn, unicode):
+            if isinstance(iscsi_iqn, six.string_types):
                 iqn = [iscsi_iqn]
             else:
                 iqn = iscsi_iqn