check: test
test:
- cd tests; make PYTHON=${PYTHON} test
-
-test2:
- cd tests; make PYTHON=python test
-
-test3:
cd tests; make PYTHON=${PYTHON3} test
-lint:
- pylint dns tests examples/*.py
+test3: test
-lint3:
+lint:
pylint3 dns tests examples/*.py
+lint3: lint
+
typecheck:
if [ $(shell python -c "import sys; print(sys.version_info[0])") -ne 2 ]; then pip install mypy; mypy examples tests; else echo Skipping typecheck on Python 2; fi
--- /dev/null
+# Incompatible differences between dnspython 1.x and 2.x
+
+## Rounding
+
+dnspython 2.0 rounds in the standard python 3 fashion; dnspython 1.x rounded
+in the python 2 style on both python 2 and 3.
+++ /dev/null
-import sys
-import decimal
-from decimal import Context
-
-PY3 = sys.version_info[0] == 3
-PY2 = sys.version_info[0] == 2
-
-
-if PY3:
- long = int
- xrange = range
-else:
- long = long # pylint: disable=long-builtin
- xrange = xrange # pylint: disable=xrange-builtin
-
-# unicode / binary types
-if PY3:
- text_type = str
- binary_type = bytes
- string_types = (str,)
- unichr = chr
- def maybe_decode(x):
- return x.decode()
- def maybe_encode(x):
- return x.encode()
- def maybe_chr(x):
- return x
- def maybe_ord(x):
- return x
-else:
- text_type = unicode # pylint: disable=unicode-builtin, undefined-variable
- binary_type = str
- string_types = (
- basestring, # pylint: disable=basestring-builtin, undefined-variable
- )
- unichr = unichr # pylint: disable=unichr-builtin
- def maybe_decode(x):
- return x
- def maybe_encode(x):
- return x
- def maybe_chr(x):
- return chr(x)
- def maybe_ord(x):
- return ord(x)
-
-
-def round_py2_compat(what):
- """
- Python 2 and Python 3 use different rounding strategies in round(). This
- function ensures that results are python2/3 compatible and backward
- compatible with previous py2 releases
- :param what: float
- :return: rounded long
- """
- d = Context(
- prec=len(str(long(what))), # round to integer with max precision
- rounding=decimal.ROUND_HALF_UP
- ).create_decimal(str(what)) # str(): python 2.6 compat
- return long(d)
import dns.rdata
import dns.rdatatype
import dns.rdataclass
-from ._compat import string_types
-
class UnsupportedAlgorithm(dns.exception.DNSException):
"""The DNSSEC algorithm is not supported."""
else:
raise UnsupportedAlgorithm('unsupported algorithm "%s"' % algorithm)
- if isinstance(name, string_types):
+ if isinstance(name, str):
name = dns.name.from_text(name, origin)
hash.update(name.canonicalize().to_wire())
hash.update(_to_rdata(key, origin))
in seconds since the UNIX epoch. The default is the current time.
"""
- if isinstance(origin, string_types):
+ if isinstance(origin, str):
origin = dns.name.from_text(origin, dns.name.root)
candidate_keys = _find_candidate_keys(keys, rrsig)
in seconds since the UNIX epoch. The default is the current time.
"""
- if isinstance(origin, string_types):
+ if isinstance(origin, str):
origin = dns.name.from_text(origin, dns.name.root)
if isinstance(rrset, tuple):
import dns.exception
import dns.name
import dns.resolver
-from ._compat import string_types, maybe_decode
#: The public E.164 domain.
public_enum_domain = dns.name.from_text('e164.arpa.')
text = b''.join(dlabels)
if want_plus_prefix:
text = b'+' + text
- return maybe_decode(text)
+ return text.decode()
def query(number, domains, resolver=None):
resolver = dns.resolver.get_default_resolver()
e_nx = dns.resolver.NXDOMAIN()
for domain in domains:
- if isinstance(domain, string_types):
+ if isinstance(domain, str):
domain = dns.name.from_text(domain)
qname = dns.e164.from_e164(number, domain)
try:
import os
import random
import time
-from ._compat import long, binary_type
try:
import threading as _threading
except ImportError:
try:
self._maybe_seed()
if self.digest is None or self.next_byte == self.hash_len:
- self.hash.update(binary_type(self.pool))
+ self.hash.update(bytes(self.pool))
self.digest = bytearray(self.hash.digest())
self.stir(self.digest, True)
self.next_byte = 0
def random_between(self, first, last):
size = last - first + 1
- if size > long(4294967296):
+ if size > 4294967296:
raise ValueError('too big')
if size > 65536:
rand = self.random_32
- max = long(4294967295)
+ max = 4294967295
elif size > 256:
rand = self.random_16
max = 65535
import dns.ipv4
import dns.ipv6
-from ._compat import maybe_ord
-
# We assume that AF_INET is always defined.
AF_INET = socket.AF_INET
"""
try:
- first = maybe_ord(dns.ipv4.inet_aton(text)[0])
+ first = dns.ipv4.inet_aton(text)[0]
return first >= 224 and first <= 239
except Exception:
try:
- first = maybe_ord(dns.ipv6.inet_aton(text)[0])
+ first = dns.ipv6.inet_aton(text)[0]
return first == 255
except Exception:
raise ValueError
import struct
import dns.exception
-from ._compat import binary_type
def inet_ntoa(address):
"""Convert an IPv4 address in binary form to text form.
- *address*, a ``binary``, the IPv4 address in binary form.
+ *address*, a ``bytes``, the IPv4 address in binary form.
- Returns a ``text``.
+ Returns a ``str``.
"""
if len(address) != 4:
def inet_aton(text):
"""Convert an IPv4 address in text form to binary form.
- *text*, a ``text``, the IPv4 address in textual form.
+ *text*, a ``str``, the IPv4 address in textual form.
- Returns a ``binary``.
+ Returns a ``bytes``.
"""
- if not isinstance(text, binary_type):
+ if not isinstance(text, bytes):
text = text.encode()
parts = text.split(b'.')
if len(parts) != 4:
# No leading zeros
raise dns.exception.SyntaxError
try:
- bytes = [int(part) for part in parts]
- return struct.pack('BBBB', *bytes)
+ b = [int(part) for part in parts]
+ return struct.pack('BBBB', *b)
except:
raise dns.exception.SyntaxError
import dns.exception
import dns.ipv4
-from ._compat import xrange, binary_type, maybe_decode
_leading_zero = re.compile(r'0+([0-9a-f]+)')
def inet_ntoa(address):
"""Convert an IPv6 address in binary form to text form.
- *address*, a ``binary``, the IPv6 address in binary form.
+ *address*, a ``bytes``, the IPv6 address in binary form.
Raises ``ValueError`` if the address isn't 16 bytes long.
- Returns a ``text``.
+ Returns a ``str``.
"""
if len(address) != 16:
i = 0
l = len(hex)
while i < l:
- chunk = maybe_decode(hex[i : i + 4])
+ chunk = hex[i : i + 4].decode()
# strip leading zeros. we do this with an re instead of
# with lstrip() because lstrip() didn't support chars until
# python 2.2.2
best_len = 0
start = -1
last_was_zero = False
- for i in xrange(8):
+ for i in range(8):
if chunks[i] != '0':
if last_was_zero:
end = i
*text*, a ``text``, the IPv6 address in textual form.
- Returns a ``binary``.
+ Returns a ``bytes``.
"""
#
# Our aim here is not something fast; we just want something that works.
#
- if not isinstance(text, binary_type):
+ if not isinstance(text, bytes):
text = text.encode()
if text == b'::':
if seen_empty:
raise dns.exception.SyntaxError
seen_empty = True
- for i in xrange(0, 8 - l + 1):
+ for i in range(0, 8 - l + 1):
canonical.append(b'0000')
else:
lc = len(c)
def is_mapped(address):
"""Is the specified address a mapped IPv4 address?
- *address*, a ``binary`` is an IPv6 address in binary form.
+ *address*, a ``bytes`` is an IPv6 address in binary form.
Returns a ``bool``.
"""
import dns.tsig
import dns.wiredata
-from ._compat import long, xrange, string_types
-
class ShortHeader(dns.exception.FormError):
"""The DNS packet passed to from_wire() is too short."""
if keyname is None:
self.keyname = list(self.keyring.keys())[0]
else:
- if isinstance(keyname, string_types):
+ if isinstance(keyname, str):
keyname = dns.name.from_text(keyname)
self.keyname = keyname
self.keyalgorithm = algorithm
options = []
else:
# make sure the EDNS version in ednsflags agrees with edns
- ednsflags &= long(0xFF00FFFF)
+ ednsflags &= 0xFF00FFFF
ednsflags |= (edns << 16)
if options is None:
options = []
(value, evalue) = dns.rcode.to_flags(rcode)
self.flags &= 0xFFF0
self.flags |= value
- self.ednsflags &= long(0x00FFFFFF)
+ self.ednsflags &= 0x00FFFFFF
self.ednsflags |= evalue
if self.ednsflags != 0 and self.edns < 0:
self.edns = 0
if self.updating and qcount > 1:
raise dns.exception.FormError
- for i in xrange(0, qcount):
+ for i in range(0, qcount):
(qname, used) = dns.name.from_wire(self.wire, self.current)
if self.message.origin is not None:
qname = qname.relativize(self.message.origin)
else:
force_unique = False
seen_opt = False
- for i in xrange(0, count):
+ for i in range(0, count):
rr_start = self.current
(name, used) = dns.name.from_wire(self.wire, self.current)
absolute_name = name
Returns a ``dns.message.Message object``
"""
- str_type = string_types
+ str_type = str
opts = 'rU'
if isinstance(f, str_type):
Returns a ``dns.message.Message``
"""
- if isinstance(qname, string_types):
+ if isinstance(qname, str):
qname = dns.name.from_text(qname)
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
- if isinstance(rdclass, string_types):
+ if isinstance(rdclass, str):
rdclass = dns.rdataclass.from_text(rdclass)
m = Message()
m.flags |= dns.flags.RD
import dns.exception
import dns.wiredata
-from ._compat import long, binary_type, text_type, unichr, maybe_decode
-
try:
maxint = sys.maxint # pylint: disable=sys-max-int
except AttributeError:
except Exception as e:
raise IDNAException(idna_exception=e)
else:
- label = maybe_decode(label)
+ label = label.decode()
return _escapify(label, True)
@rtype: string"""
if not unicode_mode:
text = ''
- if isinstance(label, text_type):
+ if isinstance(label, str):
label = label.encode()
for c in bytearray(label):
if c in _escaped:
return text.encode()
text = u''
- if isinstance(label, binary_type):
+ if isinstance(label, bytes):
label = label.decode()
for c in label:
if c > u'\x20' and c < u'\x7f':
"""
- if isinstance(label, binary_type):
+ if isinstance(label, bytes):
return label
- if isinstance(label, text_type):
+ if isinstance(label, str):
return label.encode()
raise ValueError
Returns an ``int``.
"""
- h = long(0)
+ h = 0
for label in self.labels:
for c in bytearray(label.lower()):
h += (h << 3) + c
- return int(h % maxint)
+ return h % maxint
def fullcompare(self, other):
"""Compare two names, returning a 3-tuple
"""
if len(self.labels) == 0:
- return maybe_decode(b'@')
+ return '@'
if len(self.labels) == 1 and self.labels[0] == b'':
- return maybe_decode(b'.')
+ return '.'
if omit_final_dot and self.is_absolute():
l = self.labels[:-1]
else:
l = self.labels
s = b'.'.join(map(_escapify, l))
- return maybe_decode(s)
+ return s.decode()
def to_unicode(self, omit_final_dot=False, idna_codec=None):
"""Convert name to Unicode text format.
Returns a ``dns.name.Name``.
"""
- if not isinstance(text, text_type):
+ if not isinstance(text, str):
raise ValueError("input to from_unicode() must be a unicode string")
if not (origin is None or isinstance(origin, Name)):
raise ValueError("origin must be a Name or None")
edigits += 1
if edigits == 3:
escaping = False
- label += unichr(total)
+ label += chr(total)
elif c in [u'.', u'\u3002', u'\uff0e', u'\uff61']:
if len(label) == 0:
raise EmptyLabel
Returns a ``dns.name.Name``.
"""
- if isinstance(text, text_type):
+ if isinstance(text, str):
return from_unicode(text, origin, idna_codec)
- if not isinstance(text, binary_type):
+ if not isinstance(text, bytes):
raise ValueError("input to from_text() must be a string")
if not (origin is None or isinstance(origin, Name)):
raise ValueError("origin must be a Name or None")
which were consumed reading it.
"""
- if not isinstance(message, binary_type):
+ if not isinstance(message, bytes):
raise ValueError("input to from_wire() must be a byte string")
message = dns.wiredata.maybe_wrap(message)
labels = []
import collections
import dns.name
-from ._compat import xrange
class NameDict(collections.MutableMapping):
depth = len(name)
if depth > self.max_depth:
depth = self.max_depth
- for i in xrange(-depth, 0):
+ for i in range(-depth, 0):
n = dns.name.Name(name[i:])
if n in self:
return (n, self[n])
import dns.rcode
import dns.rdataclass
import dns.rdatatype
-from ._compat import long, string_types, PY3
-
-if PY3:
- select_error = OSError
-else:
- select_error = select.error
# Function used to create a socket. Can be overridden if needed in special
# situations.
pollable.register(fd, event_mask)
if timeout:
- event_list = pollable.poll(long(timeout * 1000))
+ event_list = pollable.poll(timeout * 1000)
else:
event_list = pollable.poll()
try:
if not _polling_backend(fd, readable, writable, error, timeout):
raise dns.exception.Timeout
- except select_error as e:
+ except OSError as e:
if e.args[0] != errno.EINTR:
raise e
done = True
Returns a generator of ``dns.message.Message`` objects.
"""
- if isinstance(zone, string_types):
+ if isinstance(zone, str):
zone = dns.name.from_text(zone)
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
q = dns.message.make_query(zone, rdtype, rdclass)
if rdtype == dns.rdatatype.IXFR:
"""DNS Result Codes."""
import dns.exception
-from ._compat import long
#: No error
NOERROR = 0
if value < 0 or value > 4095:
raise ValueError('rcode must be >= 0 and <= 4095')
v = value & 0xf
- ev = long(value & 0xff0) << 20
+ ev = (value & 0xff0) << 20
return (v, ev)
import dns.rdatatype
import dns.tokenizer
import dns.wiredata
-from ._compat import xrange, string_types, text_type
try:
import threading as _threading
def _escapify(qstring):
"""Escape the characters in a quoted string which need it."""
- if isinstance(qstring, text_type):
+ if isinstance(qstring, str):
qstring = qstring.encode()
if not isinstance(qstring, bytearray):
qstring = bytearray(qstring)
return the bitmap that contains all the bytes less than that index.
"""
- for i in xrange(len(what) - 1, -1, -1):
+ for i in range(len(what) - 1, -1, -1):
if what[i] != 0:
return what[0: i + 1]
return what[0:1]
Returns an instance of the chosen Rdata subclass.
"""
- if isinstance(tok, string_types):
+ if isinstance(tok, str):
tok = dns.tokenizer.Tokenizer(tok)
cls = get_rdata_class(rdclass, rdtype)
if cls != GenericRdata:
import dns.rdataclass
import dns.rdata
import dns.set
-from ._compat import string_types
# define SimpleSet here for backwards compatibility
SimpleSet = dns.set.Set
Returns a ``dns.rdataset.Rdataset`` object.
"""
- if isinstance(rdclass, string_types):
+ if isinstance(rdclass, str):
rdclass = dns.rdataclass.from_text(rdclass)
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
r = Rdataset(rdclass, rdtype)
r.update_ttl(ttl)
import dns.rdata
import dns.rdatatype
import dns.name
-from dns._compat import xrange
class CSYNC(dns.rdata.Rdata):
text = ''
for (window, bitmap) in self.windows:
bits = []
- for i in xrange(0, len(bitmap)):
- byte = bitmap[i]
- for j in xrange(0, 8):
+ for (i, byte) in enumerate(bitmap):
+ for j in range(0, 8):
if byte & (0x80 >> j):
bits.append(dns.rdatatype.to_text(window * 256 +
i * 8 + j))
import dns.exception
import dns.rdata
import dns.tokenizer
-from dns._compat import long, text_type
def _validate_float_string(what):
def _sanitize(value):
- if isinstance(value, text_type):
+ if isinstance(value, str):
return value.encode()
return value
def __init__(self, rdclass, rdtype, latitude, longitude, altitude):
super(GPOS, self).__init__(rdclass, rdtype)
if isinstance(latitude, float) or \
- isinstance(latitude, int) or \
- isinstance(latitude, long):
+ isinstance(latitude, int):
latitude = str(latitude)
if isinstance(longitude, float) or \
- isinstance(longitude, int) or \
- isinstance(longitude, long):
+ isinstance(longitude, int):
longitude = str(longitude)
if isinstance(altitude, float) or \
- isinstance(altitude, int) or \
- isinstance(altitude, long):
+ isinstance(altitude, int):
altitude = str(altitude)
latitude = _sanitize(latitude)
longitude = _sanitize(longitude)
import dns.exception
import dns.rdata
import dns.tokenizer
-from dns._compat import text_type
class HINFO(dns.rdata.Rdata):
def __init__(self, rdclass, rdtype, cpu, os):
super(HINFO, self).__init__(rdclass, rdtype)
- if isinstance(cpu, text_type):
+ if isinstance(cpu, str):
self.cpu = cpu.encode()
else:
self.cpu = cpu
- if isinstance(os, text_type):
+ if isinstance(os, str):
self.os = os.encode()
else:
self.os = os
import dns.exception
import dns.rdata
import dns.tokenizer
-from dns._compat import text_type
class ISDN(dns.rdata.Rdata):
def __init__(self, rdclass, rdtype, address, subaddress):
super(ISDN, self).__init__(rdclass, rdtype)
- if isinstance(address, text_type):
+ if isinstance(address, str):
self.address = address.encode()
else:
self.address = address
- if isinstance(address, text_type):
+ if isinstance(address, str):
self.subaddress = subaddress.encode()
else:
self.subaddress = subaddress
import dns.exception
import dns.rdata
-from dns._compat import long, xrange, round_py2_compat
-_pows = tuple(long(10**i) for i in range(0, 11))
+_pows = tuple(10**i for i in range(0, 11))
# default values are in centimeters
_default_size = 100.0
if what == 0:
return 0
exp = None
- for i in xrange(len(_pows)):
- if what // _pows[i] == long(0):
+ for (i, pow) in enumerate(_pows):
+ if what // pow == 0:
exp = i - 1
break
if exp is None or exp < 0:
what *= -1
else:
sign = 1
- what = round_py2_compat(what * 3600000)
+ what = round(what * 3600000) # pylint: disable=round-builtin
degrees = int(what // 3600000)
what -= degrees * 3600000
minutes = int(what // 60000)
def _encode_size(what, desc):
- what = long(what)
+ what = int(what)
exponent = _exponent_of(what, desc) & 0xF
base = what // pow(10, exponent) & 0xF
return base * 16 + exponent
base = (what & 0xF0) >> 4
if base > 9:
raise dns.exception.SyntaxError("bad %s base" % desc)
- return long(base) * pow(10, exponent)
+ return base * pow(10, exponent)
class LOC(dns.rdata.Rdata):
and vertical precision are specified in centimeters."""
super(LOC, self).__init__(rdclass, rdtype)
- if isinstance(latitude, int) or isinstance(latitude, long):
+ if isinstance(latitude, int):
latitude = float(latitude)
if isinstance(latitude, float):
latitude = _float_to_tuple(latitude)
self.latitude = latitude
- if isinstance(longitude, int) or isinstance(longitude, long):
+ if isinstance(longitude, int):
longitude = float(longitude)
if isinstance(longitude, float):
longitude = _float_to_tuple(longitude)
self.latitude[1] * 60000 +
self.latitude[2] * 1000 +
self.latitude[3]) * self.latitude[4]
- latitude = long(0x80000000) + milliseconds
+ latitude = 0x80000000 + milliseconds
milliseconds = (self.longitude[0] * 3600000 +
self.longitude[1] * 60000 +
self.longitude[2] * 1000 +
self.longitude[3]) * self.longitude[4]
- longitude = long(0x80000000) + milliseconds
- altitude = long(self.altitude) + long(10000000)
+ longitude = 0x80000000 + milliseconds
+ altitude = int(self.altitude) + 10000000
size = _encode_size(self.size, "size")
hprec = _encode_size(self.horizontal_precision, "horizontal precision")
vprec = _encode_size(self.vertical_precision, "vertical precision")
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
(version, size, hprec, vprec, latitude, longitude, altitude) = \
struct.unpack("!BBBBIII", wire[current: current + rdlen])
- if latitude > long(0x80000000):
- latitude = float(latitude - long(0x80000000)) / 3600000
+ if latitude > 0x80000000:
+ latitude = float(latitude - 0x80000000) / 3600000
else:
- latitude = -1 * float(long(0x80000000) - latitude) / 3600000
+ latitude = -1 * float(0x80000000 - latitude) / 3600000
if latitude < -90.0 or latitude > 90.0:
raise dns.exception.FormError("bad latitude")
- if longitude > long(0x80000000):
- longitude = float(longitude - long(0x80000000)) / 3600000
+ if longitude > 0x80000000:
+ longitude = float(longitude - 0x80000000) / 3600000
else:
- longitude = -1 * float(long(0x80000000) - longitude) / 3600000
+ longitude = -1 * float(0x80000000 - longitude) / 3600000
if longitude < -180.0 or longitude > 180.0:
raise dns.exception.FormError("bad longitude")
altitude = float(altitude) - 10000000.0
import dns.rdata
import dns.rdatatype
import dns.name
-from dns._compat import xrange
class NSEC(dns.rdata.Rdata):
text = ''
for (window, bitmap) in self.windows:
bits = []
- for i in xrange(0, len(bitmap)):
- byte = bitmap[i]
- for j in xrange(0, 8):
+ for (i, byte) in enumerate(bitmap):
+ for j in range(0, 8):
if byte & (0x80 >> j):
bits.append(dns.rdatatype.to_text(window * 256 +
i * 8 + j))
import base64
import binascii
-import string
import struct
import dns.exception
import dns.rdata
import dns.rdatatype
-from dns._compat import xrange, text_type, PY3
-
-# pylint: disable=deprecated-string-function
-if PY3:
- b32_hex_to_normal = bytes.maketrans(b'0123456789ABCDEFGHIJKLMNOPQRSTUV',
- b'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
- b32_normal_to_hex = bytes.maketrans(b'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
- b'0123456789ABCDEFGHIJKLMNOPQRSTUV')
-else:
- b32_hex_to_normal = string.maketrans('0123456789ABCDEFGHIJKLMNOPQRSTUV',
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
- b32_normal_to_hex = string.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
- '0123456789ABCDEFGHIJKLMNOPQRSTUV')
-# pylint: enable=deprecated-string-function
+b32_hex_to_normal = bytes.maketrans(b'0123456789ABCDEFGHIJKLMNOPQRSTUV',
+ b'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
+b32_normal_to_hex = bytes.maketrans(b'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
+ b'0123456789ABCDEFGHIJKLMNOPQRSTUV')
+
# hash algorithm constants
SHA1 = 1
self.algorithm = algorithm
self.flags = flags
self.iterations = iterations
- if isinstance(salt, text_type):
+ if isinstance(salt, str):
self.salt = salt.encode()
else:
self.salt = salt
text = u''
for (window, bitmap) in self.windows:
bits = []
- for i in xrange(0, len(bitmap)):
- byte = bitmap[i]
- for j in xrange(0, 8):
+ for (i, byte) in enumerate(bitmap):
+ for j in range(0, 8):
if byte & (0x80 >> j):
bits.append(dns.rdatatype.to_text(window * 256 +
i * 8 + j))
import dns.exception
import dns.rdata
-from dns._compat import text_type
class NSEC3PARAM(dns.rdata.Rdata):
self.algorithm = algorithm
self.flags = flags
self.iterations = iterations
- if isinstance(salt, text_type):
+ if isinstance(salt, str):
self.salt = salt.encode()
else:
self.salt = salt
import dns.exception
import dns.rdata
import dns.name
-from dns._compat import text_type
class URI(dns.rdata.Rdata):
self.weight = weight
if len(target) < 1:
raise dns.exception.SyntaxError("URI target cannot be empty")
- if isinstance(target, text_type):
+ if isinstance(target, str):
self.target = target.encode()
else:
self.target = target
import dns.exception
import dns.rdata
import dns.tokenizer
-from dns._compat import text_type
class X25(dns.rdata.Rdata):
def __init__(self, rdclass, rdtype, address):
super(X25, self).__init__(rdclass, rdtype)
- if isinstance(address, text_type):
+ if isinstance(address, str):
self.address = address.encode()
else:
self.address = address
import dns.inet
import dns.rdata
import dns.tokenizer
-from dns._compat import xrange, maybe_chr
-
class APLItem(object):
# Truncate least significant zero bytes.
#
last = 0
- for i in xrange(len(address) - 1, -1, -1):
- if address[i] != maybe_chr(0):
+ for i in range(len(address) - 1, -1, -1):
+ if address[i] != 0:
last = i + 1
break
address = address[0: last]
import dns.exception
import dns.name
import dns.rdata
-from dns._compat import xrange, text_type
def _write_string(file, s):
def _sanitize(value):
- if isinstance(value, text_type):
+ if isinstance(value, str):
return value.encode()
return value
current += 4
rdlen -= 4
strings = []
- for i in xrange(3):
+ for i in range(3):
l = wire[current]
current += 1
rdlen -= 1
import dns.ipv4
import dns.rdata
-from dns._compat import xrange
_proto_tcp = socket.getprotobyname('tcp')
_proto_udp = socket.getprotobyname('udp')
def to_text(self, origin=None, relativize=True, **kw):
bits = []
- for i in xrange(0, len(self.bitmap)):
+ for i in range(0, len(self.bitmap)):
byte = self.bitmap[i]
- for j in xrange(0, 8):
+ for j in range(0, 8):
if byte & (0x80 >> j):
bits.append(str(i * 8 + j))
text = ' '.join(bits)
i = serv // 8
l = len(bitmap)
if l < i + 1:
- for j in xrange(l, i + 1):
+ for j in range(l, i + 1):
bitmap.append(0)
bitmap[i] = bitmap[i] | (0x80 >> (serv % 8))
bitmap = dns.rdata._truncate_bitmap(bitmap)
import binascii
import dns.rdata
-from dns._compat import xrange
class EUIBase(dns.rdata.Rdata):
if len(text) != cls.text_len:
raise dns.exception.SyntaxError(
'Input text must have %s characters' % cls.text_len)
- expected_dash_idxs = xrange(2, cls.byte_len * 3 - 1, 3)
- for i in expected_dash_idxs:
+ for i in range(2, cls.byte_len * 3 - 1, 3):
if text[i] != '-':
raise dns.exception.SyntaxError('Dash expected at position %s'
% i)
import dns.exception
import dns.rdata
import dns.tokenizer
-from dns._compat import binary_type, string_types
class TXTBase(dns.rdata.Rdata):
def __init__(self, rdclass, rdtype, strings):
super(TXTBase, self).__init__(rdclass, rdtype)
- if isinstance(strings, binary_type) or \
- isinstance(strings, string_types):
+ if isinstance(strings, bytes) or \
+ isinstance(strings, str):
strings = [strings]
self.strings = []
for string in strings:
- if isinstance(string, string_types):
+ if isinstance(string, str):
string = string.encode()
self.strings.append(string)
if len(token.value) > 255:
raise dns.exception.SyntaxError("string too long")
value = token.value
- if isinstance(value, binary_type):
+ if isinstance(value, bytes):
strings.append(value)
else:
strings.append(value.encode())
import dns.exception
import dns.tsig
-from ._compat import long
QUESTION = 0
"""Add an EDNS OPT record to the message."""
# make sure the EDNS version in ednsflags agrees with edns
- ednsflags &= long(0xFF00FFFF)
+ ednsflags &= 0xFF00FFFF
ednsflags |= (edns << 16)
self._set_section(ADDITIONAL)
before = self.output.tell()
import sys
import time
import random
-
try:
import threading as _threading
except ImportError:
import dns.rdatatype
import dns.reversename
import dns.tsig
-from ._compat import xrange, string_types
if sys.platform == 'win32':
try:
self.response = response
min_ttl = -1
rrset = None
- for count in xrange(0, 15):
+ for count in range(0, 15):
try:
rrset = response.find_rrset(response.answer, qname,
rdclass, rdtype)
a ``text``, it is used as the name of the file to open; otherwise it
is treated as the file itself."""
- if isinstance(f, string_types):
+ if isinstance(f, str):
try:
f = open(f, 'r')
except IOError:
Returns a ``dns.resolver.Answer`` instance.
"""
- if isinstance(qname, string_types):
+ if isinstance(qname, str):
qname = dns.name.from_text(qname, None)
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
if dns.rdatatype.is_metatype(rdtype):
raise NoMetaqueries
- if isinstance(rdclass, string_types):
+ if isinstance(rdclass, str):
rdclass = dns.rdataclass.from_text(rdclass)
if dns.rdataclass.is_metaclass(rdclass):
raise NoMetaqueries
Returns a ``dns.name.Name``.
"""
- if isinstance(name, string_types):
+ if isinstance(name, str):
name = dns.name.from_text(name, dns.name.root)
if resolver is None:
resolver = get_default_resolver()
import dns.ipv6
import dns.ipv4
-from dns._compat import PY3
-
ipv4_reverse_domain = dns.name.from_text('in-addr.arpa.')
ipv6_reverse_domain = dns.name.from_text('ip6.arpa.')
try:
v6 = dns.ipv6.inet_aton(text)
if dns.ipv6.is_mapped(v6):
- if PY3:
- parts = ['%d' % byte for byte in v6[12:]]
- else:
- parts = ['%d' % ord(byte) for byte in v6[12:]]
+ parts = ['%d' % byte for byte in v6[12:]]
origin = ipv4_reverse_domain
else:
parts = [x for x in str(binascii.hexlify(v6).decode())]
import dns.rdataset
import dns.rdataclass
import dns.renderer
-from ._compat import string_types
class RRset(dns.rdataset.Rdataset):
Returns a ``dns.rrset.RRset`` object.
"""
- if isinstance(name, string_types):
+ if isinstance(name, str):
name = dns.name.from_text(name, None, idna_codec=idna_codec)
- if isinstance(rdclass, string_types):
+ if isinstance(rdclass, str):
rdclass = dns.rdataclass.from_text(rdclass)
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
r = RRset(name, rdclass, rdtype)
r.update_ttl(ttl)
Returns a ``dns.rrset.RRset`` object.
"""
- if isinstance(name, string_types):
+ if isinstance(name, str):
name = dns.name.from_text(name, None, idna_codec=idna_codec)
if len(rdatas) == 0:
import dns.exception
import dns.name
import dns.ttl
-from ._compat import long, text_type, binary_type
_DELIMITERS = {
' ': True,
will return.
"""
- if isinstance(f, text_type):
+ if isinstance(f, str):
f = StringIO(f)
if filename is None:
filename = '<string>'
- elif isinstance(f, binary_type):
+ elif isinstance(f, bytes):
f = StringIO(f.decode())
if filename is None:
filename = '<string>'
raise dns.exception.SyntaxError('expecting an identifier')
if not token.value.isdigit():
raise dns.exception.SyntaxError('expecting an integer')
- value = long(token.value)
- if value < 0 or value > long(4294967296):
+ value = int(token.value)
+ if value < 0 or value > 4294967296:
raise dns.exception.SyntaxError(
'%d is not an unsigned 32-bit integer' % value)
return value
import dns.exception
import dns.rdataclass
import dns.name
-from ._compat import long, string_types, text_type
class BadTime(dns.exception.DNSException):
@raises NotImplementedError: I{algorithm} is not supported
"""
- if isinstance(other_data, text_type):
+ if isinstance(other_data, str):
other_data = other_data.encode()
(algorithm_name, digestmod) = get_algorithm(algorithm)
if first:
ctx.update(keyname.to_digestable())
ctx.update(struct.pack('!H', dns.rdataclass.ANY))
ctx.update(struct.pack('!I', 0))
- long_time = time + long(0)
- upper_time = (long_time >> 32) & long(0xffff)
- lower_time = long_time & long(0xffffffff)
+ upper_time = (time >> 32) & 0xffff
+ lower_time = time & 0xffffffff
time_mac = struct.pack('!HIH', upper_time, lower_time, fudge)
pre_mac = algorithm_name + time_mac
ol = len(other_data)
current = current + used
(upper_time, lower_time, fudge, mac_size) = \
struct.unpack("!HIHH", wire[current:current + 10])
- time = ((upper_time + long(0)) << 32) + (lower_time + long(0))
+ time = (upper_time << 32) + lower_time
current += 10
mac = wire[current:current + mac_size]
current += mac_size
@raises NotImplementedError: I{algorithm} is not supported
"""
- if isinstance(algorithm, string_types):
+ if isinstance(algorithm, str):
algorithm = dns.name.from_text(algorithm)
try:
"""A place to store TSIG keys."""
-from dns._compat import maybe_decode, maybe_encode
-
import base64
import dns.name
keyring = {}
for keytext in textring:
keyname = dns.name.from_text(keytext)
- secret = base64.decodestring(maybe_encode(textring[keytext]))
+ secret = base64.decodestring(textring[keytext].encode())
keyring[keyname] = secret
return keyring
textring = {}
for keyname in keyring:
- keytext = maybe_decode(keyname.to_text())
- secret = maybe_decode(base64.encodestring(keyring[keyname]))
+ keytext = keyname.to_text().decode()
+ secret = base64.encodestring(keyring[keyname]).decode()
textring[keytext] = secret
return textring
"""DNS TTL conversion."""
import dns.exception
-from ._compat import long
class BadTTL(dns.exception.SyntaxError):
"""
if text.isdigit():
- total = long(text)
+ total = int(text)
else:
if not text[0].isdigit():
raise BadTTL
- total = long(0)
- current = long(0)
+ total = 0
+ current = 0
for c in text:
if c.isdigit():
current *= 10
- current += long(c)
+ current += int(c)
else:
c = c.lower()
if c == 'w':
- total += current * long(604800)
+ total += current * 604800
elif c == 'd':
- total += current * long(86400)
+ total += current * 86400
elif c == 'h':
- total += current * long(3600)
+ total += current * 3600
elif c == 'm':
- total += current * long(60)
+ total += current * 60
elif c == 's':
total += current
else:
current = 0
if not current == 0:
raise BadTTL("trailing integer")
- if total < long(0) or total > long(2147483647):
+ if total < 0 or total > 2147483647:
raise BadTTL("TTL should be between 0 and 2^31 - 1 (inclusive)")
return total
import dns.rdataclass
import dns.rdataset
import dns.tsig
-from ._compat import string_types
class Update(dns.message.Message):
"""
super(Update, self).__init__()
self.flags |= dns.opcode.to_flags(dns.opcode.UPDATE)
- if isinstance(zone, string_types):
+ if isinstance(zone, str):
zone = dns.name.from_text(zone)
self.origin = zone
- if isinstance(rdclass, string_types):
+ if isinstance(rdclass, str):
rdclass = dns.rdataclass.from_text(rdclass)
self.zone_rdclass = rdclass
self.find_rrset(self.question, self.origin, rdclass, dns.rdatatype.SOA,
- ttl, rdtype, string...
"""
- if isinstance(name, string_types):
+ if isinstance(name, str):
name = dns.name.from_text(name, None)
if isinstance(args[0], dns.rdataset.Rdataset):
for rds in args:
self._add_rr(name, ttl, rd, section=section)
else:
rdtype = args.pop(0)
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
if replace:
self.delete(name, rdtype)
- rdtype, [string...]
"""
- if isinstance(name, string_types):
+ if isinstance(name, str):
name = dns.name.from_text(name, None)
if len(args) == 0:
self.find_rrset(self.authority, name, dns.rdataclass.ANY,
self._add_rr(name, 0, rd, dns.rdataclass.NONE)
else:
rdtype = args.pop(0)
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
if len(args) == 0:
self.find_rrset(self.authority, name,
- rdtype, string...
"""
- if isinstance(name, string_types):
+ if isinstance(name, str):
name = dns.name.from_text(name, None)
if len(args) == 0:
self.find_rrset(self.answer, name,
self._add(False, self.answer, name, *args)
else:
rdtype = args[0]
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
self.find_rrset(self.answer, name,
dns.rdataclass.ANY, rdtype,
"""Require that an owner name (and optionally an rdata type) does
not exist as a prerequisite to the execution of the update."""
- if isinstance(name, string_types):
+ if isinstance(name, str):
name = dns.name.from_text(name, None)
if rdtype is None:
self.find_rrset(self.answer, name,
dns.rdatatype.NONE, None,
True, True)
else:
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
self.find_rrset(self.answer, name,
dns.rdataclass.NONE, rdtype,
"""DNS Wire Data Helper"""
import dns.exception
-from ._compat import binary_type, string_types, PY2
# Figure out what constant python passes for an unspecified slice bound.
# It's supposed to be sys.maxint, yet on 64-bit windows sys.maxint is 2^31 - 1
# out what constant Python will use.
-class _SliceUnspecifiedBound(binary_type):
+class _SliceUnspecifiedBound(bytes):
def __getitem__(self, key):
return key.stop
- if PY2:
- def __getslice__(self, i, j): # pylint: disable=getslice-method
- return self.__getitem__(slice(i, j))
-
_unspecified_bound = _SliceUnspecifiedBound()[1:]
-class WireData(binary_type):
+class WireData(bytes):
# WireData is a binary type with stricter slicing
def __getitem__(self, key):
start = key.start
stop = key.stop
- if PY2:
- if stop == _unspecified_bound:
- # handle the case where the right bound is unspecified
- stop = len(self)
-
- if start < 0 or stop < 0:
+ for index in (start, stop):
+ if index is None:
+ continue
+ elif abs(index) > len(self):
raise dns.exception.FormError
- # If it's not an empty slice, access left and right bounds
- # to make sure they're valid
- if start != stop:
- super(WireData, self).__getitem__(start)
- super(WireData, self).__getitem__(stop - 1)
- else:
- for index in (start, stop):
- if index is None:
- continue
- elif abs(index) > len(self):
- raise dns.exception.FormError
return WireData(super(WireData, self).__getitem__(
slice(start, stop)))
except IndexError:
raise dns.exception.FormError
- if PY2:
- def __getslice__(self, i, j): # pylint: disable=getslice-method
- return self.__getitem__(slice(i, j))
-
def __iter__(self):
i = 0
while 1:
raise StopIteration
def unwrap(self):
- return binary_type(self)
+ return bytes(self)
def maybe_wrap(wire):
if isinstance(wire, WireData):
return wire
- elif isinstance(wire, binary_type):
+ elif isinstance(wire, bytes):
return WireData(wire)
- elif isinstance(wire, string_types):
+ elif isinstance(wire, str):
return WireData(wire.encode())
raise ValueError("unhandled type %s" % type(wire))
import dns.tokenizer
import dns.ttl
import dns.grange
-from ._compat import string_types, text_type, PY3
class BadZone(dns.exception.DNSException):
@type rdclass: int"""
if origin is not None:
- if isinstance(origin, string_types):
+ if isinstance(origin, str):
origin = dns.name.from_text(origin)
elif not isinstance(origin, dns.name.Name):
raise ValueError("origin parameter must be convertible to a "
return not self.__eq__(other)
def _validate_name(self, name):
- if isinstance(name, string_types):
+ if isinstance(name, str):
name = dns.name.from_text(name, None)
elif not isinstance(name, dns.name.Name):
raise KeyError("name parameter must be convertible to a DNS name")
return self.nodes.__iter__()
def iterkeys(self):
- if PY3:
- return self.nodes.keys() # pylint: disable=dict-keys-not-iterating
- else:
- return self.nodes.iterkeys() # pylint: disable=dict-iter-method
+ return self.nodes.keys() # pylint: disable=dict-keys-not-iterating
def keys(self):
return self.nodes.keys() # pylint: disable=dict-keys-not-iterating
def itervalues(self):
- if PY3:
- return self.nodes.values() # pylint: disable=dict-values-not-iterating
- else:
- return self.nodes.itervalues() # pylint: disable=dict-iter-method
+ return self.nodes.values() # pylint: disable=dict-values-not-iterating
def values(self):
return self.nodes.values() # pylint: disable=dict-values-not-iterating
"""
name = self._validate_name(name)
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
- if isinstance(covers, string_types):
+ if isinstance(covers, str):
covers = dns.rdatatype.from_text(covers)
node = self.find_node(name, create)
return node.find_rdataset(self.rdclass, rdtype, covers, create)
"""
name = self._validate_name(name)
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
- if isinstance(covers, string_types):
+ if isinstance(covers, str):
covers = dns.rdatatype.from_text(covers)
node = self.get_node(name)
if node is not None:
"""
name = self._validate_name(name)
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
- if isinstance(covers, string_types):
+ if isinstance(covers, str):
covers = dns.rdatatype.from_text(covers)
rdataset = self.nodes[name].find_rdataset(self.rdclass, rdtype, covers)
rrset = dns.rrset.RRset(name, self.rdclass, rdtype, covers)
@type covers: int or string
"""
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
- if isinstance(covers, string_types):
+ if isinstance(covers, str):
covers = dns.rdatatype.from_text(covers)
for (name, node) in self.iteritems(): # pylint: disable=dict-iter-method
for rds in node:
@type covers: int or string
"""
- if isinstance(rdtype, string_types):
+ if isinstance(rdtype, str):
rdtype = dns.rdatatype.from_text(rdtype)
- if isinstance(covers, string_types):
+ if isinstance(covers, str):
covers = dns.rdatatype.from_text(covers)
for (name, node) in self.iteritems(): # pylint: disable=dict-iter-method
for rds in node:
@type nl: string or None
"""
- if isinstance(f, string_types):
+ if isinstance(f, str):
f = open(f, 'wb')
want_close = True
else:
if nl is None:
nl_b = os.linesep.encode(file_enc) # binary mode, '\n' is not enough
nl = u'\n'
- elif isinstance(nl, string_types):
+ elif isinstance(nl, str):
nl_b = nl.encode(file_enc)
else:
nl_b = nl
for n in names:
l = self[n].to_text(n, origin=self.origin,
relativize=relativize)
- if isinstance(l, text_type):
+ if isinstance(l, str):
l_b = l.encode(file_enc)
else:
l_b = l
def __init__(self, tok, origin, rdclass, relativize, zone_factory=Zone,
allow_include=False, check_origin=True):
- if isinstance(origin, string_types):
+ if isinstance(origin, str):
origin = dns.name.from_text(origin)
self.tok = tok
self.current_origin = origin
@rtype: dns.zone.Zone object
"""
- str_type = string_types
- if PY3:
- opts = 'r'
- else:
- opts = 'rU'
-
- if isinstance(f, str_type):
+ if isinstance(f, str):
if filename is None:
filename = f
- f = open(f, opts)
+ f = open(f, 'r')
want_close = True
else:
if filename is None:
import dns.rdatatype
import dns.rrset
import dns.zone
-from dns._compat import long
-
import pprint
l = list(z.iterate_rdatas())
l.sort(key=_rdata_sort)
exl = [(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns1')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns2')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA,
'foo bar 1 2 3 4 5')),
(dns.name.from_text('bar.foo', None),
- long(300),
+ 300,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX,
'0 blaz.foo')),
(dns.name.from_text('ns1', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.1')),
(dns.name.from_text('ns2', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.2')),
(dns.name.from_text('wp-db01.services.mozilla.com', None),
- long(0),
+ 0,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME,
'SERVER.FOOBAR.')),
(dns.name.from_text('wp-db02.services.mozilla.com', None),
- long(0),
+ 0,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME,
'SERVER.FOOBAR.')),
(dns.name.from_text('wp-db03.services.mozilla.com', None),
- long(0),
+ 0,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME,
'SERVER.FOOBAR.'))]
exl.sort(key=_rdata_sort)
l = list(z.iterate_rdatas())
l.sort(key=_rdata_sort)
exl = [(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns1')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns2')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA,
'foo bar 1 2 3 4 5')),
(dns.name.from_text('bar.foo', None),
- long(300),
+ 300,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX,
'0 blaz.foo')),
(dns.name.from_text('ns1', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.1')),
(dns.name.from_text('ns2', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.2')),
- (dns.name.from_text('wp-db21.services.mozilla.com', None), long(0),
+ (dns.name.from_text('wp-db21.services.mozilla.com', None), 0,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME,
'SERVER.FOOBAR.')),
- (dns.name.from_text('wp-db22.services.mozilla.com', None), long(0),
+ (dns.name.from_text('wp-db22.services.mozilla.com', None), 0,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME,
'SERVER.FOOBAR.')),
- (dns.name.from_text('wp-db23.services.mozilla.com', None), long(0),
+ (dns.name.from_text('wp-db23.services.mozilla.com', None), 0,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME,
'SERVER.FOOBAR.'))]
exl.sort(key=_rdata_sort)
l.sort(key=_rdata_sort)
exl = [(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns1')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns2')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA,
'foo bar 1 2 3 4 5')),
(dns.name.from_text('bar.foo', None),
- long(300),
+ 300,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX,
'0 blaz.foo')),
(dns.name.from_text('ns1', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.1')),
(dns.name.from_text('ns2', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.2')),
- (dns.name.from_text('wp-db21.services.mozilla.com', None), long(0),
+ (dns.name.from_text('wp-db21.services.mozilla.com', None), 0,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME,
'SERVER.FOOBAR.')),
- (dns.name.from_text('wp-db22.services.mozilla.com', None), long(0),
+ (dns.name.from_text('wp-db22.services.mozilla.com', None), 0,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME,
'SERVER.FOOBAR.')),
- (dns.name.from_text('wp-db23.services.mozilla.com', None), long(0),
+ (dns.name.from_text('wp-db23.services.mozilla.com', None), 0,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME,
'SERVER.FOOBAR.'))]
exl.sort(key=_rdata_sort)
l = list(z.iterate_rdatas())
l.sort(key=_rdata_sort)
exl = [(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns1')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns2')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA,
'foo bar 1 2 3 4 5')),
(dns.name.from_text('bar.foo', None),
- long(300),
+ 300,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX,
'0 blaz.foo')),
(dns.name.from_text('ns1', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.1')),
(dns.name.from_text('ns2', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.2')),
- (dns.name.from_text('sync1.db', None), long(3600),
+ (dns.name.from_text('sync1.db', None), 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.10.16.0')),
- (dns.name.from_text('sync2.db', None), long(3600),
+ (dns.name.from_text('sync2.db', None), 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.10.16.0')),
- (dns.name.from_text('sync3.db', None), long(3600),
+ (dns.name.from_text('sync3.db', None), 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.10.16.0'))]
exl.sort(key=_rdata_sort)
l = list(z.iterate_rdatas())
l.sort(key=_rdata_sort)
exl = [(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns1')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns2')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA,
'foo bar 1 2 3 4 5')),
(dns.name.from_text('bar.foo', None),
- long(300),
+ 300,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX,
'0 blaz.foo')),
(dns.name.from_text('ns1', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.1')),
(dns.name.from_text('ns2', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.2')),
- (dns.name.from_text('wp-db01', None), long(3600),
+ (dns.name.from_text('wp-db01', None), 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.10.16.0')),
- (dns.name.from_text('wp-db02', None), long(3600),
+ (dns.name.from_text('wp-db02', None), 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.10.16.0')),
- (dns.name.from_text('sync1.db', None), long(3600),
+ (dns.name.from_text('sync1.db', None), 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.10.16.0')),
- (dns.name.from_text('sync2.db', None), long(3600),
+ (dns.name.from_text('sync2.db', None), 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.10.16.0')),
- (dns.name.from_text('sync3.db', None), long(3600),
+ (dns.name.from_text('sync3.db', None), 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.10.16.0'))]
exl.sort(key=_rdata_sort)
l = list(z.iterate_rdatas())
l.sort(key=_rdata_sort)
exl = [(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns1')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS,
'ns2')),
(dns.name.from_text('@', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA,
'foo bar 1 2 3 4 5')),
(dns.name.from_text('bar.foo', None),
- long(300),
+ 300,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX,
'0 blaz.foo')),
(dns.name.from_text('ns1', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.1')),
(dns.name.from_text('ns2', None),
- long(3600),
+ 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A,
'10.0.0.2')),
- (dns.name.from_text('27.2', None), long(3600),
+ (dns.name.from_text('27.2', None), 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.PTR,
'zlb1.oob')),
- (dns.name.from_text('28.2', None), long(3600),
+ (dns.name.from_text('28.2', None), 3600,
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.PTR,
'zlb2.oob'))]
import dns.name
import dns.rdataclass
import dns.rdatatype
-from dns._compat import xrange
query_text = """id 1234
opcode QUERY
def test_TooBig(self):
def bad():
q = dns.message.from_text(query_text)
- for i in xrange(0, 25):
+ for i in range(0, 25):
rrset = dns.rrset.from_text('foo%d.' % i, 3600,
dns.rdataclass.IN,
dns.rdatatype.A,
import dns.rdataclass
import dns.rdatatype
import dns.resolver
-from dns._compat import xrange, PY3
# Some tests require the internet to be available to run, so let's
# skip those if it's not there.
def testLRUReplace(self):
cache = dns.resolver.LRUCache(4)
- for i in xrange(0, 5):
+ for i in range(0, 5):
name = dns.name.from_text('example%d.' % i)
answer = FakeAnswer(time.time() + 1)
cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer)
- for i in xrange(0, 5):
+ for i in range(0, 5):
name = dns.name.from_text('example%d.' % i)
if i == 0:
self.failUnless(cache.get((name, dns.rdatatype.A,
def testLRUDoesLRU(self):
cache = dns.resolver.LRUCache(4)
- for i in xrange(0, 4):
+ for i in range(0, 4):
name = dns.name.from_text('example%d.' % i)
answer = FakeAnswer(time.time() + 1)
cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer)
name = dns.name.from_text('example4.')
answer = FakeAnswer(time.time() + 1)
cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer)
- for i in xrange(0, 5):
+ for i in range(0, 5):
name = dns.name.from_text('example%d.' % i)
if i == 1:
self.failUnless(cache.get((name, dns.rdatatype.A,
def testLRUExpiration(self):
cache = dns.resolver.LRUCache(4)
- for i in xrange(0, 4):
+ for i in range(0, 4):
name = dns.name.from_text('example%d.' % i)
answer = FakeAnswer(time.time() + 1)
cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer)
time.sleep(2)
- for i in xrange(0, 4):
+ for i in range(0, 4):
name = dns.name.from_text('example%d.' % i)
self.failUnless(cache.get((name, dns.rdatatype.A,
dns.rdataclass.IN))
try:
raise dns.resolver.NXDOMAIN
except dns.exception.DNSException as e:
- if not PY3:
- # pylint: disable=exception-message-attribute
- self.assertTrue((e.message == e.__doc__))
self.assertTrue((e.args == (e.__doc__,)))
self.assertTrue(('kwargs' in dir(e)))
self.assertTrue((str(e) == e.__doc__), str(e))
try:
raise dns.resolver.NXDOMAIN("errmsg")
except dns.exception.DNSException as e:
- if not PY3:
- # pylint: disable=exception-message-attribute
- self.assertTrue((e.message == "errmsg"))
self.assertTrue((e.args == ("errmsg",)))
self.assertTrue(('kwargs' in dir(e)))
self.assertTrue((str(e) == "errmsg"), str(e))
try:
raise dns.resolver.NXDOMAIN("errmsg", -1)
except dns.exception.DNSException as e:
- if not PY3:
- # pylint: disable=exception-message-attribute
- self.assertTrue((e.message == ""))
self.assertTrue((e.args == ("errmsg", -1)))
self.assertTrue(('kwargs' in dir(e)))
self.assertTrue((str(e) == "('errmsg', -1)"), str(e))
raise dns.resolver.NXDOMAIN(qnames=[n1])
except dns.exception.DNSException as e:
MSG = "The DNS query name does not exist: a.b."
- if not PY3:
- # pylint: disable=exception-message-attribute
- self.assertTrue((e.message == MSG), e.message)
self.assertTrue((e.args == (MSG,)), repr(e.args))
self.assertTrue(('kwargs' in dir(e)))
self.assertTrue((str(e) == MSG), str(e))
e0 = dns.resolver.NXDOMAIN("errmsg")
e = e0 + e
MSG = "None of DNS query names exist: a.b.s., a.b."
- if not PY3:
- # pylint: disable=exception-message-attribute
- self.assertTrue((e.message == MSG), e.message)
self.assertTrue((e.args == (MSG,)), repr(e.args))
self.assertTrue(('kwargs' in dir(e)))
self.assertTrue((str(e) == MSG), str(e))
raise dns.resolver.NXDOMAIN(qnames=[n1], responses={n1: 'r1.1'})
except dns.resolver.NXDOMAIN as e:
MSG = "The DNS query name does not exist: a.b."
- if not PY3:
- # pylint: disable=exception-message-attribute
- self.assertTrue((e.message == MSG), e.message)
self.assertTrue((e.args == (MSG,)), repr(e.args))
self.assertTrue(('kwargs' in dir(e)))
self.assertTrue((str(e) == MSG), str(e))