diff options
author | Jan Cholasta <jcholast@redhat.com> | 2015-08-31 09:26:27 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2015-09-07 08:00:11 +0200 |
commit | cf9bf9dcafa6c6d434440e7b106f1886614eec05 (patch) | |
tree | 3b1cc510c5ef9dce7c806a1c811d064542062467 /ipapython/dnsutil.py | |
parent | ebdfa4380bdcdd99970c7d677df7e0d5e3ede6bc (diff) | |
download | freeipa-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 'ipapython/dnsutil.py')
-rw-r--r-- | ipapython/dnsutil.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/ipapython/dnsutil.py b/ipapython/dnsutil.py index 228cb6629..d190f23c7 100644 --- a/ipapython/dnsutil.py +++ b/ipapython/dnsutil.py @@ -21,18 +21,22 @@ import dns.name import dns.exception import copy +import six + +@six.python_2_unicode_compatible class DNSName(dns.name.Name): labels = None # make pylint happy + @classmethod + def from_text(cls, labels, origin=None): + return cls(dns.name.from_text(labels, origin)) + def __init__(self, labels, origin=None): try: - if isinstance(labels, str): + if isinstance(labels, six.string_types): #pylint: disable=E1101 - labels = dns.name.from_text(labels, origin).labels - elif isinstance(labels, unicode): - #pylint: disable=E1101 - labels = dns.name.from_unicode(labels, origin).labels + labels = dns.name.from_unicode(unicode(labels), origin).labels elif isinstance(labels, dns.name.Name): labels = labels.labels @@ -54,14 +58,11 @@ class DNSName(dns.name.Name): return DNSName(copy.deepcopy(self.labels, memo)) def __str__(self): - return self.to_text() - - def __unicode__(self): return self.to_unicode() def ToASCII(self): #method named by RFC 3490 and python standard library - return str(self).decode('ascii') # must be unicode string + return self.to_text().decode('ascii') # must be unicode string def canonicalize(self): return DNSName(super(DNSName, self).canonicalize()) |