diff options
Diffstat (limited to 'ipapython')
| -rw-r--r-- | ipapython/dnsutil.py | 19 | ||||
| -rw-r--r-- | ipapython/ipaldap.py | 4 |
2 files changed, 13 insertions, 10 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()) diff --git a/ipapython/ipaldap.py b/ipapython/ipaldap.py index 1279a18a8..837d57c3b 100644 --- a/ipapython/ipaldap.py +++ b/ipapython/ipaldap.py @@ -833,7 +833,7 @@ class LDAPClient(object): elif isinstance(val, (unicode, six.integer_types, long, Decimal, DN)): return value_to_utf8(val) elif isinstance(val, DNSName): - return str(val) + return val.to_text() elif isinstance(val, str): return val elif isinstance(val, list): @@ -863,6 +863,8 @@ class LDAPClient(object): return val.decode('utf-8') elif target_type is datetime.datetime: return datetime.datetime.strptime(val, LDAP_GENERALIZED_TIME_FORMAT) + elif target_type is DNSName: + return DNSName.from_text(val) else: return target_type(val) except Exception as e: |
