From: Victor Stinner Date: Wed, 10 Jun 2015 12:32:41 +0000 (+0200) Subject: Replace basestring with six.string_types X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=49d930579bf705d395bb468ec71ae67278a28a97;p=openstack-build%2Fcinder-build.git Replace basestring with six.string_types basestring type is gone in Python 3, use six.string_types to make Cinder code compatible with Python 3. This patch was generated by the basestring operation of the sixer tool: https://pypi.python.org/pypi/sixer Blueprint cinder-python3 Change-Id: Ie1aedf1cbb9d3e54a996321cd586b875e69ac85a --- diff --git a/cinder/api/contrib/admin_actions.py b/cinder/api/contrib/admin_actions.py index 18bbabd46..3ef3511c5 100644 --- a/cinder/api/contrib/admin_actions.py +++ b/cinder/api/contrib/admin_actions.py @@ -15,6 +15,7 @@ from oslo_log import log as logging import oslo_messaging as messaging from oslo_utils import strutils +import six import webob from webob import exc @@ -222,7 +223,7 @@ class VolumeAdminController(AdminController): except KeyError: raise exc.HTTPBadRequest(explanation=_("Must specify 'host'")) force_host_copy = params.get('force_host_copy', False) - if isinstance(force_host_copy, basestring): + if isinstance(force_host_copy, six.string_types): try: force_host_copy = strutils.bool_from_string(force_host_copy, strict=True) diff --git a/cinder/api/contrib/volume_actions.py b/cinder/api/contrib/volume_actions.py index b67970cd8..d6c88309d 100644 --- a/cinder/api/contrib/volume_actions.py +++ b/cinder/api/contrib/volume_actions.py @@ -266,7 +266,7 @@ class VolumeActionsController(wsgi.Controller): raise webob.exc.HTTPBadRequest(explanation=msg) force = params.get('force', False) - if isinstance(force, basestring): + if isinstance(force, six.string_types): try: force = strutils.bool_from_string(force, strict=False) except ValueError: @@ -337,7 +337,7 @@ class VolumeActionsController(wsgi.Controller): msg = _("Must specify readonly in request.") raise webob.exc.HTTPBadRequest(explanation=msg) - if isinstance(readonly_flag, basestring): + if isinstance(readonly_flag, six.string_types): try: readonly_flag = strutils.bool_from_string(readonly_flag, strict=True) @@ -382,7 +382,7 @@ class VolumeActionsController(wsgi.Controller): msg = _("Must specify bootable in request.") raise webob.exc.HTTPBadRequest(explanation=msg) - if isinstance(bootable, basestring): + if isinstance(bootable, six.string_types): try: bootable = strutils.bool_from_string(bootable, strict=True) diff --git a/cinder/api/xmlutil.py b/cinder/api/xmlutil.py index a867555fa..831242c84 100644 --- a/cinder/api/xmlutil.py +++ b/cinder/api/xmlutil.py @@ -208,7 +208,7 @@ class TemplateElement(object): def __getitem__(self, idx): """Retrieve a child node by index or name.""" - if isinstance(idx, basestring): + if isinstance(idx, six.string_types): # Allow access by node name return self._childmap[idx] else: diff --git a/cinder/context.py b/cinder/context.py index 774769cd7..23edc03d8 100644 --- a/cinder/context.py +++ b/cinder/context.py @@ -22,6 +22,7 @@ import copy from oslo_context import context from oslo_log import log as logging from oslo_utils import timeutils +import six from cinder.i18n import _ from cinder import policy @@ -69,7 +70,7 @@ class RequestContext(context.RequestContext): self.remote_address = remote_address if not timestamp: timestamp = timeutils.utcnow() - elif isinstance(timestamp, basestring): + elif isinstance(timestamp, six.string_types): timestamp = timeutils.parse_isotime(timestamp) self.timestamp = timestamp self.quota_class = quota_class diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 1b0941675..b0536c889 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -1387,7 +1387,7 @@ def volume_get_all_by_host(context, host, filters=None): # now be either form below: # Host # Host#Pool - if host and isinstance(host, basestring): + if host and isinstance(host, six.string_types): session = get_session() with session.begin(): host_attr = getattr(models.Volume, 'host') diff --git a/cinder/image/glance.py b/cinder/image/glance.py index 893e1ab3c..be32766b6 100644 --- a/cinder/image/glance.py +++ b/cinder/image/glance.py @@ -400,13 +400,13 @@ def _convert_timestamps_to_datetimes(image_meta): # NOTE(bcwaldon): used to store non-string data in glance metadata def _json_loads(properties, attr): prop = properties[attr] - if isinstance(prop, basestring): + if isinstance(prop, six.string_types): properties[attr] = jsonutils.loads(prop) def _json_dumps(properties, attr): prop = properties[attr] - if not isinstance(prop, basestring): + if not isinstance(prop, six.string_types): properties[attr] = jsonutils.dumps(prop) diff --git a/cinder/quota.py b/cinder/quota.py index 808710f78..ae886110c 100644 --- a/cinder/quota.py +++ b/cinder/quota.py @@ -23,6 +23,7 @@ from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils from oslo_utils import timeutils +import six from cinder import context from cinder import db @@ -593,7 +594,7 @@ class QuotaEngine(object): if not quota_driver_class: quota_driver_class = CONF.quota_driver - if isinstance(quota_driver_class, basestring): + if isinstance(quota_driver_class, six.string_types): quota_driver_class = importutils.import_object(quota_driver_class) self._resources = {} diff --git a/cinder/tests/unit/fake_utils.py b/cinder/tests/unit/fake_utils.py index 26b5cba07..885f473e4 100644 --- a/cinder/tests/unit/fake_utils.py +++ b/cinder/tests/unit/fake_utils.py @@ -19,6 +19,7 @@ import re from eventlet import greenthread from oslo_concurrency import processutils from oslo_log import log as logging +import six from cinder import utils @@ -78,7 +79,7 @@ def fake_execute(*cmd_parts, **kwargs): LOG.debug('Faked command matched %s' % fake_replier[0]) break - if isinstance(reply_handler, basestring): + if isinstance(reply_handler, six.string_types): # If the reply handler is a string, return it as stdout reply = reply_handler, '' else: diff --git a/cinder/volume/drivers/ibm/storwize_svc/ssh.py b/cinder/volume/drivers/ibm/storwize_svc/ssh.py index ae8d91bae..15c6e384b 100644 --- a/cinder/volume/drivers/ibm/storwize_svc/ssh.py +++ b/cinder/volume/drivers/ibm/storwize_svc/ssh.py @@ -18,6 +18,7 @@ import re from oslo_concurrency import processutils from oslo_log import log as logging +import six from cinder import exception from cinder.i18n import _, _LE @@ -380,7 +381,7 @@ class CLIResponse(object): vs = [] for k in keys: v = a.get(k, None) - if isinstance(v, basestring) or v is None: + if isinstance(v, six.string_types) or v is None: v = [v] if isinstance(v, list): vs.append(v) @@ -414,7 +415,7 @@ class CLIResponse(object): else: yield [] - if isinstance(self.raw, basestring): + if isinstance(self.raw, six.string_types): stdout, stderr = self.raw, '' else: stdout, stderr = self.raw diff --git a/cinder/volume/drivers/violin/v6000_common.py b/cinder/volume/drivers/violin/v6000_common.py index c14dbfd9a..b0e8d67eb 100644 --- a/cinder/volume/drivers/violin/v6000_common.py +++ b/cinder/volume/drivers/violin/v6000_common.py @@ -34,6 +34,7 @@ import time from oslo_config import cfg from oslo_log import log as logging from oslo_utils import importutils +import six from cinder import exception from cinder.i18n import _, _LE, _LW, _LI @@ -375,7 +376,7 @@ class V6000Common(object): start = time.time() done = False - if isinstance(success_msgs, basestring): + if isinstance(success_msgs, six.string_types): success_msgs = [success_msgs] while not done: @@ -435,7 +436,7 @@ class V6000Common(object): request_needed = True verify_needed = True - if isinstance(request_success_msgs, basestring): + if isinstance(request_success_msgs, six.string_types): request_success_msgs = [request_success_msgs] rargs = rargs if rargs else []