Fix basestring issue for Python 2/3 compatible code.
replace basestring with six.string_types need python-six module Story: 2003430 Task: 26518 Change-Id: If8864a1af26274211d8d0e125071794d18dfed01 Signed-off-by: Sun Austin <austin.sun@intel.com>
This commit is contained in:
parent
24cd0141ae
commit
f21e0c13d7
|
@ -17,7 +17,7 @@ BuildRequires: util-linux
|
|||
BuildRequires: systemd
|
||||
BuildRequires: systemd-devel
|
||||
Requires: python-libs
|
||||
|
||||
Requires: python-six
|
||||
# Needed for /etc/init.d, can be removed when we go fully systemd
|
||||
Requires: chkconfig
|
||||
# Needed for /etc/pmon.d
|
||||
|
|
|
@ -22,6 +22,7 @@ import ast
|
|||
import datetime
|
||||
import iso8601
|
||||
import netaddr
|
||||
import six
|
||||
|
||||
from sm_api.openstack.common import timeutils
|
||||
|
||||
|
@ -42,7 +43,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)
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ import re
|
|||
import socket
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import six
|
||||
from oslo_config import cfg
|
||||
|
||||
from sm_api.openstack.common import gettextutils
|
||||
|
@ -221,7 +221,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))
|
||||
|
|
|
@ -56,7 +56,7 @@ _nasty_type_tests = [inspect.ismodule, inspect.isclass, inspect.ismethod,
|
|||
inspect.iscode, inspect.isbuiltin, inspect.isroutine,
|
||||
inspect.isabstract]
|
||||
|
||||
_simple_types = (types.NoneType, int, basestring, bool, float, long)
|
||||
_simple_types = (types.NoneType, int, six.string_types, bool, float, long)
|
||||
|
||||
|
||||
def to_primitive(value, convert_instances=False, convert_datetime=True,
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
|
||||
import uuid
|
||||
import six
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
|
@ -166,7 +167,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)
|
||||
|
|
|
@ -428,7 +428,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
|
||||
|
@ -693,7 +693,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)
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ Time related utilities and helper functions.
|
|||
|
||||
import calendar
|
||||
import datetime
|
||||
|
||||
import six
|
||||
import iso8601
|
||||
|
||||
|
||||
|
@ -79,14 +79,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)
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ Source0: %{name}-%{version}.tar.gz
|
|||
BuildRequires: python
|
||||
BuildRequires: python-setuptools
|
||||
Requires: python-libs
|
||||
|
||||
Requires: python-six
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ import os
|
|||
import sys
|
||||
import textwrap
|
||||
import uuid
|
||||
|
||||
import prettytable
|
||||
import six
|
||||
|
||||
from sm_client import exc
|
||||
from sm_client.openstack.common import importutils
|
||||
|
@ -134,7 +134,7 @@ def print_mapping(data, fields, dict_property="Property", wrap=0):
|
|||
v = textwrap.fill(str(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:
|
||||
|
@ -161,7 +161,7 @@ def print_dict(d, fields, dict_property="Property", wrap=0):
|
|||
v = textwrap.fill(str(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:
|
||||
|
|
|
@ -30,7 +30,7 @@ import re
|
|||
import socket
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import six
|
||||
from oslo_config import cfg
|
||||
|
||||
from sm_client.openstack.common import gettextutils
|
||||
|
@ -221,7 +221,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))
|
||||
|
|
Loading…
Reference in New Issue