From 912849fe1a0ab1d22474eea0b529cb83df590826 Mon Sep 17 00:00:00 2001 From: wangzihao Date: Wed, 23 Sep 2020 15:08:33 +0800 Subject: [PATCH] Remove six.PY3 The Python 2.7 Support has been dropped since Ussuri. So remove hacking rules for compatibility between python 2 and 3. Change-Id: Ibed92787d66227fec0cf48c78de8a24f9b39cc52 --- oslo_i18n/_factory.py | 8 +++----- oslo_i18n/_message.py | 6 +++--- oslo_i18n/tests/test_message.py | 5 +---- oslo_i18n/tests/utils.py | 14 +++----------- 4 files changed, 10 insertions(+), 23 deletions(-) diff --git a/oslo_i18n/_factory.py b/oslo_i18n/_factory.py index c732b01..f9ec1e5 100644 --- a/oslo_i18n/_factory.py +++ b/oslo_i18n/_factory.py @@ -19,8 +19,6 @@ import gettext import os -import six - from oslo_i18n import _lazy from oslo_i18n import _locale from oslo_i18n import _message @@ -75,7 +73,7 @@ class TranslatorFactory(object): fallback=True) # Use the appropriate method of the translation object based # on the python version. - m = t.gettext if six.PY3 else t.ugettext + m = t.gettext def f(msg): """oslo_i18n.gettextutils translation function.""" @@ -103,7 +101,7 @@ class TranslatorFactory(object): fallback=True) # Use the appropriate method of the translation object based # on the python version. - m = t.gettext if six.PY3 else t.ugettext + m = t.gettext def f(ctx, msg): """oslo.i18n.gettextutils translation with context function.""" @@ -140,7 +138,7 @@ class TranslatorFactory(object): fallback=True) # Use the appropriate method of the translation object based # on the python version. - m = t.ngettext if six.PY3 else t.ungettext + m = t.ngettext def f(msgsingle, msgplural, msgcount): """oslo.i18n.gettextutils plural translation function.""" diff --git a/oslo_i18n/_message.py b/oslo_i18n/_message.py index 09ed69c..1d94e8d 100644 --- a/oslo_i18n/_message.py +++ b/oslo_i18n/_message.py @@ -117,7 +117,7 @@ class Message(six.text_type): if not has_contextual_form and not has_plural_form: # This is the most common case, so check it first. - translator = lang.gettext if six.PY3 else lang.ugettext + translator = lang.gettext translated_message = translator(msgid) elif has_contextual_form and has_plural_form: @@ -127,7 +127,7 @@ class Message(six.text_type): elif has_contextual_form: (msgctx, msgtxt) = msgid - translator = lang.gettext if six.PY3 else lang.ugettext + translator = lang.gettext msg_with_ctx = "%s%s%s" % (msgctx, CONTEXT_SEPARATOR, msgtxt) translated_message = translator(msg_with_ctx) @@ -138,7 +138,7 @@ class Message(six.text_type): elif has_plural_form: (msgsingle, msgplural, msgcount) = msgid - translator = lang.ngettext if six.PY3 else lang.ungettext + translator = lang.ngettext translated_message = translator(msgsingle, msgplural, msgcount) return translated_message diff --git a/oslo_i18n/tests/test_message.py b/oslo_i18n/tests/test_message.py index 882be8b..f6d7fc6 100644 --- a/oslo_i18n/tests/test_message.py +++ b/oslo_i18n/tests/test_message.py @@ -168,10 +168,7 @@ class MessageTestCase(test_base.BaseTestCase): # Now set up ugettext to return the translated version of # the original message, with a bad format string. wrong_type = u'Wrong type %(arg1)d' - if six.PY3: - trans.return_value.gettext.return_value = wrong_type - else: - trans.return_value.ugettext.return_value = wrong_type + trans.return_value.gettext.return_value = wrong_type trans_result = result.translation() expected = msgid % params self.assertEqual(expected, trans_result) diff --git a/oslo_i18n/tests/utils.py b/oslo_i18n/tests/utils.py index be1d94b..49dc92e 100644 --- a/oslo_i18n/tests/utils.py +++ b/oslo_i18n/tests/utils.py @@ -12,18 +12,14 @@ # License for the specific language governing permissions and limitations # under the License. -import six - class SomeObject(object): def __init__(self, message): self.message = message - def __unicode__(self): + def __str__(self): return self.message - # alias for Python 3 - __str__ = __unicode__ class NoDeepCopyObject(object): @@ -31,12 +27,8 @@ class NoDeepCopyObject(object): def __init__(self, value): self.value = value - if six.PY3: - def __str__(self): - return str(self.value) - else: - def __unicode__(self): - return six.text_type(self.value) + def __str__(self): + return str(self.value) def __deepcopy__(self, memo): raise TypeError('Deep Copy not supported')