py3: use six.string_types instead of basestring
six is the canonical compatibility library for supporting Python 2 and 3 in a single codebase. The basestring was removed in Python 3 and we should use 'six.string_types' instead of 'basestring' to make code compatible with py 2 and 3 as well. Partially-implements blueprint py3-compatibility Change-Id: Idb452afdc2a828089627e14f90c53f3967ceb2ad
This commit is contained in:
parent
ca079b22e8
commit
8abe92efa9
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import six # noqa
|
||||||
|
|
||||||
from tempest.api.share import base
|
from tempest.api.share import base
|
||||||
from tempest import config_share as config
|
from tempest import config_share as config
|
||||||
from tempest import exceptions
|
from tempest import exceptions
|
||||||
|
@ -206,8 +208,8 @@ class ShareServersAdminTest(base.BaseSharesAdminTest):
|
||||||
self.assertIn(int(resp["status"]), test.HTTP_SUCCESS)
|
self.assertIn(int(resp["status"]), test.HTTP_SUCCESS)
|
||||||
# If details are present they and their values should be only strings
|
# If details are present they and their values should be only strings
|
||||||
for k, v in details.iteritems():
|
for k, v in details.iteritems():
|
||||||
self.assertTrue(isinstance(k, basestring))
|
self.assertTrue(isinstance(k, six.string_types))
|
||||||
self.assertTrue(isinstance(v, basestring))
|
self.assertTrue(isinstance(v, six.string_types))
|
||||||
|
|
||||||
@test.attr(type=["gate", "smoke", ])
|
@test.attr(type=["gate", "smoke", ])
|
||||||
def test_delete_share_server(self):
|
def test_delete_share_server(self):
|
||||||
|
|
|
@ -50,12 +50,13 @@ class VolumeTypeExtraSpecsController(wsgi.Controller):
|
||||||
# with length in range(1, 256)
|
# with length in range(1, 256)
|
||||||
is_valid = True
|
is_valid = True
|
||||||
for k, v in six.iteritems(extra_specs):
|
for k, v in six.iteritems(extra_specs):
|
||||||
if not (isinstance(k, basestring) and len(k) in range(1, 256)):
|
if not (isinstance(k, six.string_types) and
|
||||||
|
len(k) in range(1, 256)):
|
||||||
is_valid = False
|
is_valid = False
|
||||||
break
|
break
|
||||||
if isinstance(v, dict):
|
if isinstance(v, dict):
|
||||||
self._verify_extra_specs(v)
|
self._verify_extra_specs(v)
|
||||||
elif isinstance(v, basestring):
|
elif isinstance(v, six.string_types):
|
||||||
if len(v) not in range(1, 256):
|
if len(v) not in range(1, 256):
|
||||||
is_valid = False
|
is_valid = False
|
||||||
break
|
break
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
import six
|
||||||
|
|
||||||
from manila import utils
|
from manila import utils
|
||||||
|
|
||||||
|
@ -205,7 +206,7 @@ class TemplateElement(object):
|
||||||
def __getitem__(self, idx):
|
def __getitem__(self, idx):
|
||||||
"""Retrieve a child node by index or name."""
|
"""Retrieve a child node by index or name."""
|
||||||
|
|
||||||
if isinstance(idx, basestring):
|
if isinstance(idx, six.string_types):
|
||||||
# Allow access by node name
|
# Allow access by node name
|
||||||
return self._childmap[idx]
|
return self._childmap[idx]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
import copy
|
import copy
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from manila.openstack.common import local
|
from manila.openstack.common import local
|
||||||
from manila.openstack.common import log as logging
|
from manila.openstack.common import log as logging
|
||||||
from manila.openstack.common import timeutils
|
from manila.openstack.common import timeutils
|
||||||
|
@ -73,7 +75,7 @@ class RequestContext(object):
|
||||||
self.remote_address = remote_address
|
self.remote_address = remote_address
|
||||||
if not timestamp:
|
if not timestamp:
|
||||||
timestamp = timeutils.utcnow()
|
timestamp = timeutils.utcnow()
|
||||||
if isinstance(timestamp, basestring):
|
if isinstance(timestamp, six.string_types):
|
||||||
timestamp = timeutils.parse_strtime(timestamp)
|
timestamp = timeutils.parse_strtime(timestamp)
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
if service_catalog:
|
if service_catalog:
|
||||||
|
|
|
@ -736,7 +736,7 @@ class QuotaEngine(object):
|
||||||
return self.__driver
|
return self.__driver
|
||||||
if not self._driver_cls:
|
if not self._driver_cls:
|
||||||
self._driver_cls = CONF.quota_driver
|
self._driver_cls = CONF.quota_driver
|
||||||
if isinstance(self._driver_cls, basestring):
|
if isinstance(self._driver_cls, six.string_types):
|
||||||
self._driver_cls = importutils.import_object(self._driver_cls)
|
self._driver_cls = importutils.import_object(self._driver_cls)
|
||||||
self.__driver = self._driver_cls
|
self.__driver = self._driver_cls
|
||||||
return self.__driver
|
return self.__driver
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from eventlet import greenthread
|
from eventlet import greenthread
|
||||||
|
import six
|
||||||
|
|
||||||
from manila import exception
|
from manila import exception
|
||||||
from manila.openstack.common import log as logging
|
from manila.openstack.common import log as logging
|
||||||
|
@ -80,7 +81,7 @@ def fake_execute(*cmd_parts, **kwargs):
|
||||||
LOG.debug('Faked command matched %s' % fake_replier[0])
|
LOG.debug('Faked command matched %s' % fake_replier[0])
|
||||||
break
|
break
|
||||||
|
|
||||||
if isinstance(reply_handler, basestring):
|
if isinstance(reply_handler, six.string_types):
|
||||||
# If the reply handler is a string, return it as stdout
|
# If the reply handler is a string, return it as stdout
|
||||||
reply = reply_handler, ''
|
reply = reply_handler, ''
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -29,6 +29,7 @@ import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
import six
|
||||||
|
|
||||||
from manila.openstack.common import importutils
|
from manila.openstack.common import importutils
|
||||||
|
|
||||||
|
@ -164,7 +165,7 @@ def _print_opt(opt):
|
||||||
if opt_default is None:
|
if opt_default is None:
|
||||||
print('#%s=<None>' % opt_name)
|
print('#%s=<None>' % opt_name)
|
||||||
elif opt_type == STROPT:
|
elif opt_type == STROPT:
|
||||||
assert(isinstance(opt_default, basestring))
|
assert(isinstance(opt_default, six.string_types))
|
||||||
print('#%s=%s' % (opt_name, _sanitize_default(opt_default)))
|
print('#%s=%s' % (opt_name, _sanitize_default(opt_default)))
|
||||||
elif opt_type == BOOLOPT:
|
elif opt_type == BOOLOPT:
|
||||||
assert(isinstance(opt_default, bool))
|
assert(isinstance(opt_default, bool))
|
||||||
|
|
Loading…
Reference in New Issue