Remove all six usage

Remove six Replace the following items with Python 3 style code.

- six.string_types
- six.text_type
- six.itervalues
- six.StringIO

Change-Id: I32401859129843242922f1d0510b21e32bb7d8cc
This commit is contained in:
wangzihao 2020-10-14 10:21:25 +08:00
parent f8cd4689e9
commit a2122e7432
12 changed files with 55 additions and 71 deletions

View File

@ -39,7 +39,6 @@ PyYAML==3.13
requests==2.14.2 requests==2.14.2
requestsexceptions==1.2.0 requestsexceptions==1.2.0
rfc3986==0.3.1 rfc3986==0.3.1
six==1.10.0
smmap==0.9.0 smmap==0.9.0
snowballstemmer==1.2.1 snowballstemmer==1.2.1
stestr==2.0.0 stestr==2.0.0

View File

@ -18,10 +18,8 @@ This module includes various utilities
used in generating reports. used in generating reports.
""" """
import six
class StringWithAttrs(str):
class StringWithAttrs(six.text_type):
"""A String that can have arbitrary attributes""" """A String that can have arbitrary attributes"""
pass pass

View File

@ -28,8 +28,6 @@ try: # python 3
except ImportError: # python 2 except ImportError: # python 2
import collections as abc import collections as abc
import six
class ReportModel(abc.MutableMapping): class ReportModel(abc.MutableMapping):
"""A Report Data Model """A Report Data Model
@ -71,7 +69,7 @@ class ReportModel(abc.MutableMapping):
self_cpy = copy.deepcopy(self) self_cpy = copy.deepcopy(self)
for key in self_cpy: for key in self_cpy:
if getattr(self_cpy[key], 'attached_view', None) is not None: if getattr(self_cpy[key], 'attached_view', None) is not None:
self_cpy[key] = six.text_type(self_cpy[key]) self_cpy[key] = str(self_cpy[key])
if self.attached_view is not None: if self.attached_view is not None:
return self.attached_view(self_cpy) return self.attached_view(self_cpy)
@ -147,7 +145,7 @@ class ReportModel(abc.MutableMapping):
# don't die on recursive structures, # don't die on recursive structures,
# and don't treat strings like sequences # and don't treat strings like sequences
if oid in visited or isinstance(obj, six.string_types): if oid in visited or isinstance(obj, str):
return return
visited.add(oid) visited.add(oid)
@ -160,7 +158,7 @@ class ReportModel(abc.MutableMapping):
traverse_obj(item) traverse_obj(item)
elif isinstance(obj, abc.Mapping): elif isinstance(obj, abc.Mapping):
for val in six.itervalues(obj): for val in obj.values():
traverse_obj(val) traverse_obj(val)
traverse_obj(self) traverse_obj(self)

View File

@ -19,7 +19,6 @@ All reports take the form of a report class containing various report
sections. sections.
""" """
import six
from oslo_reports.views.text import header as header_views from oslo_reports.views.text import header as header_views
@ -74,7 +73,7 @@ class BasicReport(object):
:returns: the serialized report :returns: the serialized report
""" """
return "\n".join(six.text_type(sect) for sect in self.sections) return "\n".join(str(sect) for sect in self.sections)
class ReportSection(object): class ReportSection(object):

View File

@ -20,7 +20,6 @@ except ImportError: # python 2
import collections as abc import collections as abc
from oslotest import base from oslotest import base
import six
from oslo_reports.models import base as base_model from oslo_reports.models import base as base_model
from oslo_reports import report from oslo_reports import report
@ -30,7 +29,7 @@ class BasicView(object):
def __call__(self, model): def __call__(self, model):
res = "" res = ""
for k in sorted(model.keys()): for k in sorted(model.keys()):
res += six.text_type(k) + ": " + six.text_type(model[k]) + ";" res += str(k) + ": " + str(model[k]) + ";"
return res return res
@ -71,7 +70,7 @@ class TestBaseModel(base.BaseTestCase):
def test_submodel_attached_view(self): def test_submodel_attached_view(self):
class TmpView(object): class TmpView(object):
def __call__(self, model): def __call__(self, model):
return '{len: ' + six.text_type(len(model.c)) + '}' return '{len: ' + str(len(model.c)) + '}'
def generate_model_with_submodel(): def generate_model_with_submodel():
base_m = basic_generator() base_m = basic_generator()
@ -87,13 +86,13 @@ class TestBaseModel(base.BaseTestCase):
model = base_model.ReportModel(data={'c': [1, 2, 3]}) model = base_model.ReportModel(data={'c': [1, 2, 3]})
self.assertRaisesRegex(Exception, self.assertRaisesRegex(Exception,
'Cannot stringify model: no attached view', 'Cannot stringify model: no attached view',
six.text_type, model) str, model)
def test_str_returns_string_with_attached_view(self): def test_str_returns_string_with_attached_view(self):
model = base_model.ReportModel(data={'a': 1, 'b': 2}, model = base_model.ReportModel(data={'a': 1, 'b': 2},
attached_view=BasicView()) attached_view=BasicView())
self.assertEqual(six.text_type(model), 'a: 1;b: 2;') self.assertEqual(str(model), 'a: 1;b: 2;')
def test_model_repr(self): def test_model_repr(self):
model1 = base_model.ReportModel(data={'a': 1, 'b': 2}, model1 = base_model.ReportModel(data={'a': 1, 'b': 2},
@ -120,7 +119,7 @@ class TestBaseModel(base.BaseTestCase):
model.attached_view = BasicView() model.attached_view = BasicView()
# if we don't handle lists properly, we'll get a TypeError here # if we don't handle lists properly, we'll get a TypeError here
self.assertEqual('0: a;1: b;', six.text_type(model)) self.assertEqual('0: a;1: b;', str(model))
def test_immutable_mappings_produce_mutable_models(self): def test_immutable_mappings_produce_mutable_models(self):
class SomeImmutableMapping(abc.Mapping): class SomeImmutableMapping(abc.Mapping):
@ -140,9 +139,9 @@ class TestBaseModel(base.BaseTestCase):
model = base_model.ReportModel(data=mp) model = base_model.ReportModel(data=mp)
model.attached_view = BasicView() model.attached_view = BasicView()
self.assertEqual('a: 2;b: 4;c: 8;', six.text_type(model)) self.assertEqual('a: 2;b: 4;c: 8;', str(model))
model['d'] = 16 model['d'] = 16
self.assertEqual('a: 2;b: 4;c: 8;d: 16;', six.text_type(model)) self.assertEqual('a: 2;b: 4;c: 8;d: 16;', str(model))
self.assertEqual({'a': 2, 'b': 4, 'c': 8}, mp.data) self.assertEqual({'a': 2, 'b': 4, 'c': 8}, mp.data)

View File

@ -13,6 +13,7 @@
# under the License. # under the License.
import datetime import datetime
import io
import os import os
import re import re
import signal import signal
@ -24,7 +25,6 @@ from unittest import mock
import fixtures import fixtures
import greenlet import greenlet
from oslotest import base from oslotest import base
import six
import oslo_config import oslo_config
from oslo_config import fixture from oslo_config import fixture
@ -189,7 +189,7 @@ class TestGuruMeditationReport(base.BaseTestCase):
def test_register_autorun(self): def test_register_autorun(self):
gmr.TextGuruMeditation.setup_autorun(FakeVersionObj()) gmr.TextGuruMeditation.setup_autorun(FakeVersionObj())
self.old_stderr = sys.stderr self.old_stderr = sys.stderr
sys.stderr = six.StringIO() sys.stderr = io.StringIO()
os.kill(os.getpid(), signal.SIGUSR2) os.kill(os.getpid(), signal.SIGUSR2)
self.assertIn('Guru Meditation', sys.stderr.getvalue()) self.assertIn('Guru Meditation', sys.stderr.getvalue())
@ -236,7 +236,7 @@ class TestGuruMeditationReport(base.BaseTestCase):
run_mock.side_effect = RunFail() run_mock.side_effect = RunFail()
gmr.TextGuruMeditation.setup_autorun(FakeVersionObj()) gmr.TextGuruMeditation.setup_autorun(FakeVersionObj())
self.old_stderr = sys.stderr self.old_stderr = sys.stderr
sys.stderr = six.StringIO() sys.stderr = io.StringIO()
os.kill(os.getpid(), signal.SIGUSR2) os.kill(os.getpid(), signal.SIGUSR2)
self.assertIn('RunFail', sys.stderr.getvalue()) self.assertIn('RunFail', sys.stderr.getvalue())

View File

@ -19,7 +19,6 @@ from unittest import mock
import greenlet import greenlet
from oslo_config import cfg from oslo_config import cfg
from oslotest import base from oslotest import base
import six
from oslo_reports.generators import conf as os_cgen from oslo_reports.generators import conf as os_cgen
from oslo_reports.generators import threading as os_tgen from oslo_reports.generators import threading as os_tgen
@ -43,7 +42,7 @@ class TestOpenstackGenerators(base.BaseTestCase):
self.assertTrue(was_ok) self.assertTrue(was_ok)
model.set_current_view_type('text') model.set_current_view_type('text')
self.assertIsNotNone(six.text_type(model)) self.assertIsNotNone(str(model))
def test_thread_generator_tb(self): def test_thread_generator_tb(self):
class FakeModel(object): class FakeModel(object):
@ -73,7 +72,7 @@ class TestOpenstackGenerators(base.BaseTestCase):
self.assertTrue(was_ok) self.assertTrue(was_ok)
model.set_current_view_type('text') model.set_current_view_type('text')
self.assertIsNotNone(six.text_type(model)) self.assertIsNotNone(str(model))
def test_config_model(self): def test_config_model(self):
conf = cfg.ConfigOpts() conf = cfg.ConfigOpts()
@ -114,7 +113,7 @@ class TestOpenstackGenerators(base.BaseTestCase):
'%s' '%s'
' crackers = triscuit\n' ' crackers = triscuit\n'
' secrets = ***') % config_source_line ' secrets = ***') % config_source_line
self.assertEqual(target_str, six.text_type(model)) self.assertEqual(target_str, str(model))
def test_package_report_generator(self): def test_package_report_generator(self):
class VersionObj(object): class VersionObj(object):
@ -133,7 +132,7 @@ class TestOpenstackGenerators(base.BaseTestCase):
target_str = ('product = Sharp Cheddar\n' target_str = ('product = Sharp Cheddar\n'
'vendor = Cheese Shoppe\n' 'vendor = Cheese Shoppe\n'
'version = 1.0.0') 'version = 1.0.0')
self.assertEqual(target_str, six.text_type(model)) self.assertEqual(target_str, str(model))
def test_package_report_generator_without_vendor_string(self): def test_package_report_generator_without_vendor_string(self):
class VersionObj(object): class VersionObj(object):
@ -149,4 +148,4 @@ class TestOpenstackGenerators(base.BaseTestCase):
target_str = ('product = Sharp Cheddar\n' target_str = ('product = Sharp Cheddar\n'
'vendor = None\n' 'vendor = None\n'
'version = 1.0.0') 'version = 1.0.0')
self.assertEqual(target_str, six.text_type(model)) self.assertEqual(target_str, str(model))

View File

@ -16,7 +16,6 @@ import copy
from unittest import mock from unittest import mock
from oslotest import base from oslotest import base
import six
from oslo_reports.models import base as base_model from oslo_reports.models import base as base_model
from oslo_reports.models import with_default_views as mwdv from oslo_reports.models import with_default_views as mwdv
@ -35,15 +34,15 @@ class TestModelReportType(base.BaseTestCase):
model = mwdv_generator() model = mwdv_generator()
model.set_current_view_type('text') model.set_current_view_type('text')
self.assertEqual('int = 1\nstring = value', six.text_type(model)) self.assertEqual('int = 1\nstring = value', str(model))
model.set_current_view_type('json') model.set_current_view_type('json')
self.assertEqual('{"int": 1, "string": "value"}', six.text_type(model)) self.assertEqual('{"int": 1, "string": "value"}', str(model))
model.set_current_view_type('xml') model.set_current_view_type('xml')
self.assertEqual('<model><int>1</int><string>value</string></model>', self.assertEqual('<model><int>1</int><string>value</string></model>',
six.text_type(model)) str(model))
def test_recursive_type_propagation_with_nested_models(self): def test_recursive_type_propagation_with_nested_models(self):
model = mwdv_generator() model = mwdv_generator()
@ -85,7 +84,7 @@ class TestModelReportType(base.BaseTestCase):
def test_report_of_type(self): def test_report_of_type(self):
rep = report.ReportOfType('json') rep = report.ReportOfType('json')
rep.add_section(lambda x: six.text_type(x), mwdv_generator) rep.add_section(lambda x: str(x), mwdv_generator)
self.assertEqual('{"int": 1, "string": "value"}', rep.run()) self.assertEqual('{"int": 1, "string": "value"}', rep.run())
@ -134,7 +133,7 @@ class TestGenericXMLView(base.BaseTestCase):
'<dt><a>1</a><b>2</b></dt>' '<dt><a>1</a><b>2</b></dt>'
'<int>1</int>' '<int>1</int>'
'<string>value</string></model>') '<string>value</string></model>')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_list_serialization(self): def test_list_serialization(self):
self.model['lt'] = ['a', 'b'] self.model['lt'] = ['a', 'b']
@ -143,7 +142,7 @@ class TestGenericXMLView(base.BaseTestCase):
'<int>1</int>' '<int>1</int>'
'<lt><item>a</item><item>b</item></lt>' '<lt><item>a</item><item>b</item></lt>'
'<string>value</string></model>') '<string>value</string></model>')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_list_in_dict_serialization(self): def test_list_in_dict_serialization(self):
self.model['dt'] = {'a': 1, 'b': [2, 3]} self.model['dt'] = {'a': 1, 'b': [2, 3]}
@ -153,7 +152,7 @@ class TestGenericXMLView(base.BaseTestCase):
'<b><item>2</item><item>3</item></b></dt>' '<b><item>2</item><item>3</item></b></dt>'
'<int>1</int>' '<int>1</int>'
'<string>value</string></model>') '<string>value</string></model>')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_dict_in_list_serialization(self): def test_dict_in_list_serialization(self):
self.model['lt'] = [1, {'b': 2, 'c': 3}] self.model['lt'] = [1, {'b': 2, 'c': 3}]
@ -163,7 +162,7 @@ class TestGenericXMLView(base.BaseTestCase):
'<lt><item>1</item>' '<lt><item>1</item>'
'<item><b>2</b><c>3</c></item></lt>' '<item><b>2</b><c>3</c></item></lt>'
'<string>value</string></model>') '<string>value</string></model>')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_submodel_serialization(self): def test_submodel_serialization(self):
sm = mwdv_generator() sm = mwdv_generator()
@ -178,7 +177,7 @@ class TestGenericXMLView(base.BaseTestCase):
'<model><int>1</int><string>value</string></model>' '<model><int>1</int><string>value</string></model>'
'</submodel>' '</submodel>'
'</model>') '</model>')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_wrapper_name(self): def test_wrapper_name(self):
self.model.attached_view.wrapper_name = 'cheese' self.model.attached_view.wrapper_name = 'cheese'
@ -187,7 +186,7 @@ class TestGenericXMLView(base.BaseTestCase):
'<int>1</int>' '<int>1</int>'
'<string>value</string>' '<string>value</string>'
'</cheese>') '</cheese>')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
class TestGenericJSONViews(base.BaseTestCase): class TestGenericJSONViews(base.BaseTestCase):
@ -203,7 +202,7 @@ class TestGenericJSONViews(base.BaseTestCase):
attached_view=attached_view) attached_view=attached_view)
self.assertEqual('{"int": 1, "string": "value"}', self.assertEqual('{"int": 1, "string": "value"}',
six.text_type(self.model)) str(self.model))
def test_dict_serialization(self): def test_dict_serialization(self):
self.model['dt'] = {'a': 1, 'b': 2} self.model['dt'] = {'a': 1, 'b': 2}
@ -213,7 +212,7 @@ class TestGenericJSONViews(base.BaseTestCase):
'"int": 1, ' '"int": 1, '
'"string": "value"' '"string": "value"'
'}') '}')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_list_serialization(self): def test_list_serialization(self):
self.model['lt'] = ['a', 'b'] self.model['lt'] = ['a', 'b']
@ -223,7 +222,7 @@ class TestGenericJSONViews(base.BaseTestCase):
'"lt": ["a", "b"], ' '"lt": ["a", "b"], '
'"string": "value"' '"string": "value"'
'}') '}')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_list_in_dict_serialization(self): def test_list_in_dict_serialization(self):
self.model['dt'] = {'a': 1, 'b': [2, 3]} self.model['dt'] = {'a': 1, 'b': [2, 3]}
@ -233,7 +232,7 @@ class TestGenericJSONViews(base.BaseTestCase):
'"int": 1, ' '"int": 1, '
'"string": "value"' '"string": "value"'
'}') '}')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_dict_in_list_serialization(self): def test_dict_in_list_serialization(self):
self.model['lt'] = [1, {'b': 2, 'c': 3}] self.model['lt'] = [1, {'b': 2, 'c': 3}]
@ -243,7 +242,7 @@ class TestGenericJSONViews(base.BaseTestCase):
'"lt": [1, {"b": 2, "c": 3}], ' '"lt": [1, {"b": 2, "c": 3}], '
'"string": "value"' '"string": "value"'
'}') '}')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_submodel_serialization(self): def test_submodel_serialization(self):
sm = mwdv_generator() sm = mwdv_generator()
@ -256,7 +255,7 @@ class TestGenericJSONViews(base.BaseTestCase):
'"string": "value", ' '"string": "value", '
'"submodel": {"int": 1, "string": "value"}' '"submodel": {"int": 1, "string": "value"}'
'}') '}')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
class TestGenericTextViews(base.BaseTestCase): class TestGenericTextViews(base.BaseTestCase):
@ -280,7 +279,7 @@ class TestGenericTextViews(base.BaseTestCase):
'string = value\n' 'string = value\n'
'int = 2\n' 'int = 2\n'
'string = value') 'string = value')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_basic_kv_view(self): def test_basic_kv_view(self):
attached_view = text_generic.BasicKeyValueView() attached_view = text_generic.BasicKeyValueView()
@ -288,7 +287,7 @@ class TestGenericTextViews(base.BaseTestCase):
attached_view=attached_view) attached_view=attached_view)
self.assertEqual('int = 1\nstring = value\n', self.assertEqual('int = 1\nstring = value\n',
six.text_type(self.model)) str(self.model))
def test_table_view(self): def test_table_view(self):
column_names = ['Column A', 'Column B'] column_names = ['Column A', 'Column B']
@ -305,7 +304,7 @@ class TestGenericTextViews(base.BaseTestCase):
' 1 | 2 \n' # noqa ' 1 | 2 \n' # noqa
' 3 | 4 \n') # noqa ' 3 | 4 \n') # noqa
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_dict_serialization(self): def test_dict_serialization(self):
self.model['dt'] = {'a': 1, 'b': 2} self.model['dt'] = {'a': 1, 'b': 2}
@ -315,7 +314,7 @@ class TestGenericTextViews(base.BaseTestCase):
' b = 2\n' ' b = 2\n'
'int = 1\n' 'int = 1\n'
'string = value') 'string = value')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_list_serialization(self): def test_list_serialization(self):
self.model['lt'] = ['a', 'b'] self.model['lt'] = ['a', 'b']
@ -325,7 +324,7 @@ class TestGenericTextViews(base.BaseTestCase):
' a\n' ' a\n'
' b\n' ' b\n'
'string = value') 'string = value')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_list_in_dict_serialization(self): def test_list_in_dict_serialization(self):
self.model['dt'] = {'a': 1, 'b': [2, 3]} self.model['dt'] = {'a': 1, 'b': [2, 3]}
@ -338,7 +337,7 @@ class TestGenericTextViews(base.BaseTestCase):
'int = 1\n' 'int = 1\n'
'string = value') 'string = value')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_dict_in_list_serialization(self): def test_dict_in_list_serialization(self):
self.model['lt'] = [1, {'b': 2, 'c': 3}] self.model['lt'] = [1, {'b': 2, 'c': 3}]
@ -350,7 +349,7 @@ class TestGenericTextViews(base.BaseTestCase):
' b = 2\n' ' b = 2\n'
' c = 3\n' ' c = 3\n'
'string = value') 'string = value')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_submodel_serialization(self): def test_submodel_serialization(self):
sm = mwdv_generator() sm = mwdv_generator()
@ -363,7 +362,7 @@ class TestGenericTextViews(base.BaseTestCase):
'submodel = \n' 'submodel = \n'
' int = 1\n' ' int = 1\n'
' string = value') ' string = value')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def test_custom_indent_string(self): def test_custom_indent_string(self):
view = text_generic.KeyValueView(indent_str='~~') view = text_generic.KeyValueView(indent_str='~~')
@ -376,7 +375,7 @@ class TestGenericTextViews(base.BaseTestCase):
'~~a\n' '~~a\n'
'~~b\n' '~~b\n'
'string = value') 'string = value')
self.assertEqual(target_str, six.text_type(self.model)) self.assertEqual(target_str, str(self.model))
def get_open_mocks(rv): def get_open_mocks(rv):
@ -401,14 +400,14 @@ class TestJinjaView(base.BaseTestCase):
self.model.attached_view = jv.JinjaView(path='a/b/c/d.jinja.txt') self.model.attached_view = jv.JinjaView(path='a/b/c/d.jinja.txt')
self.assertEqual('int is 1, string is value', self.assertEqual('int is 1, string is value',
six.text_type(self.model)) str(self.model))
self.MM_FILE.assert_called_with_once('a/b/c/d.jinja.txt') self.MM_FILE.assert_called_with_once('a/b/c/d.jinja.txt')
def test_direct_pass(self): def test_direct_pass(self):
self.model.attached_view = jv.JinjaView(text=self.TEMPL_STR) self.model.attached_view = jv.JinjaView(text=self.TEMPL_STR)
self.assertEqual('int is 1, string is value', self.assertEqual('int is 1, string is value',
six.text_type(self.model)) str(self.model))
def test_load_from_class(self): def test_load_from_class(self):
class TmpJinjaView(jv.JinjaView): class TmpJinjaView(jv.JinjaView):
@ -417,7 +416,7 @@ class TestJinjaView(base.BaseTestCase):
self.model.attached_view = TmpJinjaView() self.model.attached_view = TmpJinjaView()
self.assertEqual('int is 1, string is value', self.assertEqual('int is 1, string is value',
six.text_type(self.model)) str(self.model))
def test_is_deepcopiable(self): def test_is_deepcopiable(self):
view_orig = jv.JinjaView(text=self.TEMPL_STR) view_orig = jv.JinjaView(text=self.TEMPL_STR)

View File

@ -23,8 +23,6 @@ try: # python 3
except ImportError: # python 2 except ImportError: # python 2
import collections as abc import collections as abc
import six
class MultiView(object): class MultiView(object):
"""A Text View Containing Multiple Views """A Text View Containing Multiple Views
@ -38,7 +36,7 @@ class MultiView(object):
""" """
def __call__(self, model): def __call__(self, model):
res = sorted([six.text_type(model[key]) for key in model]) res = sorted([str(model[key]) for key in model])
return "\n".join(res) return "\n".join(res)
@ -126,7 +124,7 @@ class KeyValueView(object):
for key in sorted(root): for key in sorted(root):
res.extend(serialize(root[key], key, indent + 1)) res.extend(serialize(root[key], key, indent + 1))
elif (isinstance(root, abc.Sequence) and elif (isinstance(root, abc.Sequence) and
not isinstance(root, six.string_types)): not isinstance(root, str)):
if rootkey is not None: if rootkey is not None:
res[0] += self.list_sep res[0] += self.list_sep
if self.before_list is not None: if self.before_list is not None:
@ -135,7 +133,7 @@ class KeyValueView(object):
for val in sorted(root, key=str): for val in sorted(root, key=str):
res.extend(serialize(val, None, indent + 1)) res.extend(serialize(val, None, indent + 1))
else: else:
str_root = six.text_type(root) str_root = str(root)
if '\n' in str_root: if '\n' in str_root:
# we are in a submodel # we are in a submodel
if rootkey is not None: if rootkey is not None:
@ -198,7 +196,7 @@ class TableView(object):
def __call__(self, model): def __call__(self, model):
res = self.header_fmt_str.format(ch=self.column_names) res = self.header_fmt_str.format(ch=self.column_names)
for raw_row in model[self.table_prop_name]: for raw_row in model[self.table_prop_name]:
row = [six.text_type(raw_row[prop_name]) row = [str(raw_row[prop_name])
for prop_name in self.column_values] for prop_name in self.column_values]
# double format is in case we have roundoff error # double format is in case we have roundoff error
res += '{0: <72}\n'.format(self.row_fmt_str.format(cv=row)) res += '{0: <72}\n'.format(self.row_fmt_str.format(cv=row))

View File

@ -17,8 +17,6 @@
This package defines several text views with headers This package defines several text views with headers
""" """
import six
class HeaderView(object): class HeaderView(object):
"""A Text View With a Header """A Text View With a Header
@ -33,7 +31,7 @@ class HeaderView(object):
self.header = header self.header = header
def __call__(self, model): def __call__(self, model):
return six.text_type(self.header) + "\n" + six.text_type(model) return str(self.header) + "\n" + str(model)
class TitledView(HeaderView): class TitledView(HeaderView):

View File

@ -31,8 +31,6 @@ try: # python 3
except ImportError: # python 2 except ImportError: # python 2
import collections as abc import collections as abc
import six
from oslo_reports import _utils as utils from oslo_reports import _utils as utils
@ -73,13 +71,13 @@ class KeyValueView(object):
for key in sorted(rootmodel): for key in sorted(rootmodel):
res.append(serialize(rootmodel[key], key)) res.append(serialize(rootmodel[key], key))
elif (isinstance(rootmodel, abc.Sequence) and elif (isinstance(rootmodel, abc.Sequence) and
not isinstance(rootmodel, six.string_types)): not isinstance(rootmodel, str)):
for val in sorted(rootmodel, key=str): for val in sorted(rootmodel, key=str):
res.append(serialize(val, 'item')) res.append(serialize(val, 'item'))
elif ET.iselement(rootmodel): elif ET.iselement(rootmodel):
res.append(rootmodel) res.append(rootmodel)
else: else:
res.text = six.text_type(rootmodel) res.text = str(rootmodel)
return res return res

View File

@ -6,6 +6,5 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0
Jinja2>=2.10 # BSD License (3 clause) Jinja2>=2.10 # BSD License (3 clause)
oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
psutil>=3.2.2 # BSD psutil>=3.2.2 # BSD
six>=1.10.0 # MIT
oslo.i18n>=3.15.3 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0