Imported Debian patch 4.0.5-6~numeezy

This commit is contained in:
Alexandre Ellert
2016-02-17 15:07:45 +01:00
committed by Mario Fetka
parent c44de33144
commit 10dfc9587b
1203 changed files with 53869 additions and 241462 deletions

View File

@@ -21,41 +21,31 @@ import dns.name
import dns.exception
import copy
import six
if six.PY3:
unicode = str
@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):
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, six.string_types):
#pylint: disable=E1101
labels = dns.name.from_text(unicode(labels), origin).labels
elif isinstance(labels, dns.name.Name):
labels = labels.labels
super(DNSName, self).__init__(labels)
except UnicodeError as e:
except UnicodeError, e:
# dnspython bug, an invalid domain name returns the UnicodeError
# instead of a dns.exception
raise dns.exception.SyntaxError(e)
def __bool__(self):
def __nonzero__(self):
#dns.name.from_text('@') is represented like empty tuple
#we need to acting '@' as nonzero value
return True
__nonzero__ = __bool__ # for Python 2
def __copy__(self):
return DNSName(self.labels)
@@ -63,14 +53,14 @@ 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 self.to_text().decode('ascii') # must be unicode string
def canonicalize(self):
return DNSName(super(DNSName, self).canonicalize())
return str(self).decode('ascii') # must be unicode string
def concatenate(self, other):
return DNSName(super(DNSName, self).concatenate(other))