From e2f285e7c63a8ff9f2c049ee3a058b6e281352a8 Mon Sep 17 00:00:00 2001 From: Martin Basti Date: Wed, 19 Nov 2014 14:51:20 +0100 Subject: [PATCH] Raise right exception if domain name is not valid Because of dnspython implementation, in some cases UnicodeError is raised instead of DNS SyntaxError Ticket: https://fedorahosted.org/freeipa/ticket/4734 Reviewed-By: Jan Cholasta --- ipapython/dnsutil.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ipapython/dnsutil.py b/ipapython/dnsutil.py index d7841fe2548dd100d51e60ea11bc6e468f3475cf..f08cddad959658a11623a31cb591655f1a5fdabf 100644 --- a/ipapython/dnsutil.py +++ b/ipapython/dnsutil.py @@ -26,15 +26,16 @@ class DNSName(dns.name.Name): labels = None # make pylint happy def __init__(self, labels, origin=None): - if isinstance(labels, str): - #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 - elif isinstance(labels, dns.name.Name): - labels = labels.labels try: + if isinstance(labels, str): + #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 + elif isinstance(labels, dns.name.Name): + labels = labels.labels + super(DNSName, self).__init__(labels) except UnicodeError, e: # dnspython bug, an invalid domain name returns the UnicodeError -- 2.1.0