summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2015-08-31 09:26:27 +0200
committerJan Cholasta <jcholast@redhat.com>2015-09-07 08:00:11 +0200
commitcf9bf9dcafa6c6d434440e7b106f1886614eec05 (patch)
tree3b1cc510c5ef9dce7c806a1c811d064542062467 /ipalib
parentebdfa4380bdcdd99970c7d677df7e0d5e3ede6bc (diff)
downloadfreeipa-cf9bf9dcafa6c6d434440e7b106f1886614eec05.tar.gz
freeipa-cf9bf9dcafa6c6d434440e7b106f1886614eec05.tar.xz
freeipa-cf9bf9dcafa6c6d434440e7b106f1886614eec05.zip
Use six.python_2_unicode_compatible
Rename __unicode__ to __str__ in classes which define it and use the six.python_2_unicode_compatible decorator on them to make them compatible with both Python 2 and 3. Additional changes were required for the ipapython.dnsutil.DNSName class, because it defined both __str__ and __unicode__. Reviewed-By: Petr Viktorin <pviktori@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/text.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/ipalib/text.py b/ipalib/text.py
index 6b465a55b..160213eb8 100644
--- a/ipalib/text.py
+++ b/ipalib/text.py
@@ -116,6 +116,8 @@ import threading
import locale
import gettext
+import six
+
from ipalib.request import context
@@ -187,6 +189,7 @@ class LazyText(object):
return other + ConcatenatedLazyText(self)
+@six.python_2_unicode_compatible
class Gettext(LazyText):
"""
Deferred translation using ``gettext.ugettext()``.
@@ -241,7 +244,7 @@ class Gettext(LazyText):
return '%s(%r, domain=%r, localedir=%r)' % (self.__class__.__name__,
self.msg, self.domain, self.localedir)
- def __unicode__(self):
+ def __str__(self):
"""
Translate this message and return as a ``unicode`` instance.
"""
@@ -252,12 +255,13 @@ class Gettext(LazyText):
return g(self.msg)
def __json__(self):
- return self.__unicode__()
+ return self.__unicode__() #pylint: disable=no-member
def __mod__(self, kw):
- return self.__unicode__() % kw
+ return self.__unicode__() % kw #pylint: disable=no-member
+@six.python_2_unicode_compatible
class FixMe(Gettext):
"""
Non-translated place-holder for UI labels.
@@ -303,7 +307,7 @@ class FixMe(Gettext):
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.msg)
- def __unicode__(self):
+ def __str__(self):
return u'<%s>' % self.msg
@@ -400,6 +404,7 @@ class NGettext(LazyText):
return ng(self.singular, self.plural, count)
+@six.python_2_unicode_compatible
class ConcatenatedLazyText(object):
"""Concatenation of multiple strings, or any objects convertible to unicode
@@ -415,7 +420,7 @@ class ConcatenatedLazyText(object):
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.components)
- def __unicode__(self):
+ def __str__(self):
return u''.join(unicode(c) for c in self.components)
def __json__(self):