]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Remove _compat module.
authorBob Halley <halley@dnspython.org>
Sun, 9 Dec 2018 20:06:24 +0000 (12:06 -0800)
committerBob Halley <halley@dnspython.org>
Sun, 9 Dec 2018 20:06:24 +0000 (12:06 -0800)
45 files changed:
Makefile
differences.md [new file with mode: 0644]
dns/_compat.py [deleted file]
dns/dnssec.py
dns/e164.py
dns/entropy.py
dns/inet.py
dns/ipv4.py
dns/ipv6.py
dns/message.py
dns/name.py
dns/namedict.py
dns/query.py
dns/rcode.py
dns/rdata.py
dns/rdataset.py
dns/rdtypes/ANY/CSYNC.py
dns/rdtypes/ANY/GPOS.py
dns/rdtypes/ANY/HINFO.py
dns/rdtypes/ANY/ISDN.py
dns/rdtypes/ANY/LOC.py
dns/rdtypes/ANY/NSEC.py
dns/rdtypes/ANY/NSEC3.py
dns/rdtypes/ANY/NSEC3PARAM.py
dns/rdtypes/ANY/URI.py
dns/rdtypes/ANY/X25.py
dns/rdtypes/IN/APL.py
dns/rdtypes/IN/NAPTR.py
dns/rdtypes/IN/WKS.py
dns/rdtypes/euibase.py
dns/rdtypes/txtbase.py
dns/renderer.py
dns/resolver.py
dns/reversename.py
dns/rrset.py
dns/tokenizer.py
dns/tsig.py
dns/tsigkeyring.py
dns/ttl.py
dns/update.py
dns/wiredata.py
dns/zone.py
tests/test_generate.py
tests/test_message.py
tests/test_resolver.py

index 958e684cb9e7ae9a849e5a292437551214bb8c8d..d20eed210f866bd3ff7b587661878226767530de 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -60,19 +60,14 @@ tags:
 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
diff --git a/differences.md b/differences.md
new file mode 100644 (file)
index 0000000..0896e8f
--- /dev/null
@@ -0,0 +1,6 @@
+# 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.
diff --git a/dns/_compat.py b/dns/_compat.py
deleted file mode 100644 (file)
index ca0931c..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-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)
index 35da6b5a81129c0e42674651f916dc1dd860e2f7..d5bd3fe75e58de468f7680f2138dc96d112b5f89 100644 (file)
@@ -28,8 +28,6 @@ import dns.rdataset
 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."""
@@ -172,7 +170,7 @@ def make_ds(name, key, algorithm, origin=None):
     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))
@@ -292,7 +290,7 @@ def _validate_rrsig(rrset, rrsig, keys, origin=None, now=None):
     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)
@@ -443,7 +441,7 @@ def _validate(rrset, rrsigset, keys, origin=None, now=None):
     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):
index 758c47a78474d4c2f22b76809fb30bbf81c9a82f..ab14041d699698cd8b0a62c47f59ed5df0ef7b72 100644 (file)
@@ -20,7 +20,6 @@
 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.')
@@ -75,7 +74,7 @@ def to_e164(name, origin=public_enum_domain, want_plus_prefix=True):
     text = b''.join(dlabels)
     if want_plus_prefix:
         text = b'+' + text
-    return maybe_decode(text)
+    return text.decode()
 
 
 def query(number, domains, resolver=None):
@@ -95,7 +94,7 @@ 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:
index 00c6a4b3894478f6fad975b73272243e2ab0a308..3b4194ec435b6303d9391bd2feaad45b8341ec4d 100644 (file)
@@ -18,7 +18,6 @@
 import os
 import random
 import time
-from ._compat import long, binary_type
 try:
     import threading as _threading
 except ImportError:
@@ -97,7 +96,7 @@ class EntropyPool(object):
         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
@@ -115,11 +114,11 @@ class EntropyPool(object):
 
     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
index c8d7c1b404d38638fcc5ec02aedd4480bbb8ffe9..e7729f2f68a816f6b3c6f8be96953065eb080ad8 100644 (file)
@@ -22,8 +22,6 @@ import socket
 import dns.ipv4
 import dns.ipv6
 
-from ._compat import maybe_ord
-
 # We assume that AF_INET is always defined.
 
 AF_INET = socket.AF_INET
@@ -114,11 +112,11 @@ def is_multicast(text):
     """
 
     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
index 8fc4f7dcfdc9ef113a0b227a803088e5411a1c04..c35775b483d1ba88c9a354c267c31b3e13a3749b 100644 (file)
 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:
@@ -40,12 +39,12 @@ def inet_ntoa(address):
 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:
@@ -57,7 +56,7 @@ def inet_aton(text):
             # 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
index 128e56c8f1414b390222949c8c837343db4dc83c..e501a41a364ec70ff24fbf73ac07894ae4cddb2f 100644 (file)
@@ -22,17 +22,16 @@ import binascii
 
 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:
@@ -42,7 +41,7 @@ def inet_ntoa(address):
     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
@@ -58,7 +57,7 @@ def inet_ntoa(address):
     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
@@ -102,13 +101,13 @@ def inet_aton(text):
 
     *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'::':
@@ -147,7 +146,7 @@ def inet_aton(text):
             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)
@@ -173,7 +172,7 @@ _mapped_prefix = b'\x00' * 10 + b'\xff\xff'
 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``.
     """
index 9d2b2f43c913281acd65faf53a6384e16d26a5c0..a5ed5239e20d9fd424cd4c4464c94476980b6a57 100644 (file)
@@ -38,8 +38,6 @@ import dns.renderer
 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."""
@@ -472,7 +470,7 @@ class Message(object):
         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
@@ -520,7 +518,7 @@ class Message(object):
             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 = []
@@ -561,7 +559,7 @@ class Message(object):
         (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
@@ -617,7 +615,7 @@ class _WireReader(object):
         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)
@@ -645,7 +643,7 @@ class _WireReader(object):
         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
@@ -1041,7 +1039,7 @@ def from_file(f):
     Returns a ``dns.message.Message object``
     """
 
-    str_type = string_types
+    str_type = str
     opts = 'rU'
 
     if isinstance(f, str_type):
@@ -1099,11 +1097,11 @@ def make_query(qname, rdtype, rdclass=dns.rdataclass.IN, use_edns=None,
     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
index 0bcfd8343287c0463f0514e63cdbe078514e70b7..10167435d3a3976f7ac114703b66c9ba1bb45414 100644 (file)
@@ -32,8 +32,6 @@ except ImportError:
 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:
@@ -122,7 +120,7 @@ class IDNACodec(object):
             except Exception as e:
                 raise IDNAException(idna_exception=e)
         else:
-            label = maybe_decode(label)
+            label = label.decode()
         return _escapify(label, True)
 
 
@@ -248,7 +246,7 @@ def _escapify(label, unicode_mode=False):
     @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:
@@ -260,7 +258,7 @@ def _escapify(label, unicode_mode=False):
         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':
@@ -308,9 +306,9 @@ def _maybe_convert_to_binary(label):
 
     """
 
-    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
 
@@ -374,11 +372,11 @@ class Name(object):
         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
@@ -544,15 +542,15 @@ class Name(object):
         """
 
         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.
@@ -813,7 +811,7 @@ def from_unicode(text, origin=root, idna_codec=None):
     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")
@@ -846,7 +844,7 @@ def from_unicode(text, origin=root, idna_codec=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
@@ -885,9 +883,9 @@ def from_text(text, origin=root, idna_codec=None):
     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")
@@ -961,7 +959,7 @@ def from_wire(message, current):
     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 = []
index 37a13104e60198947a209e3f6b4dbf93625522af..f44cf6f9752934fe71fa710bfa56afcfa2aed585 100644 (file)
@@ -29,7 +29,6 @@
 
 import collections
 import dns.name
-from ._compat import xrange
 
 
 class NameDict(collections.MutableMapping):
@@ -100,7 +99,7 @@ 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])
index c0c517ccd45b8d5227bc41c0594df4f8e76f61b4..20c953cb328c78db3764539cee83c39807e84567 100644 (file)
@@ -33,12 +33,6 @@ import dns.message
 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.
@@ -87,7 +81,7 @@ def _poll_for(fd, readable, writable, error, timeout):
     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()
 
@@ -130,7 +124,7 @@ def _wait_for(fd, readable, writable, error, expiration):
         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
@@ -562,9 +556,9 @@ def xfr(where, zone, rdtype=dns.rdatatype.AXFR, rdclass=dns.rdataclass.IN,
     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:
index 5191e1b18c63209df39341eac11e263b3f170fd0..2215bef140dae010d1ae1427171687b1943c5f5b 100644 (file)
@@ -18,7 +18,6 @@
 """DNS Result Codes."""
 
 import dns.exception
-from ._compat import long
 
 #: No error
 NOERROR = 0
@@ -122,7 +121,7 @@ def to_flags(value):
     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)
 
 
index ea1971dc5ff0d68783cf5a9d0f3f80d92867e29a..01930a4f7f684f899256e7796c24b3c80586f7af 100644 (file)
@@ -27,7 +27,6 @@ import dns.rdataclass
 import dns.rdatatype
 import dns.tokenizer
 import dns.wiredata
-from ._compat import xrange, string_types, text_type
 
 try:
     import threading as _threading
@@ -65,7 +64,7 @@ __escaped = bytearray(b'"\\')
 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)
@@ -86,7 +85,7 @@ def _truncate_bitmap(what):
     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]
@@ -370,7 +369,7 @@ def from_text(rdclass, rdtype, tok, origin=None, relativize=True):
     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:
index f1afe24198b3d1a42299b91c7190b9a6a7ba407a..7f4339c0f01aea7d777bf19d8cca354ddc73028c 100644 (file)
@@ -26,7 +26,6 @@ import dns.rdatatype
 import dns.rdataclass
 import dns.rdata
 import dns.set
-from ._compat import string_types
 
 # define SimpleSet here for backwards compatibility
 SimpleSet = dns.set.Set
@@ -297,9 +296,9 @@ def from_text_list(rdclass, rdtype, ttl, text_rdatas):
     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)
index 06292fb28c0ea4cafd4c9f0a05cb5480ed7dae5b..878befac51997e4bb1eed6c6ab1dcff72ba2dcaf 100644 (file)
@@ -21,7 +21,6 @@ import dns.exception
 import dns.rdata
 import dns.rdatatype
 import dns.name
-from dns._compat import xrange
 
 class CSYNC(dns.rdata.Rdata):
 
@@ -46,9 +45,8 @@ 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))
index 422822f03b3a63e685b8c61e99edc762872e0fee..2448420c7c2a5cb8e44ef36d94df6e87934da4e0 100644 (file)
@@ -20,7 +20,6 @@ import struct
 import dns.exception
 import dns.rdata
 import dns.tokenizer
-from dns._compat import long, text_type
 
 
 def _validate_float_string(what):
@@ -38,7 +37,7 @@ def _validate_float_string(what):
 
 
 def _sanitize(value):
-    if isinstance(value, text_type):
+    if isinstance(value, str):
         return value.encode()
     return value
 
@@ -60,16 +59,13 @@ class GPOS(dns.rdata.Rdata):
     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)
index e4e0b34a49f3e8ed5bdb8029cdf71fe5b63c6ed4..7bf8edd3220f25eebf2a8326df7a32bbce7848c4 100644 (file)
@@ -20,7 +20,6 @@ import struct
 import dns.exception
 import dns.rdata
 import dns.tokenizer
-from dns._compat import text_type
 
 
 class HINFO(dns.rdata.Rdata):
@@ -37,11 +36,11 @@ 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
index f5f5f8b9ea46473662cb105be1230fb8efe47013..4d1b8662462f32346367232bd343a48c43bab401 100644 (file)
@@ -20,7 +20,6 @@ import struct
 import dns.exception
 import dns.rdata
 import dns.tokenizer
-from dns._compat import text_type
 
 
 class ISDN(dns.rdata.Rdata):
@@ -37,11 +36,11 @@ 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
index da9bb03a954c42648f0ae75c6140a29c0675ef66..104551312aec0c89b10585bb140c8f65a8b819fe 100644 (file)
@@ -21,10 +21,9 @@ import struct
 
 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
@@ -36,8 +35,8 @@ def _exponent_of(what, desc):
     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:
@@ -51,7 +50,7 @@ def _float_to_tuple(what):
         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)
@@ -71,7 +70,7 @@ def _tuple_to_float(what):
 
 
 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
@@ -84,7 +83,7 @@ def _decode_size(what, desc):
     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):
@@ -122,12 +121,12 @@ 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)
@@ -271,13 +270,13 @@ class LOC(dns.rdata.Rdata):
                         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")
@@ -289,16 +288,16 @@ class LOC(dns.rdata.Rdata):
     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
index 4e3da7296b9a7f0658ed81f7862df5fbf5039001..a138d4d2907302b567e41cd12a155501635a594b 100644 (file)
@@ -21,7 +21,6 @@ import dns.exception
 import dns.rdata
 import dns.rdatatype
 import dns.name
-from dns._compat import xrange
 
 
 class NSEC(dns.rdata.Rdata):
@@ -45,9 +44,8 @@ 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))
index 1c281c4a4d0189e1ec374e295798b4222d07155d..e33cc7c3be92de0f3947f7c8e3ed788007ba4781 100644 (file)
 
 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
 
@@ -71,7 +61,7 @@ class NSEC3(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
@@ -88,9 +78,8 @@ class NSEC3(dns.rdata.Rdata):
         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))
index 87c36e56755f0fc78a5604e01a724987ee40de3f..356fff4620d9ef4546e15138071e017ae4266502 100644 (file)
@@ -20,7 +20,6 @@ import binascii
 
 import dns.exception
 import dns.rdata
-from dns._compat import text_type
 
 
 class NSEC3PARAM(dns.rdata.Rdata):
@@ -43,7 +42,7 @@ 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
index f5b65ed6a9465453225252586ab78c719d9c47dc..4c6569ceec39070279ab7a0a402e6ed2c3f1e048 100644 (file)
@@ -21,7 +21,6 @@ import struct
 import dns.exception
 import dns.rdata
 import dns.name
-from dns._compat import text_type
 
 
 class URI(dns.rdata.Rdata):
@@ -44,7 +43,7 @@ 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
index e530a2c2a673712adfe0814574dfed4b31007181..1323ba4df7c123bff1fed7e4df8f4e51f126ed33 100644 (file)
@@ -20,7 +20,6 @@ import struct
 import dns.exception
 import dns.rdata
 import dns.tokenizer
-from dns._compat import text_type
 
 
 class X25(dns.rdata.Rdata):
@@ -35,7 +34,7 @@ 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
index 48faf88ab7cdc3d2b42cc4233a6d8db3a8156c78..564890861b463e32cd89dbe85484c8b4e8f87ed7 100644 (file)
@@ -23,8 +23,6 @@ import dns.exception
 import dns.inet
 import dns.rdata
 import dns.tokenizer
-from dns._compat import xrange, maybe_chr
-
 
 class APLItem(object):
 
@@ -65,8 +63,8 @@ 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]
index 32fa4745eaaf6f282eaf8b3b4a44452431f0378a..79e5e5f3543cfa24acee6359a3a881bdc3e1b8d9 100644 (file)
@@ -20,7 +20,6 @@ import struct
 import dns.exception
 import dns.name
 import dns.rdata
-from dns._compat import xrange, text_type
 
 
 def _write_string(file, s):
@@ -31,7 +30,7 @@ def _write_string(file, s):
 
 
 def _sanitize(value):
-    if isinstance(value, text_type):
+    if isinstance(value, str):
         return value.encode()
     return value
 
@@ -103,7 +102,7 @@ class NAPTR(dns.rdata.Rdata):
         current += 4
         rdlen -= 4
         strings = []
-        for i in xrange(3):
+        for i in range(3):
             l = wire[current]
             current += 1
             rdlen -= 1
index 96f98ada709c403b5b5227fd8535fbeb5ef4915f..c3a47985c40f9d63220fe1b319f20a04f82c7e2f 100644 (file)
@@ -20,7 +20,6 @@ import struct
 
 import dns.ipv4
 import dns.rdata
-from dns._compat import xrange
 
 _proto_tcp = socket.getprotobyname('tcp')
 _proto_udp = socket.getprotobyname('udp')
@@ -51,9 +50,9 @@ class WKS(dns.rdata.Rdata):
 
     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)
@@ -85,7 +84,7 @@ class WKS(dns.rdata.Rdata):
             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)
index cc5fdaa63beacf091a0b7ed932e7db0f71c8e823..4eaecbf8deb49d879fd36c67c9d81c5e86b4b8e3 100644 (file)
@@ -17,7 +17,6 @@
 import binascii
 
 import dns.rdata
-from dns._compat import xrange
 
 
 class EUIBase(dns.rdata.Rdata):
@@ -50,8 +49,7 @@ 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)
index 645a57ecfcfca38c3cd463879263621e694d6b2b..fd8587135f57d42bf92520bafd949ae7f7a55966 100644 (file)
@@ -22,7 +22,6 @@ import struct
 import dns.exception
 import dns.rdata
 import dns.tokenizer
-from dns._compat import binary_type, string_types
 
 
 class TXTBase(dns.rdata.Rdata):
@@ -37,12 +36,12 @@ 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)
 
@@ -66,7 +65,7 @@ class TXTBase(dns.rdata.Rdata):
             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())
index d7ef8c7f096fa39ccc908686239156dda4457ba7..2325e775d1eb6ba57e8b15067817ef5641999d93 100644 (file)
@@ -24,7 +24,6 @@ import time
 
 import dns.exception
 import dns.tsig
-from ._compat import long
 
 
 QUESTION = 0
@@ -172,7 +171,7 @@ class Renderer(object):
         """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()
index 806e5b2b453e498edb1cd6ed984abceacf0c3e3e..74828bd18839ff98210ec791d796c54135923455 100644 (file)
@@ -21,7 +21,6 @@ import socket
 import sys
 import time
 import random
-
 try:
     import threading as _threading
 except ImportError:
@@ -39,7 +38,6 @@ import dns.rdataclass
 import dns.rdatatype
 import dns.reversename
 import dns.tsig
-from ._compat import xrange, string_types
 
 if sys.platform == 'win32':
     try:
@@ -207,7 +205,7 @@ class Answer(object):
         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)
@@ -573,7 +571,7 @@ class Resolver(object):
         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:
@@ -844,13 +842,13 @@ class Resolver(object):
         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
@@ -1121,7 +1119,7 @@ def zone_for_name(name, rdclass=dns.rdataclass.IN, tcp=False, resolver=None):
     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()
index 8f095fa91ed5e7e7f65bd8e94039a81b0d0248aa..60618cc98c16e8192a914dbc4fbb35887d88bf1d 100644 (file)
@@ -23,8 +23,6 @@ import dns.name
 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.')
 
@@ -44,10 +42,7 @@ def from_address(text):
     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())]
index a53ec324b89568c203aba99c263af3e2fd79fba4..8be433963052ae7c25eb2947b7aa0676ce0f5f74 100644 (file)
@@ -22,7 +22,6 @@ import dns.name
 import dns.rdataset
 import dns.rdataclass
 import dns.renderer
-from ._compat import string_types
 
 
 class RRset(dns.rdataset.Rdataset):
@@ -134,11 +133,11 @@ def from_text_list(name, ttl, rdclass, rdtype, text_rdatas,
     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)
@@ -165,7 +164,7 @@ def from_rdata_list(name, ttl, rdatas, idna_codec=None):
     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:
index 880b71ce7ae907065798660897515d0923400f74..74674a6545f2fdb79250becf2ec723d37e35036c 100644 (file)
@@ -23,7 +23,6 @@ import sys
 import dns.exception
 import dns.name
 import dns.ttl
-from ._compat import long, text_type, binary_type
 
 _DELIMITERS = {
     ' ': True,
@@ -189,11 +188,11 @@ class Tokenizer(object):
         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>'
@@ -497,8 +496,8 @@ class Tokenizer(object):
             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
index 3daa387855b426b33075224962c61ffbf56122f9..2517162064a8c87efe9eb50e9623989c65280473 100644 (file)
@@ -24,7 +24,6 @@ import struct
 import dns.exception
 import dns.rdataclass
 import dns.name
-from ._compat import long, string_types, text_type
 
 class BadTime(dns.exception.DNSException):
 
@@ -97,7 +96,7 @@ def sign(wire, keyname, secret, time, fudge, original_id, error,
     @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:
@@ -113,9 +112,8 @@ def sign(wire, keyname, secret, time, fudge, original_id, error,
         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)
@@ -167,7 +165,7 @@ def validate(wire, keyname, secret, now, request_mac, tsig_start, tsig_rdata,
     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
@@ -209,7 +207,7 @@ def get_algorithm(algorithm):
     @raises NotImplementedError: I{algorithm} is not supported
     """
 
-    if isinstance(algorithm, string_types):
+    if isinstance(algorithm, str):
         algorithm = dns.name.from_text(algorithm)
 
     try:
index 5e5fe1cbe4e99770bfeb1a50f91abf35f16703fe..db8c59faeb4f207255e19cbd44ce81727e1726b5 100644 (file)
@@ -17,8 +17,6 @@
 
 """A place to store TSIG keys."""
 
-from dns._compat import maybe_decode, maybe_encode
-
 import base64
 
 import dns.name
@@ -32,7 +30,7 @@ def from_text(textring):
     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
 
@@ -44,7 +42,7 @@ def to_text(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
index 4be16bee5b5df061b8037d220c526aa05de2e11c..2b1ced0a5dcef3806c4db853e745e70f75bceabc 100644 (file)
@@ -18,7 +18,6 @@
 """DNS TTL conversion."""
 
 import dns.exception
-from ._compat import long
 
 
 class BadTTL(dns.exception.SyntaxError):
@@ -38,26 +37,26 @@ def from_text(text):
     """
 
     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:
@@ -65,6 +64,6 @@ def from_text(text):
                 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
index 96a00d5dbee231755be4ddd795fcf51595d15d6d..9e591ae3fa20e386837afbb17f9ea1bfc152f4ed 100644 (file)
@@ -25,7 +25,6 @@ import dns.rdata
 import dns.rdataclass
 import dns.rdataset
 import dns.tsig
-from ._compat import string_types
 
 
 class Update(dns.message.Message):
@@ -56,10 +55,10 @@ 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,
@@ -93,7 +92,7 @@ class Update(dns.message.Message):
                 - 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:
@@ -111,7 +110,7 @@ class Update(dns.message.Message):
                     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)
@@ -150,7 +149,7 @@ class Update(dns.message.Message):
                 - 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,
@@ -167,7 +166,7 @@ class Update(dns.message.Message):
                     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,
@@ -214,7 +213,7 @@ class Update(dns.message.Message):
                 - 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,
@@ -231,7 +230,7 @@ class Update(dns.message.Message):
             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,
@@ -242,7 +241,7 @@ class Update(dns.message.Message):
         """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,
@@ -250,7 +249,7 @@ class Update(dns.message.Message):
                             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,
index ea3c1e67d6928f439702976c82cf2ed68a83ae97..85412691c07ca7819bbe1c7c7c1e2cec3abb4662 100644 (file)
@@ -18,7 +18,6 @@
 """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
@@ -27,19 +26,15 @@ from ._compat import binary_type, string_types, PY2
 # 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):
@@ -51,24 +46,11 @@ class WireData(binary_type):
                 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)))
@@ -76,10 +58,6 @@ class WireData(binary_type):
         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:
@@ -90,14 +68,14 @@ class WireData(binary_type):
                 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))
index 1e2fe78168e181441c4a2c0d8cd1d42bfaba2197..3da8208b82c05e416a639adff771ee9e3d389109 100644 (file)
@@ -35,7 +35,6 @@ import dns.rrset
 import dns.tokenizer
 import dns.ttl
 import dns.grange
-from ._compat import string_types, text_type, PY3
 
 
 class BadZone(dns.exception.DNSException):
@@ -95,7 +94,7 @@ class Zone(object):
         @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 "
@@ -129,7 +128,7 @@ class Zone(object):
         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")
@@ -157,19 +156,13 @@ class Zone(object):
         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
@@ -265,9 +258,9 @@ class Zone(object):
         """
 
         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)
@@ -328,9 +321,9 @@ class Zone(object):
         """
 
         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:
@@ -391,9 +384,9 @@ class Zone(object):
         """
 
         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)
@@ -447,9 +440,9 @@ class Zone(object):
         @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:
@@ -470,9 +463,9 @@ class Zone(object):
         @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:
@@ -499,7 +492,7 @@ class Zone(object):
         @type nl: string or None
         """
 
-        if isinstance(f, string_types):
+        if isinstance(f, str):
             f = open(f, 'wb')
             want_close = True
         else:
@@ -514,7 +507,7 @@ class Zone(object):
         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
@@ -529,7 +522,7 @@ class Zone(object):
             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
@@ -619,7 +612,7 @@ class _MasterReader(object):
 
     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
@@ -1060,16 +1053,10 @@ def from_file(f, origin=None, rdclass=dns.rdataclass.IN,
     @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:
index 592e5b87aab0837d2a78052af2ae70a4cff215f6..e06e9c64e724298de78558da2c1646380944fab1 100644 (file)
@@ -26,8 +26,6 @@ import dns.rdataclass
 import dns.rdatatype
 import dns.rrset
 import dns.zone
-from dns._compat import long
-
 import pprint
 
 
@@ -237,42 +235,42 @@ class GenerateTestCase(unittest.TestCase):
         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)
@@ -283,39 +281,39 @@ class GenerateTestCase(unittest.TestCase):
         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)
@@ -327,38 +325,38 @@ class GenerateTestCase(unittest.TestCase):
         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)
@@ -369,39 +367,39 @@ class GenerateTestCase(unittest.TestCase):
         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)
@@ -412,46 +410,46 @@ class GenerateTestCase(unittest.TestCase):
         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)
@@ -462,35 +460,35 @@ class GenerateTestCase(unittest.TestCase):
         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'))]
 
index a6f39a2832a9254b04460525af50250451cf5aa1..d60e711c5b0fc80e7a6de69a14d09009745522c8 100644 (file)
@@ -24,7 +24,6 @@ import dns.message
 import dns.name
 import dns.rdataclass
 import dns.rdatatype
-from dns._compat import xrange
 
 query_text = """id 1234
 opcode QUERY
@@ -136,7 +135,7 @@ class MessageTestCase(unittest.TestCase):
     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,
index 1738c1a3668d5fd7d5b7d460e532b2244d0d89ec..b36992cb0b03d4d027431c4f7c855f6680cb9314 100644 (file)
@@ -27,7 +27,6 @@ import dns.name
 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.
@@ -182,11 +181,11 @@ class BaseResolverTests(unittest.TestCase):
 
     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,
@@ -199,7 +198,7 @@ class BaseResolverTests(unittest.TestCase):
 
     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)
@@ -209,7 +208,7 @@ class BaseResolverTests(unittest.TestCase):
         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,
@@ -222,12 +221,12 @@ class BaseResolverTests(unittest.TestCase):
 
     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))
@@ -283,9 +282,6 @@ class NXDOMAINExceptionTestCase(unittest.TestCase):
         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))
@@ -295,9 +291,6 @@ class NXDOMAINExceptionTestCase(unittest.TestCase):
         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))
@@ -307,9 +300,6 @@ class NXDOMAINExceptionTestCase(unittest.TestCase):
         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))
@@ -335,9 +325,6 @@ class NXDOMAINExceptionTestCase(unittest.TestCase):
             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))
@@ -352,9 +339,6 @@ class NXDOMAINExceptionTestCase(unittest.TestCase):
             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))
@@ -372,9 +356,6 @@ class NXDOMAINExceptionTestCase(unittest.TestCase):
             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))