Merge "Fix basestring issue for Python 2/3 compatible code."
This commit is contained in:
commit
68efbe8d72
|
@ -17,6 +17,8 @@ Requires: python-prettytable
|
|||
Requires: bash-completion
|
||||
Requires: python-neutronclient
|
||||
Requires: python-keystoneclient
|
||||
# Needed for python2 and python3 compatible
|
||||
Requires: python-six
|
||||
|
||||
%description
|
||||
System Client and CLI
|
||||
|
|
|
@ -456,7 +456,7 @@ def print_dict(d, dict_property="Property", wrap=0):
|
|||
v = textwrap.fill(six.text_type(v), wrap)
|
||||
# if value has a newline, add in multiple rows
|
||||
# e.g. fault with stacktrace
|
||||
if v and isinstance(v, basestring) and r'\n' in v:
|
||||
if v and isinstance(v, six.string_types) and r'\n' in v:
|
||||
lines = v.strip().split(r'\n')
|
||||
col1 = k
|
||||
for line in lines:
|
||||
|
|
|
@ -26,6 +26,7 @@ import re
|
|||
import socket
|
||||
import sys
|
||||
import textwrap
|
||||
import six
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
|
@ -217,7 +218,7 @@ def _print_opt(opt):
|
|||
if opt_default is None:
|
||||
print '#%s=<None>' % opt_name
|
||||
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))
|
||||
elif opt_type == BOOLOPT:
|
||||
assert(isinstance(opt_default, bool))
|
||||
|
|
|
@ -19,6 +19,8 @@ Requires: python-pbr
|
|||
# Requires: oslo.config
|
||||
|
||||
BuildRequires: systemd
|
||||
# Needed for python2 and python3 compatible
|
||||
Requires: python-six
|
||||
|
||||
%description
|
||||
System Inventory
|
||||
|
|
|
@ -46,7 +46,7 @@ def datetime_or_none(dt):
|
|||
|
||||
|
||||
def datetime_or_str_or_none(val):
|
||||
if isinstance(val, basestring):
|
||||
if isinstance(val, six.string_types):
|
||||
return timeutils.parse_isotime(val)
|
||||
return datetime_or_none(val)
|
||||
|
||||
|
@ -55,7 +55,7 @@ def bool_or_none(val):
|
|||
"""Attempt to parse an boolean value, or None."""
|
||||
if val is None:
|
||||
return False
|
||||
elif isinstance(val, basestring):
|
||||
elif isinstance(val, six.string_types):
|
||||
return bool(val.lower() in ['y', 'n', 'yes', 'no', 'true', 'false'])
|
||||
else:
|
||||
return bool(int(val) != 0)
|
||||
|
@ -98,7 +98,7 @@ def list_of_strings_or_none(val):
|
|||
return val
|
||||
if not isinstance(val, list):
|
||||
raise ValueError(_('A list of strings is required here'))
|
||||
if not all([isinstance(x, basestring) for x in val]):
|
||||
if not all([isinstance(x, six.string_types) for x in val]):
|
||||
raise ValueError(_('Invalid values found in list '
|
||||
'(strings are required)'))
|
||||
return val
|
||||
|
@ -121,7 +121,7 @@ def uuid_or_none(val):
|
|||
"""Attempt to dictify a value, or None."""
|
||||
if val is None:
|
||||
return None
|
||||
elif isinstance(val, basestring):
|
||||
elif isinstance(val, six.string_types):
|
||||
return str(uuid.UUID(val.strip()))
|
||||
raise ValueError(_('Invalid UUID value %s') % val)
|
||||
|
||||
|
@ -130,7 +130,7 @@ def ipv4_mode_or_none(val):
|
|||
"""Attempt to validate an IPv4 address mode."""
|
||||
if val is None:
|
||||
return None
|
||||
elif not isinstance(val, basestring):
|
||||
elif not isinstance(val, six.string_types):
|
||||
raise ValueError(_('Invalid IPv4 address mode %s') % val)
|
||||
elif val not in constants.IPV4_ADDRESS_MODES:
|
||||
raise ValueError(_('Unsupported IPv4 address mode %s') % val)
|
||||
|
@ -141,7 +141,7 @@ def ipv6_mode_or_none(val):
|
|||
"""Attempt to validate an IPv4 address mode."""
|
||||
if val is None:
|
||||
return None
|
||||
elif not isinstance(val, basestring):
|
||||
elif not isinstance(val, six.string_types):
|
||||
raise ValueError(_('Invalid IPv6 address mode %s') % val)
|
||||
elif val not in constants.IPV6_ADDRESS_MODES:
|
||||
raise ValueError(_('Unsupported IPv6 address mode %s') % val)
|
||||
|
|
|
@ -26,6 +26,7 @@ import re
|
|||
import socket
|
||||
import sys
|
||||
import textwrap
|
||||
import six
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
|
@ -217,7 +218,7 @@ def _print_opt(opt):
|
|||
if opt_default is None:
|
||||
print '#%s=<None>' % opt_name
|
||||
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))
|
||||
elif opt_type == BOOLOPT:
|
||||
assert(isinstance(opt_default, bool))
|
||||
|
|
|
@ -51,7 +51,7 @@ _nasty_type_tests = [inspect.ismodule, inspect.isclass, inspect.ismethod,
|
|||
inspect.iscode, inspect.isbuiltin, inspect.isroutine,
|
||||
inspect.isabstract]
|
||||
|
||||
_simple_types = (type(None), six.integer_types, basestring, bool, float)
|
||||
_simple_types = (type(None), six.integer_types, six.string_types, bool, float)
|
||||
|
||||
|
||||
def to_primitive(value, convert_instances=False, convert_datetime=True,
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# under the License.
|
||||
|
||||
import uuid
|
||||
import six
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
|
@ -162,7 +163,7 @@ def add_driver(notification_driver):
|
|||
"""Add a notification driver at runtime."""
|
||||
# Make sure the driver list is initialized.
|
||||
_get_drivers()
|
||||
if isinstance(notification_driver, basestring):
|
||||
if isinstance(notification_driver, six.string_types):
|
||||
# Load and add
|
||||
try:
|
||||
driver = importutils.import_module(notification_driver)
|
||||
|
|
|
@ -423,7 +423,7 @@ def _parse_list_rule(rule):
|
|||
continue
|
||||
|
||||
# Handle bare strings
|
||||
if isinstance(inner_rule, basestring):
|
||||
if isinstance(inner_rule, six.string_types):
|
||||
inner_rule = [inner_rule]
|
||||
|
||||
# Parse the inner rules into Check objects
|
||||
|
@ -687,7 +687,7 @@ def parse_rule(rule):
|
|||
"""
|
||||
|
||||
# If the rule is a string, it's in the policy language
|
||||
if isinstance(rule, basestring):
|
||||
if isinstance(rule, six.string_types):
|
||||
return _parse_text_rule(rule)
|
||||
return _parse_list_rule(rule)
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import calendar
|
|||
import datetime
|
||||
|
||||
import iso8601
|
||||
import six
|
||||
|
||||
|
||||
# ISO 8601 extended time format with microseconds
|
||||
|
@ -75,14 +76,14 @@ def normalize_time(timestamp):
|
|||
|
||||
def is_older_than(before, seconds):
|
||||
"""Return True if before is older than seconds."""
|
||||
if isinstance(before, basestring):
|
||||
if isinstance(before, six.string_types):
|
||||
before = parse_strtime(before).replace(tzinfo=None)
|
||||
return utcnow() - before > datetime.timedelta(seconds=seconds)
|
||||
|
||||
|
||||
def is_newer_than(after, seconds):
|
||||
"""Return True if after is newer than seconds."""
|
||||
if isinstance(after, basestring):
|
||||
if isinstance(after, six.string_types):
|
||||
after = parse_strtime(after).replace(tzinfo=None)
|
||||
return after - utcnow() > datetime.timedelta(seconds=seconds)
|
||||
|
||||
|
|
Loading…
Reference in New Issue