Remove all usage of six library
Convert all code to not require six library and instead use python 3.x logic. Change-Id: I32d9f261a219ab4dc95a697d9ab1ff5d9298aee8
This commit is contained in:
parent
c5f9385b6c
commit
7d03255181
@ -15,8 +15,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
|
|
||||||
class BaseDataModel(object):
|
class BaseDataModel(object):
|
||||||
def to_dict(self, calling_classes=None, recurse=False,
|
def to_dict(self, calling_classes=None, recurse=False,
|
||||||
@ -52,8 +50,6 @@ class BaseDataModel(object):
|
|||||||
calling_classes=calling_classes + [type(self)])
|
calling_classes=calling_classes + [type(self)])
|
||||||
else:
|
else:
|
||||||
ret[attr] = None
|
ret[attr] = None
|
||||||
elif six.PY2 and isinstance(value, six.text_type):
|
|
||||||
ret[attr.encode('utf8')] = value.encode('utf8')
|
|
||||||
elif isinstance(value, UnsetType):
|
elif isinstance(value, UnsetType):
|
||||||
if render_unsets:
|
if render_unsets:
|
||||||
ret[attr] = None
|
ret[attr] = None
|
||||||
|
@ -57,13 +57,10 @@ assert_not_equal_end_with_none_re = re.compile(
|
|||||||
r"(.)*assertNotEqual\(.+, None\)")
|
r"(.)*assertNotEqual\(.+, None\)")
|
||||||
assert_not_equal_start_with_none_re = re.compile(
|
assert_not_equal_start_with_none_re = re.compile(
|
||||||
r"(.)*assertNotEqual\(None, .+\)")
|
r"(.)*assertNotEqual\(None, .+\)")
|
||||||
assert_no_xrange_re = re.compile(
|
|
||||||
r"\s*xrange\s*\(")
|
|
||||||
revert_must_have_kwargs_re = re.compile(
|
revert_must_have_kwargs_re = re.compile(
|
||||||
r'[ ]*def revert\(.+,[ ](?!\*\*kwargs)\w+\):')
|
r'[ ]*def revert\(.+,[ ](?!\*\*kwargs)\w+\):')
|
||||||
untranslated_exception_re = re.compile(r"raise (?:\w*)\((.*)\)")
|
untranslated_exception_re = re.compile(r"raise (?:\w*)\((.*)\)")
|
||||||
no_basestring_re = re.compile(r"\bbasestring\b")
|
no_basestring_re = re.compile(r"\bbasestring\b")
|
||||||
no_iteritems_re = re.compile(r".*\.iteritems\(\)")
|
|
||||||
no_eventlet_re = re.compile(r'(import|from)\s+[(]?eventlet')
|
no_eventlet_re = re.compile(r'(import|from)\s+[(]?eventlet')
|
||||||
no_line_continuation_backslash_re = re.compile(r'.*(\\)\n')
|
no_line_continuation_backslash_re = re.compile(r'.*(\\)\n')
|
||||||
no_logging_re = re.compile(r'(import|from)\s+[(]?logging')
|
no_logging_re = re.compile(r'(import|from)\s+[(]?logging')
|
||||||
@ -182,15 +179,6 @@ def no_log_warn(logical_line):
|
|||||||
yield(0, "O339:Use LOG.warning() rather than LOG.warn()")
|
yield(0, "O339:Use LOG.warning() rather than LOG.warn()")
|
||||||
|
|
||||||
|
|
||||||
def no_xrange(logical_line):
|
|
||||||
"""Disallow 'xrange()'
|
|
||||||
|
|
||||||
O340
|
|
||||||
"""
|
|
||||||
if assert_no_xrange_re.match(logical_line):
|
|
||||||
yield(0, "O340: Do not use xrange().")
|
|
||||||
|
|
||||||
|
|
||||||
def no_translate_logs(logical_line, filename):
|
def no_translate_logs(logical_line, filename):
|
||||||
"""O341 - Don't translate logs.
|
"""O341 - Don't translate logs.
|
||||||
|
|
||||||
@ -247,24 +235,7 @@ def check_no_basestring(logical_line):
|
|||||||
"""
|
"""
|
||||||
if no_basestring_re.search(logical_line):
|
if no_basestring_re.search(logical_line):
|
||||||
msg = ("O343: basestring is not Python3-compatible, use "
|
msg = ("O343: basestring is not Python3-compatible, use "
|
||||||
"six.string_types instead.")
|
"str instead.")
|
||||||
yield(0, msg)
|
|
||||||
|
|
||||||
|
|
||||||
def check_python3_no_iteritems(logical_line):
|
|
||||||
"""O344 - Use dict.items() instead of dict.iteritems().
|
|
||||||
|
|
||||||
:param logical_line: The logical line to check.
|
|
||||||
:returns: None if the logical line passes the check, otherwise a tuple
|
|
||||||
is yielded that contains the offending index in logical line
|
|
||||||
and a message describe the check validation failure.
|
|
||||||
"""
|
|
||||||
if no_iteritems_re.search(logical_line):
|
|
||||||
msg = ("O344: Use dict.items() instead of dict.iteritems() to be "
|
|
||||||
"compatible with both Python 2 and Python 3. In Python 2, "
|
|
||||||
"dict.items() may be inefficient for very large dictionaries. "
|
|
||||||
"If you can prove that you need the optimization of an "
|
|
||||||
"iterator for Python 2, then you can use six.iteritems(dict).")
|
|
||||||
yield(0, msg)
|
yield(0, msg)
|
||||||
|
|
||||||
|
|
||||||
@ -338,10 +309,8 @@ def factory(register):
|
|||||||
register(no_mutable_default_args)
|
register(no_mutable_default_args)
|
||||||
register(assert_equal_in)
|
register(assert_equal_in)
|
||||||
register(no_log_warn)
|
register(no_log_warn)
|
||||||
register(no_xrange)
|
|
||||||
register(check_raised_localized_exceptions)
|
register(check_raised_localized_exceptions)
|
||||||
register(check_no_basestring)
|
register(check_no_basestring)
|
||||||
register(check_python3_no_iteritems)
|
|
||||||
register(check_no_eventlet_imports)
|
register(check_no_eventlet_imports)
|
||||||
register(check_line_continuation_no_backslash)
|
register(check_line_continuation_no_backslash)
|
||||||
register(check_no_logging_imports)
|
register(check_no_logging_imports)
|
||||||
|
@ -43,7 +43,7 @@ class TestDriverLib(base.TestCase):
|
|||||||
self.driver_lib._check_for_socket_ready,
|
self.driver_lib._check_for_socket_ready,
|
||||||
'bogus')
|
'bogus')
|
||||||
|
|
||||||
@mock.patch('six.moves.builtins.memoryview')
|
@mock.patch('builtins.memoryview')
|
||||||
def test_recv(self, mock_memoryview):
|
def test_recv(self, mock_memoryview):
|
||||||
mock_socket = mock.MagicMock()
|
mock_socket = mock.MagicMock()
|
||||||
mock_socket.recv.side_effect = [b'1', b'\n', b'2', b'\n', b'3', b'\n']
|
mock_socket.recv.side_effect = [b'1', b'\n', b'2', b'\n', b'3', b'\n']
|
||||||
|
@ -167,13 +167,6 @@ class HackingTestCase(base.BaseTestCase):
|
|||||||
self.assertEqual(0, len(list(checks.no_log_warn(
|
self.assertEqual(0, len(list(checks.no_log_warn(
|
||||||
"LOG.warning()"))))
|
"LOG.warning()"))))
|
||||||
|
|
||||||
def test_no_xrange(self):
|
|
||||||
self.assertEqual(1, len(list(checks.no_xrange(
|
|
||||||
"xrange(45)"))))
|
|
||||||
|
|
||||||
self.assertEqual(0, len(list(checks.no_xrange(
|
|
||||||
"range(45)"))))
|
|
||||||
|
|
||||||
def test_no_log_translations(self):
|
def test_no_log_translations(self):
|
||||||
for log in checks._all_log_levels:
|
for log in checks._all_log_levels:
|
||||||
for hint in checks._all_hints:
|
for hint in checks._all_hints:
|
||||||
@ -210,17 +203,7 @@ class HackingTestCase(base.BaseTestCase):
|
|||||||
"isinstance('foo', basestring)"))))
|
"isinstance('foo', basestring)"))))
|
||||||
|
|
||||||
self.assertEqual(0, len(list(checks.check_no_basestring(
|
self.assertEqual(0, len(list(checks.check_no_basestring(
|
||||||
"isinstance('foo', six.string_types)"))))
|
"isinstance('foo', str)"))))
|
||||||
|
|
||||||
def test_dict_iteritems(self):
|
|
||||||
self.assertEqual(1, len(list(checks.check_python3_no_iteritems(
|
|
||||||
"obj.iteritems()"))))
|
|
||||||
|
|
||||||
self.assertEqual(0, len(list(checks.check_python3_no_iteritems(
|
|
||||||
"six.iteritems(obj)"))))
|
|
||||||
|
|
||||||
self.assertEqual(0, len(list(checks.check_python3_no_iteritems(
|
|
||||||
"obj.items()"))))
|
|
||||||
|
|
||||||
def test_check_no_eventlet_imports(self):
|
def test_check_no_eventlet_imports(self):
|
||||||
f = checks.check_no_eventlet_imports
|
f = checks.check_no_eventlet_imports
|
||||||
|
@ -5,5 +5,4 @@
|
|||||||
oslo.i18n>=3.15.3 # Apache-2.0
|
oslo.i18n>=3.15.3 # Apache-2.0
|
||||||
oslo.serialization>=2.28.1 # Apache-2.0
|
oslo.serialization>=2.28.1 # Apache-2.0
|
||||||
pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
||||||
six>=1.10.0 # MIT
|
|
||||||
tenacity>=5.0.2 # Apache-2.0
|
tenacity>=5.0.2 # Apache-2.0
|
||||||
|
Loading…
Reference in New Issue
Block a user