Remove six in files under cinder/*
Replace the following items with Python 3 style code. - six.add_metaclass - six.PY2 - six.text_type - six.string_types - six.wraps Change-Id: I393ee1f1627a993021af395c02bb936a7a476aec Implements: blueprint six-removal
This commit is contained in:
parent
6ad1ab0c72
commit
04a2683b2d
@ -26,7 +26,6 @@ from oslo_context import context
|
|||||||
from oslo_db.sqlalchemy import enginefacade
|
from oslo_db.sqlalchemy import enginefacade
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import six
|
|
||||||
|
|
||||||
from cinder import exception
|
from cinder import exception
|
||||||
from cinder.i18n import _
|
from cinder.i18n import _
|
||||||
@ -105,7 +104,7 @@ class RequestContext(context.RequestContext):
|
|||||||
self.remote_address = remote_address
|
self.remote_address = remote_address
|
||||||
if not timestamp:
|
if not timestamp:
|
||||||
timestamp = timeutils.utcnow()
|
timestamp = timeutils.utcnow()
|
||||||
elif isinstance(timestamp, six.string_types):
|
elif isinstance(timestamp, str):
|
||||||
timestamp = timeutils.parse_isotime(timestamp)
|
timestamp = timeutils.parse_isotime(timestamp)
|
||||||
self.timestamp = timestamp
|
self.timestamp = timestamp
|
||||||
self.quota_class = quota_class
|
self.quota_class = quota_class
|
||||||
|
@ -24,7 +24,6 @@ SHOULD include dedicated exception logging.
|
|||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_versionedobjects import exception as obj_exc
|
from oslo_versionedobjects import exception as obj_exc
|
||||||
import six
|
|
||||||
import webob.exc
|
import webob.exc
|
||||||
from webob.util import status_generic_reasons
|
from webob.util import status_generic_reasons
|
||||||
from webob.util import status_reasons
|
from webob.util import status_reasons
|
||||||
@ -85,7 +84,7 @@ class CinderException(Exception):
|
|||||||
# NOTE(tommylikehu): If this is a cinder exception it will
|
# NOTE(tommylikehu): If this is a cinder exception it will
|
||||||
# return the msg object, so we won't be preventing
|
# return the msg object, so we won't be preventing
|
||||||
# translations.
|
# translations.
|
||||||
self.kwargs[k] = six.text_type(v)
|
self.kwargs[k] = str(v)
|
||||||
|
|
||||||
if self._should_format():
|
if self._should_format():
|
||||||
try:
|
try:
|
||||||
@ -100,7 +99,7 @@ class CinderException(Exception):
|
|||||||
# NOTE(tommylikehu): If this is a cinder exception it will
|
# NOTE(tommylikehu): If this is a cinder exception it will
|
||||||
# return the msg object, so we won't be preventing
|
# return the msg object, so we won't be preventing
|
||||||
# translations.
|
# translations.
|
||||||
message = six.text_type(message)
|
message = str(message)
|
||||||
|
|
||||||
# NOTE(luisg): We put the actual message in 'msg' so that we can access
|
# NOTE(luisg): We put the actual message in 'msg' so that we can access
|
||||||
# it, because if we try to access the message via 'message' it will be
|
# it, because if we try to access the message via 'message' it will be
|
||||||
|
@ -25,13 +25,14 @@ __all__ = [
|
|||||||
'get_notifier',
|
'get_notifier',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
import functools
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import oslo_messaging as messaging
|
import oslo_messaging as messaging
|
||||||
from oslo_messaging.rpc import dispatcher
|
from oslo_messaging.rpc import dispatcher
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
profiler = importutils.try_import('osprofiler.profiler')
|
profiler = importutils.try_import('osprofiler.profiler')
|
||||||
import six
|
|
||||||
|
|
||||||
import cinder.context
|
import cinder.context
|
||||||
import cinder.exception
|
import cinder.exception
|
||||||
@ -177,7 +178,7 @@ def assert_min_rpc_version(min_ver, exc=None):
|
|||||||
exc = cinder.exception.ServiceTooOld
|
exc = cinder.exception.ServiceTooOld
|
||||||
|
|
||||||
def decorator(f):
|
def decorator(f):
|
||||||
@six.wraps(f)
|
@functools.wraps(f)
|
||||||
def _wrapper(self, *args, **kwargs):
|
def _wrapper(self, *args, **kwargs):
|
||||||
if not self.client.can_send_version(min_ver):
|
if not self.client.can_send_version(min_ver):
|
||||||
msg = _('One of %(binary)s services is too old to accept '
|
msg = _('One of %(binary)s services is too old to accept '
|
||||||
|
@ -25,7 +25,6 @@ from oslo_config import cfg
|
|||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
import paramiko
|
import paramiko
|
||||||
import six
|
|
||||||
|
|
||||||
from cinder import exception
|
from cinder import exception
|
||||||
from cinder.i18n import _
|
from cinder.i18n import _
|
||||||
@ -159,7 +158,7 @@ class SSHPool(pools.Pool):
|
|||||||
transport.set_keepalive(self.conn_timeout)
|
transport.set_keepalive(self.conn_timeout)
|
||||||
return ssh
|
return ssh
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
msg = _("Error connecting via ssh: %s") % six.text_type(e)
|
msg = _("Error connecting via ssh: %s") % str(e)
|
||||||
LOG.error(msg)
|
LOG.error(msg)
|
||||||
raise paramiko.SSHException(msg)
|
raise paramiko.SSHException(msg)
|
||||||
|
|
||||||
|
@ -46,12 +46,10 @@ from oslo_concurrency import lockutils
|
|||||||
from oslo_concurrency import processutils
|
from oslo_concurrency import processutils
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_utils import encodeutils
|
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
from oslo_utils import strutils
|
from oslo_utils import strutils
|
||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
import six
|
|
||||||
import tenacity
|
import tenacity
|
||||||
|
|
||||||
from cinder import exception
|
from cinder import exception
|
||||||
@ -309,7 +307,7 @@ def monkey_patch():
|
|||||||
if isinstance(module_data[key], pyclbr.Class):
|
if isinstance(module_data[key], pyclbr.Class):
|
||||||
clz = importutils.import_class("%s.%s" % (module, key))
|
clz = importutils.import_class("%s.%s" % (module, key))
|
||||||
# On Python 3, unbound methods are regular functions
|
# On Python 3, unbound methods are regular functions
|
||||||
predicate = inspect.isfunction if six.PY3 else inspect.ismethod
|
predicate = inspect.isfunction
|
||||||
for method, func in inspect.getmembers(clz, predicate):
|
for method, func in inspect.getmembers(clz, predicate):
|
||||||
setattr(
|
setattr(
|
||||||
clz, method,
|
clz, method,
|
||||||
@ -415,8 +413,7 @@ def tempdir(**kwargs):
|
|||||||
try:
|
try:
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
LOG.debug('Could not remove tmpdir: %s',
|
LOG.debug('Could not remove tmpdir: %s', str(e))
|
||||||
six.text_type(e))
|
|
||||||
|
|
||||||
|
|
||||||
def get_root_helper():
|
def get_root_helper():
|
||||||
@ -670,7 +667,7 @@ def retry(exceptions, interval=1, retries=3, backoff_rate=2,
|
|||||||
|
|
||||||
def _decorator(f):
|
def _decorator(f):
|
||||||
|
|
||||||
@six.wraps(f)
|
@functools.wraps(f)
|
||||||
def _wrapper(*args, **kwargs):
|
def _wrapper(*args, **kwargs):
|
||||||
r = tenacity.Retrying(
|
r = tenacity.Retrying(
|
||||||
sleep=tenacity.nap.sleep,
|
sleep=tenacity.nap.sleep,
|
||||||
@ -696,13 +693,10 @@ def convert_str(text):
|
|||||||
encode Unicode using encodeutils.safe_encode()
|
encode Unicode using encodeutils.safe_encode()
|
||||||
* convert to Unicode on Python 3: decode bytes from UTF-8
|
* convert to Unicode on Python 3: decode bytes from UTF-8
|
||||||
"""
|
"""
|
||||||
if six.PY2:
|
if isinstance(text, bytes):
|
||||||
return encodeutils.to_utf8(text)
|
return text.decode('utf-8')
|
||||||
else:
|
else:
|
||||||
if isinstance(text, bytes):
|
return text
|
||||||
return text.decode('utf-8')
|
|
||||||
else:
|
|
||||||
return text
|
|
||||||
|
|
||||||
|
|
||||||
def trace_method(f):
|
def trace_method(f):
|
||||||
@ -778,7 +772,7 @@ def trace(*dec_args, **dec_kwargs):
|
|||||||
logger.debug('==> %(func)s: call %(all_args)r',
|
logger.debug('==> %(func)s: call %(all_args)r',
|
||||||
{'func': func_name,
|
{'func': func_name,
|
||||||
'all_args': strutils.mask_password(
|
'all_args': strutils.mask_password(
|
||||||
six.text_type(all_args))})
|
str(all_args))})
|
||||||
|
|
||||||
start_time = time.time() * 1000
|
start_time = time.time() * 1000
|
||||||
try:
|
try:
|
||||||
@ -794,7 +788,7 @@ def trace(*dec_args, **dec_kwargs):
|
|||||||
|
|
||||||
if isinstance(result, dict):
|
if isinstance(result, dict):
|
||||||
mask_result = strutils.mask_dict_password(result)
|
mask_result = strutils.mask_dict_password(result)
|
||||||
elif isinstance(result, six.string_types):
|
elif isinstance(result, str):
|
||||||
mask_result = strutils.mask_password(result)
|
mask_result = strutils.mask_password(result)
|
||||||
else:
|
else:
|
||||||
mask_result = result
|
mask_result = result
|
||||||
@ -822,8 +816,7 @@ class TraceWrapperMetaclass(type):
|
|||||||
decorated with the trace_method decorator.
|
decorated with the trace_method decorator.
|
||||||
|
|
||||||
To use the metaclass you define a class like so:
|
To use the metaclass you define a class like so:
|
||||||
@six.add_metaclass(utils.TraceWrapperMetaclass)
|
class MyClass(object, metaclass=utils.TraceWrapperMetaclass):
|
||||||
class MyClass(object):
|
|
||||||
"""
|
"""
|
||||||
def __new__(meta, classname, bases, classDict):
|
def __new__(meta, classname, bases, classDict):
|
||||||
newClassDict = {}
|
newClassDict = {}
|
||||||
@ -877,7 +870,7 @@ def build_or_str(elements, str_format=None):
|
|||||||
if not elements:
|
if not elements:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
if not isinstance(elements, six.string_types):
|
if not isinstance(elements, str):
|
||||||
elements = _(' or ').join(elements)
|
elements = _(' or ').join(elements)
|
||||||
|
|
||||||
if str_format:
|
if str_format:
|
||||||
|
Loading…
Reference in New Issue
Block a user