From: Victor Stinner Date: Wed, 10 Jun 2015 12:39:37 +0000 (+0200) Subject: Replace unicode with six.text_type X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f658c4bb49cebc1eaec50a165f890f7d2a9f8f88;p=openstack-build%2Fcinder-build.git Replace unicode with six.text_type 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 --- diff --git a/cinder/utils.py b/cinder/utils.py index ecc8572f5..1b2baa59d 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -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) diff --git a/cinder/volume/drivers/emc/emc_vmax_https.py b/cinder/volume/drivers/emc/emc_vmax_https.py index ea08ebfc0..0aabb3177 100644 --- a/cinder/volume/drivers/emc/emc_vmax_https.py +++ b/cinder/volume/drivers/emc/emc_vmax_https.py @@ -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 = '\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])) diff --git a/cinder/volume/drivers/ibm/storwize_svc/helpers.py b/cinder/volume/drivers/ibm/storwize_svc/helpers.py index ccfa0c6f4..fe129535b 100644 --- a/cinder/volume/drivers/ibm/storwize_svc/helpers.py +++ b/cinder/volume/drivers/ibm/storwize_svc/helpers.py @@ -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') diff --git a/cinder/volume/drivers/san/hp/hp_3par_iscsi.py b/cinder/volume/drivers/san/hp/hp_3par_iscsi.py index a85dbe9f8..70472f12d 100644 --- a/cinder/volume/drivers/san/hp/hp_3par_iscsi.py +++ b/cinder/volume/drivers/san/hp/hp_3par_iscsi.py @@ -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