]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
create exceptions with arguments as "raise E(args)" instead of "raise E, args"
authorBob Halley <halley@nominum.com>
Thu, 14 Jan 2010 22:51:06 +0000 (14:51 -0800)
committerBob Halley <halley@nominum.com>
Thu, 14 Jan 2010 22:51:06 +0000 (14:51 -0800)
31 files changed:
dns/e164.py
dns/entropy.py
dns/ipv6.py
dns/message.py
dns/name.py
dns/namedict.py
dns/query.py
dns/rcode.py
dns/rdata.py
dns/rdataclass.py
dns/rdataset.py
dns/rdatatype.py
dns/rdtypes/ANY/CERT.py
dns/rdtypes/ANY/HIP.py
dns/rdtypes/ANY/LOC.py
dns/rdtypes/ANY/NSEC.py
dns/rdtypes/ANY/NSEC3.py
dns/rdtypes/ANY/NXT.py
dns/rdtypes/IN/IPSECKEY.py
dns/rdtypes/IN/NSAP.py
dns/rdtypes/IN/WKS.py
dns/rdtypes/keybase.py
dns/rdtypes/txtbase.py
dns/resolver.py
dns/reversename.py
dns/rrset.py
dns/set.py
dns/tokenizer.py
dns/tsig.py
dns/ttl.py
dns/zone.py

index 214fcaae9dfbf1271844c9efc022d8ec671f9d06..d8f71ec7999513e76cc5ca9a5eea055b61fbbf91 100644 (file)
@@ -54,7 +54,7 @@ def to_e164(name, origin=public_enum_domain, want_plus_prefix=True):
         name = name.relativize(origin)
     dlabels = [d for d in name.labels if (d.isdigit() and len(d) == 1)]
     if len(dlabels) != len(name.labels):
-        raise dns.exception.SyntaxError, 'non-digit labels in ENUM domain name'
+        raise dns.exception.SyntaxError('non-digit labels in ENUM domain name')
     dlabels.reverse()
     text = ''.join(dlabels)
     if want_plus_prefix:
index 9e10d126cc38419850a600969d0666ea6a380a4c..fd9d4f8cdf8ce5e1f5cc122e3dda67ef6cc2245b 100644 (file)
@@ -102,7 +102,7 @@ class EntropyPool(object):
     def random_between(self, first, last):
         size = last - first + 1
         if size > 4294967296L:
-            raise ValueError, 'too big'
+            raise ValueError('too big')
         if size > 65536:
             rand = self.random_32
             max = 4294967295L
index ec25ba2738249eaed68247869d038172fdf45d00..33c6713796d0ab2c43fb1425237ddebe62b73295 100644 (file)
@@ -32,7 +32,7 @@ def inet_ntoa(address):
     """
 
     if len(address) != 16:
-        raise ValueError, "IPv6 addresses are 16 bytes long"
+        raise ValueError("IPv6 addresses are 16 bytes long")
     hex = address.encode('hex_codec')
     chunks = []
     i = 0
@@ -95,13 +95,13 @@ _colon_colon_end = re.compile(r'.*::$')
 
 def inet_aton(text):
     """Convert a text format IPv6 address into network format.
-    
+
     @param text: the textual address
     @type text: string
     @rtype: string
     @raises dns.exception.SyntaxError: the text was not properly formatted
     """
-    
+
     #
     # Our aim here is not something fast; we just want something that works.
     #
index f74d1218aa3a01311ead3239651e9f1d8226e49d..ba0ebf65f14c7b8966fda39e35462b838f29c2be 100644 (file)
@@ -290,7 +290,7 @@ class Message(object):
         elif section is self.additional:
             return 3
         else:
-            raise ValueError, 'unknown section'
+            raise ValueError('unknown section')
 
     def find_rrset(self, section, name, rdclass, rdtype,
                    covers=dns.rdatatype.NONE, deleting=None, create=False,
@@ -653,10 +653,10 @@ class _WireReader(object):
                         i == (count - 1)):
                     raise BadTSIG
                 if self.message.keyring is None:
-                    raise UnknownTSIGKey, 'got signed message without keyring'
+                    raise UnknownTSIGKey('got signed message without keyring')
                 secret = self.message.keyring.get(absolute_name)
                 if secret is None:
-                    raise UnknownTSIGKey, "key '%s' unknown" % name
+                    raise UnknownTSIGKey("key '%s' unknown" % name)
                 self.message.tsig_ctx = \
                                       dns.tsig.validate(self.wire,
                                           absolute_name,
@@ -1067,7 +1067,7 @@ def make_response(query, recursion_available=False, our_payload=8192):
     @rtype: dns.message.Message object"""
 
     if query.flags & dns.flags.QR:
-        raise dns.exception.FormError, 'specified query message is not a query'
+        raise dns.exception.FormError('specified query message is not a query')
     response = dns.message.Message(query.id)
     response.flags = dns.flags.QR | (query.flags & dns.flags.RD)
     if recursion_available:
index bee61d3b278f8e25da8f2477ce4471180888be6a..f239c9b5de20eb9dccefeb7be01dea15e0431008 100644 (file)
@@ -107,7 +107,7 @@ def _validate_labels(labels):
     @raises LabelTooLong: an individual label is too long
     @raises EmptyLabel: a label is empty (i.e. the root label) and appears
     in a position other than the end of the label sequence"""
-    
+
     l = len(labels)
     total = 0
     i = -1
@@ -130,43 +130,43 @@ class Name(object):
 
     The dns.name.Name class represents a DNS name as a tuple of labels.
     Instances of the class are immutable.
-    
+
     @ivar labels: The tuple of labels in the name. Each label is a string of
     up to 63 octets."""
 
     __slots__ = ['labels']
-    
+
     def __init__(self, labels):
         """Initialize a domain name from a list of labels.
         @param labels: the labels
         @type labels: any iterable whose values are strings
         """
-        
+
         super(Name, self).__setattr__('labels', tuple(labels))
         _validate_labels(self.labels)
 
     def __setattr__(self, name, value):
-        raise TypeError, "object doesn't support attribute assignment"
+        raise TypeError("object doesn't support attribute assignment")
 
     def is_absolute(self):
         """Is the most significant label of this name the root label?
         @rtype: bool
         """
-        
+
         return len(self.labels) > 0 and self.labels[-1] == ''
 
     def is_wild(self):
         """Is this name wild?  (I.e. Is the least significant label '*'?)
         @rtype: bool
         """
-        
+
         return len(self.labels) > 0 and self.labels[0] == '*'
 
     def __hash__(self):
         """Return a case-insensitive hash of the name.
         @rtype: int
         """
-        
+
         h = 0L
         for label in self.labels:
             for c in label:
@@ -185,7 +185,7 @@ class Name(object):
         0 if self == other.  A relative name is always less than an
         absolute name.  If both names have the same relativity, then
         the DNSSEC order relation is used to order them.
-        
+
         I{nlabels} is the number of significant labels that the two names
         have in common.
         """
@@ -240,7 +240,7 @@ class Name(object):
         The notion of subdomain includes equality.
         @rtype: bool
         """
-        
+
         (nr, o, nl) = self.fullcompare(other)
         if nr == NAMERELN_SUBDOMAIN or nr == NAMERELN_EQUAL:
             return True
@@ -252,7 +252,7 @@ class Name(object):
         The notion of subdomain includes equality.
         @rtype: bool
         """
-        
+
         (nr, o, nl) = self.fullcompare(other)
         if nr == NAMERELN_SUPERDOMAIN or nr == NAMERELN_EQUAL:
             return True
@@ -263,7 +263,7 @@ class Name(object):
         DNSSEC canonical form.
         @rtype: dns.name.Name object
         """
-        
+
         return Name([x.lower() for x in self.labels])
 
     def __eq__(self, other):
@@ -304,7 +304,7 @@ class Name(object):
 
     def __repr__(self):
         return '<DNS name ' + self.__str__() + '>'
-    
+
     def __str__(self):
         return self.to_text(False)
 
@@ -314,7 +314,7 @@ class Name(object):
         root label) for absolute names.  The default is False.
         @rtype: string
         """
-        
+
         if len(self.labels) == 0:
             return '@'
         if len(self.labels) == 1 and self.labels[0] == '':
@@ -335,7 +335,7 @@ class Name(object):
         root label) for absolute names.  The default is False.
         @rtype: string
         """
-        
+
         if len(self.labels) == 0:
             return u'@'
         if len(self.labels) == 1 and self.labels[0] == '':
@@ -351,7 +351,7 @@ class Name(object):
         """Convert name to a format suitable for digesting in hashes.
 
         The name is canonicalized and converted to uncompressed wire format.
-        
+
         @param origin: If the name is relative and origin is not None, then
         origin will be appended to it.
         @type origin: dns.name.Name object
@@ -360,7 +360,7 @@ class Name(object):
         if it is missing, then this exception is raised
         @rtype: string
         """
-        
+
         if not self.is_absolute():
             if origin is None or not origin.is_absolute():
                 raise NeedAbsoluteNameOrOrigin
@@ -370,7 +370,7 @@ class Name(object):
             labels = self.labels
         dlabels = ["%s%s" % (chr(len(x)), x.lower()) for x in labels]
         return ''.join(dlabels)
-        
+
     def to_wire(self, file = None, compress = None, origin = None):
         """Convert name to wire format, possibly compressing it.
 
@@ -431,7 +431,7 @@ class Name(object):
         """The length of the name (in labels).
         @rtype: int
         """
-        
+
         return len(self.labels)
 
     def __getitem__(self, index):
@@ -456,15 +456,14 @@ class Name(object):
         @returns: the tuple (prefix, suffix)
         @rtype: tuple
         """
-        
+
         l = len(self.labels)
         if depth == 0:
             return (self, dns.name.empty)
         elif depth == l:
             return (dns.name.empty, self)
         elif depth < 0 or depth > l:
-            raise ValueError, \
-                  'depth must be >= 0 and <= the length of the name'
+            raise ValueError('depth must be >= 0 and <= the length of the name')
         return (Name(self[: -depth]), Name(self[-depth :]))
 
     def concatenate(self, other):
@@ -473,7 +472,7 @@ class Name(object):
         @raises AbsoluteConcatenation: self is absolute and other is
         not the empty name
         """
-        
+
         if self.is_absolute() and len(other) > 0:
             raise AbsoluteConcatenation
         labels = list(self.labels)
@@ -485,7 +484,7 @@ class Name(object):
         relative to origin.  Otherwise return self.
         @rtype: dns.name.Name object
         """
-        
+
         if not origin is None and self.is_subdomain(origin):
             return Name(self[: -len(origin)])
         else:
@@ -496,7 +495,7 @@ class Name(object):
         concatenation of self and origin.  Otherwise return self.
         @rtype: dns.name.Name object
         """
-        
+
         if not self.is_absolute():
             return self.concatenate(origin)
         else:
@@ -509,7 +508,7 @@ class Name(object):
         false the name is derelativized.
         @rtype: dns.name.Name object
         """
-        
+
         if origin:
             if relativize:
                 return self.relativize(origin)
@@ -527,7 +526,7 @@ class Name(object):
         if self == root or self == empty:
             raise NoParent
         return Name(self.labels[1:])
-        
+
 root = Name([''])
 empty = Name([])
 
@@ -535,14 +534,14 @@ def from_unicode(text, origin = root):
     """Convert unicode text into a Name object.
 
     Lables are encoded in IDN ACE form.
-    
+
     @rtype: dns.name.Name object
     """
 
     if not isinstance(text, unicode):
-        raise ValueError, "input to from_unicode() must be a unicode string"
+        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"
+        raise ValueError("origin must be a Name or None")
     labels = []
     label = u''
     escaping = False
@@ -602,9 +601,9 @@ def from_text(text, origin = root):
         if isinstance(text, unicode) and sys.hexversion >= 0x02030000:
             return from_unicode(text, origin)
         else:
-            raise ValueError, "input to from_text() must be a string"
+            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"
+        raise ValueError("origin must be a Name or None")
     labels = []
     label = ''
     escaping = False
@@ -670,7 +669,7 @@ def from_wire(message, current):
     """
 
     if not isinstance(message, str):
-        raise ValueError, "input to from_wire() must be a byte string"
+        raise ValueError("input to from_wire() must be a byte string")
     labels = []
     biggest_pointer = current
     hops = 0
index fa646f2141ac1926342d973796e69909e272aeea..54afb77188890e3defa64e127c8df9b28aaa135e 100644 (file)
@@ -31,7 +31,7 @@ class NameDict(dict):
 
     def __setitem__(self, key, value):
         if not isinstance(key, dns.name.Name):
-            raise ValueError, 'NameDict key must be a name'
+            raise ValueError('NameDict key must be a name')
         depth = len(key)
         if depth > self.max_depth:
             self.max_depth = depth
@@ -39,7 +39,7 @@ class NameDict(dict):
 
     def get_deepest_match(self, name):
         """Find the deepest match to I{name} in the dictionary.
-        
+
         The deepest match is the longest name in the dictionary which is
         a superdomain of I{name}.
 
@@ -47,7 +47,7 @@ class NameDict(dict):
         @type name: dns.name.Name object
         @rtype: (key, value) tuple
         """
-        
+
         depth = len(name)
         if depth > self.max_depth:
             depth = self.max_depth
index a907df0e894dac3f0ca38bdccad4889b0e673b2e..c023b140aff67d1d0748c87718849ebc7076d7e5 100644 (file)
@@ -140,9 +140,9 @@ def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0,
                          from_address[1:] == destination[1:]):
                 break
             if not ignore_unexpected:
-                raise UnexpectedSource, \
-                      'got a response from %s instead of %s' % (from_address,
-                                                                destination)
+                raise UnexpectedSource('got a response from '
+                                       '%s instead of %s' % (from_address,
+                                                             destination))
     finally:
         s.close()
     r = dns.message.from_wire(wire, keyring=q.keyring, request_mac=q.mac,
@@ -186,7 +186,7 @@ def _connect(s, address):
         if v[0] != errno.EINPROGRESS and \
                v[0] != errno.EWOULDBLOCK and \
                v[0] != errno.EALREADY:
-            raise ty, v
+            raise v
 
 def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0,
         one_rr_per_rrset=False):
@@ -335,7 +335,7 @@ def xfr(where, zone, rdtype=dns.rdatatype.AXFR, rdclass=dns.rdataclass.IN,
             source = (source, source_port, 0, 0)
     if use_udp:
         if rdtype != dns.rdatatype.IXFR:
-            raise ValueError, 'cannot do a UDP AXFR'
+            raise ValueError('cannot do a UDP AXFR')
         s = socket.socket(af, socket.SOCK_DGRAM, 0)
     else:
         s = socket.socket(af, socket.SOCK_STREAM, 0)
@@ -387,7 +387,7 @@ def xfr(where, zone, rdtype=dns.rdatatype.AXFR, rdclass=dns.rdataclass.IN,
                 raise dns.exception.FormError
             rrset = r.answer[0]
             if rrset.rdtype != dns.rdatatype.SOA:
-                raise dns.exception.FormError, "first RRset is not an SOA"
+                raise dns.exception.FormError("first RRset is not an SOA")
             answer_index = 1
             soa_rrset = rrset.copy()
             if rdtype == dns.rdatatype.IXFR:
@@ -404,12 +404,11 @@ def xfr(where, zone, rdtype=dns.rdatatype.AXFR, rdclass=dns.rdataclass.IN,
         #
         for rrset in r.answer[answer_index:]:
             if done:
-                raise dns.exception.FormError, "answers after final SOA"
+                raise dns.exception.FormError("answers after final SOA")
             if rrset.rdtype == dns.rdatatype.SOA and rrset.name == oname:
                 if expecting_SOA:
                     if rrset[0].serial != serial:
-                        raise dns.exception.FormError, \
-                              "IXFR base serial mismatch"
+                        raise dns.exception.FormError("IXFR base serial mismatch")
                     expecting_SOA = False
                 elif rdtype == dns.rdatatype.IXFR:
                     delete_mode = not delete_mode
@@ -424,6 +423,6 @@ def xfr(where, zone, rdtype=dns.rdatatype.AXFR, rdclass=dns.rdataclass.IN,
                 rdtype = dns.rdatatype.AXFR
                 expecting_SOA = False
         if done and q.keyring and not r.had_tsig:
-            raise dns.exception.FormError, "missing TSIG"
+            raise dns.exception.FormError("missing TSIG")
         yield r
     s.close()
index e8f1ee42f7fee5cc6b6aeb02b2647f090fa93d9f..c055f2e7cd29c211d3c02a551b060e10e14c830d 100644 (file)
@@ -58,7 +58,7 @@ class UnknownRcode(dns.exception.DNSException):
 
 def from_text(text):
     """Convert text into an rcode.
-    
+
     @param text: the texual rcode
     @type text: string
     @raises UnknownRcode: the rcode is unknown
@@ -87,7 +87,7 @@ def from_flags(flags, ednsflags):
 
     value = (flags & 0x000f) | ((ednsflags >> 20) & 0xff0)
     if value < 0 or value > 4095:
-        raise ValueError, 'rcode must be >= 0 and <= 4095'
+        raise ValueError('rcode must be >= 0 and <= 4095')
     return value
 
 def to_flags(value):
@@ -100,7 +100,7 @@ def to_flags(value):
     """
 
     if value < 0 or value > 4095:
-        raise ValueError, 'rcode must be >= 0 and <= 4095'
+        raise ValueError('rcode must be >= 0 and <= 4095')
     v = value & 0xf
     ev = long(value & 0xff0) << 20
     return (v, ev)
@@ -112,7 +112,7 @@ def to_text(value):
     @type value: int
     @rtype: string
     """
-    
+
     text = _by_value.get(value)
     if text is None:
         text = str(value)
index 1bed9a16c19c0d41399d07071a3467ef0675ae32..ce0268697b0aa5c7e03024c959d23b9257c77cd6 100644 (file)
@@ -321,8 +321,7 @@ class GenericRdata(Rdata):
     def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
         token = tok.get()
         if not token.is_identifier() or token.value != '\#':
-            raise dns.exception.SyntaxError, \
-                  r'generic rdata does not start with \#'
+            raise dns.exception.SyntaxError(r'generic rdata does not start with \#')
         length = tok.get_int()
         chunks = []
         while 1:
@@ -333,8 +332,7 @@ class GenericRdata(Rdata):
         hex = ''.join(chunks)
         data = hex.decode('hex_codec')
         if len(data) != length:
-            raise dns.exception.SyntaxError, \
-                  'generic rdata hex data has wrong length'
+            raise dns.exception.SyntaxError('generic rdata hex data has wrong length')
         return cls(rdclass, rdtype, data)
 
     from_text = classmethod(from_text)
index 278f378d35ed85321e6d5780cfe867dbaae78b14..887fd1ad6b91462c91e98048c35eaf17b6d89c53 100644 (file)
@@ -77,7 +77,7 @@ def from_text(text):
     @raises dns.rdataclass.UnknownRdataClass: the class is unknown
     @raises ValueError: the rdata class value is not >= 0 and <= 65535
     """
-    
+
     value = _by_text.get(text.upper())
     if value is None:
         match = _unknown_class_pattern.match(text)
@@ -85,7 +85,7 @@ def from_text(text):
             raise UnknownRdataclass
         value = int(match.group(1))
         if value < 0 or value > 65535:
-            raise ValueError, "class must be between >= 0 and <= 65535"
+            raise ValueError("class must be between >= 0 and <= 65535")
     return value
 
 def to_text(value):
@@ -97,7 +97,7 @@ def to_text(value):
     """
 
     if value < 0 or value > 65535:
-        raise ValueError, "class must be between >= 0 and <= 65535"
+        raise ValueError("class must be between >= 0 and <= 65535")
     text = _by_value.get(value)
     if text is None:
         text = 'CLASS' + `value`
@@ -108,7 +108,7 @@ def is_metaclass(rdclass):
     @param rdclass: the rdata class
     @type rdclass: int
     @rtype: bool"""
-    
+
     if _metaclasses.has_key(rdclass):
         return True
     return False
index 2aa51679a9c5a137eecb491cf5d669c8d6ddddd0..0af018bab5c0e715cede89f7fc7ab794e7faea9c 100644 (file)
@@ -58,13 +58,13 @@ class Rdataset(dns.set.Set):
     """
 
     __slots__ = ['rdclass', 'rdtype', 'covers', 'ttl']
-    
+
     def __init__(self, rdclass, rdtype, covers=dns.rdatatype.NONE):
         """Create a new rdataset of the specified class and type.
 
         @see: the description of the class instance variables for the
         meaning of I{rdclass} and I{rdtype}"""
-        
+
         super(Rdataset, self).__init__()
         self.rdclass = rdclass
         self.rdtype = rdtype
@@ -85,7 +85,7 @@ class Rdataset(dns.set.Set):
         to the specified TTL.
         @param ttl: The TTL
         @type ttl: int"""
-        
+
         if len(self) == 0:
             self.ttl = ttl
         elif ttl < self.ttl:
@@ -96,12 +96,12 @@ class Rdataset(dns.set.Set):
 
         If the optional I{ttl} parameter is supplied, then
         self.update_ttl(ttl) will be called prior to adding the rdata.
-        
+
         @param rd: The rdata
         @type rd: dns.rdata.Rdata object
         @param ttl: The TTL
         @type ttl: int"""
-        
+
         #
         # If we're adding a signature, do some special handling to
         # check that the signature covers the same type as the
@@ -136,7 +136,7 @@ class Rdataset(dns.set.Set):
 
         @param other: The rdataset from which to update
         @type other: dns.rdataset.Rdataset object"""
-        
+
         self.update_ttl(other.ttl)
         super(Rdataset, self).update(other)
 
@@ -147,7 +147,7 @@ class Rdataset(dns.set.Set):
             ctext = '(' + dns.rdatatype.to_text(self.covers) + ')'
         return '<DNS ' + dns.rdataclass.to_text(self.rdclass) + ' ' + \
                dns.rdatatype.to_text(self.rdtype) + ctext + ' rdataset>'
-    
+
     def __str__(self):
         return self.to_text()
 
@@ -155,7 +155,7 @@ class Rdataset(dns.set.Set):
         """Two rdatasets are equal if they have the same class, type, and
         covers, and contain the same rdata.
         @rtype: bool"""
-        
+
         if not isinstance(other, Rdataset):
             return False
         if self.rdclass != other.rdclass or \
@@ -163,7 +163,7 @@ class Rdataset(dns.set.Set):
            self.covers != other.covers:
             return False
         return super(Rdataset, self).__eq__(other)
-    
+
     def __ne__(self, other):
         return not self.__eq__(other)
 
@@ -177,7 +177,7 @@ class Rdataset(dns.set.Set):
 
         Any additional keyword arguments are passed on to the rdata
         to_text() method.
-        
+
         @param name: If name is not None, emit a RRs with I{name} as
         the owner name.
         @type name: dns.name.Name object
@@ -264,7 +264,7 @@ class Rdataset(dns.set.Set):
                 file.write(stuff)
                 file.seek(0, 2)
             return len(self)
-    
+
     def match(self, rdclass, rdtype, covers):
         """Returns True if this rdataset matches the specified class, type,
         and covers"""
@@ -291,11 +291,11 @@ def from_text_list(rdclass, rdtype, ttl, text_rdatas):
         rd = dns.rdata.from_text(r.rdclass, r.rdtype, t)
         r.add(rd)
     return r
-    
+
 def from_text(rdclass, rdtype, ttl, *text_rdatas):
     """Create an rdataset with the specified class, type, and TTL, and with
     the specified rdatas in text format.
-    
+
     @rtype: dns.rdataset.Rdataset object
     """
 
@@ -304,12 +304,12 @@ def from_text(rdclass, rdtype, ttl, *text_rdatas):
 def from_rdata_list(ttl, rdatas):
     """Create an rdataset with the specified TTL, and with
     the specified list of rdata objects.
-    
+
     @rtype: dns.rdataset.Rdataset object
     """
 
     if len(rdatas) == 0:
-        raise ValueError, "rdata list must not be empty"
+        raise ValueError("rdata list must not be empty")
     r = None
     for rd in rdatas:
         if r is None:
@@ -318,11 +318,11 @@ def from_rdata_list(ttl, rdatas):
             first_time = False
         r.add(rd)
     return r
-    
+
 def from_rdata(ttl, *rdatas):
     """Create an rdataset with the specified TTL, and with
     the specified rdata objects.
-    
+
     @rtype: dns.rdataset.Rdataset object
     """
 
index c54c14edf50a9092b694445c7b190ff9311cc10d..1a02b7d3cd9598b4b8dece53545e53909957d3be 100644 (file)
@@ -194,7 +194,7 @@ def from_text(text):
             raise UnknownRdatatype
         value = int(match.group(1))
         if value < 0 or value > 65535:
-            raise ValueError, "type must be between >= 0 and <= 65535"
+            raise ValueError("type must be between >= 0 and <= 65535")
     return value
 
 def to_text(value):
@@ -205,7 +205,7 @@ def to_text(value):
     @rtype: string"""
 
     if value < 0 or value > 65535:
-        raise ValueError, "type must be between >= 0 and <= 65535"
+        raise ValueError("type must be between >= 0 and <= 65535")
     text = _by_value.get(value)
     if text is None:
         text = 'TYPE' + `value`
index fda7ae025931de177e1fe2da35e46fe673ea2d41..d2703519d5f842325f02e02f57a4963e1920b715 100644 (file)
@@ -83,7 +83,7 @@ class CERT(dns.rdata.Rdata):
         key_tag = tok.get_uint16()
         algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
         if algorithm < 0 or algorithm > 255:
-            raise dns.exception.SyntaxError, "bad algorithm type"
+            raise dns.exception.SyntaxError("bad algorithm type")
         chunks = []
         while 1:
             t = tok.get().unescape()
index 93d085bcc48b455cec21511184c43894e2abceff..8f96ae93d640cc8dbd4a699a494fa94c8c6b902d 100644 (file)
@@ -58,7 +58,7 @@ class HIP(dns.rdata.Rdata):
         algorithm = tok.get_uint8()
         hit = tok.get_string().decode('hex-codec')
         if len(hit) > 255:
-            raise dns.exception.SyntaxError, "HIT too long"
+            raise dns.exception.SyntaxError("HIT too long")
         key = tok.get_string().decode('base64-codec')
         servers = []
         while 1:
index 53780fb3d633c632a409f4bbb7bbfe0e8c86fffc..518dd6010f7c6d7a3084fd2e2c65022af918b2c0 100644 (file)
@@ -29,7 +29,7 @@ def _exponent_of(what, desc):
             exp = i - 1
             break
     if exp is None or exp < 0:
-        raise dns.exception.SyntaxError, "%s value out of bounds" % desc
+        raise dns.exception.SyntaxError("%s value out of bounds" % desc)
     return exp
 
 def _float_to_tuple(what):
@@ -69,10 +69,10 @@ def _encode_size(what, desc):
 def _decode_size(what, desc):
     exponent = what & 0x0F
     if exponent > 9:
-        raise dns.exception.SyntaxError, "bad %s exponent" % desc
+        raise dns.exception.SyntaxError("bad %s exponent" % desc)
     base = (what & 0xF0) >> 4
     if base > 9:
-        raise dns.exception.SyntaxError, "bad %s base" % desc
+        raise dns.exception.SyntaxError("bad %s base" % desc)
     return long(base) * pow(10, exponent)
 
 class LOC(dns.rdata.Rdata):
@@ -164,16 +164,13 @@ class LOC(dns.rdata.Rdata):
             if '.' in t:
                 (seconds, milliseconds) = t.split('.')
                 if not seconds.isdigit():
-                    raise dns.exception.SyntaxError, \
-                          'bad latitude seconds value'
+                    raise dns.exception.SyntaxError('bad latitude seconds value')
                 latitude[2] = int(seconds)
                 if latitude[2] >= 60:
-                    raise dns.exception.SyntaxError, \
-                          'latitude seconds >= 60'
+                    raise dns.exception.SyntaxError('latitude seconds >= 60')
                 l = len(milliseconds)
                 if l == 0 or l > 3 or not milliseconds.isdigit():
-                    raise dns.exception.SyntaxError, \
-                          'bad latitude milliseconds value'
+                    raise dns.exception.SyntaxError('bad latitude milliseconds value')
                 if l == 1:
                     m = 100
                 elif l == 2:
@@ -188,7 +185,7 @@ class LOC(dns.rdata.Rdata):
         if t == 'S':
             latitude[0] *= -1
         elif t != 'N':
-            raise dns.exception.SyntaxError, 'bad latitude hemisphere value'
+            raise dns.exception.SyntaxError('bad latitude hemisphere value')
 
         longitude[0] = tok.get_int()
         t = tok.get_string()
@@ -198,16 +195,13 @@ class LOC(dns.rdata.Rdata):
             if '.' in t:
                 (seconds, milliseconds) = t.split('.')
                 if not seconds.isdigit():
-                    raise dns.exception.SyntaxError, \
-                          'bad longitude seconds value'
+                    raise dns.exception.SyntaxError('bad longitude seconds value')
                 longitude[2] = int(seconds)
                 if longitude[2] >= 60:
-                    raise dns.exception.SyntaxError, \
-                          'longitude seconds >= 60'
+                    raise dns.exception.SyntaxError('longitude seconds >= 60')
                 l = len(milliseconds)
                 if l == 0 or l > 3 or not milliseconds.isdigit():
-                    raise dns.exception.SyntaxError, \
-                          'bad longitude milliseconds value'
+                    raise dns.exception.SyntaxError('bad longitude milliseconds value')
                 if l == 1:
                     m = 100
                 elif l == 2:
@@ -222,7 +216,7 @@ class LOC(dns.rdata.Rdata):
         if t == 'W':
             longitude[0] *= -1
         elif t != 'E':
-            raise dns.exception.SyntaxError, 'bad longitude hemisphere value'
+            raise dns.exception.SyntaxError('bad longitude hemisphere value')
 
         t = tok.get_string()
         if t[-1] == 'm':
@@ -293,13 +287,13 @@ class LOC(dns.rdata.Rdata):
         else:
             latitude = -1 * float(0x80000000L - latitude) / 3600000
         if latitude < -90.0 or latitude > 90.0:
-            raise dns.exception.FormError, "bad latitude"
+            raise dns.exception.FormError("bad latitude")
         if longitude > 0x80000000L:
             longitude = float(longitude - 0x80000000L) / 3600000
         else:
             longitude = -1 * float(0x80000000L - longitude) / 3600000
         if longitude < -180.0 or longitude > 180.0:
-            raise dns.exception.FormError, "bad longitude"
+            raise dns.exception.FormError("bad longitude")
         altitude = float(altitude) - 10000000.0
         size = _decode_size(size, "size")
         hprec = _decode_size(hprec, "horizontal precision")
index 415f94a6f869be89087c5899130519898e88a88a..72859ce108a883a0bcbcc4fd8ae185d7aea433f3 100644 (file)
@@ -59,9 +59,9 @@ class NSEC(dns.rdata.Rdata):
                 break
             nrdtype = dns.rdatatype.from_text(token.value)
             if nrdtype == 0:
-                raise dns.exception.SyntaxError, "NSEC with bit 0"
+                raise dns.exception.SyntaxError("NSEC with bit 0")
             if nrdtype > 65535:
-                raise dns.exception.SyntaxError, "NSEC with bit > 65535"
+                raise dns.exception.SyntaxError("NSEC with bit > 65535")
             rdtypes.append(nrdtype)
         rdtypes.sort()
         window = 0
@@ -102,15 +102,15 @@ class NSEC(dns.rdata.Rdata):
         windows = []
         while rdlen > 0:
             if rdlen < 3:
-                raise dns.exception.FormError, "NSEC too short"
+                raise dns.exception.FormError("NSEC too short")
             window = ord(wire[current])
             octets = ord(wire[current + 1])
             if octets == 0 or octets > 32:
-                raise dns.exception.FormError, "bad NSEC octets"
+                raise dns.exception.FormError("bad NSEC octets")
             current += 2
             rdlen -= 2
             if rdlen < octets:
-                raise dns.exception.FormError, "bad NSEC bitmap length"
+                raise dns.exception.FormError("bad NSEC bitmap length")
             bitmap = wire[current : current + octets]
             current += octets
             rdlen -= octets
index cab24cf5a7cd12fe1e767c7ef288bbeb82c25295..932d7b40327553a83e5f8c971f6558a4b94d8a11 100644 (file)
@@ -98,9 +98,9 @@ class NSEC3(dns.rdata.Rdata):
                 break
             nrdtype = dns.rdatatype.from_text(token.value)
             if nrdtype == 0:
-                raise dns.exception.SyntaxError, "NSEC3 with bit 0"
+                raise dns.exception.SyntaxError("NSEC3 with bit 0")
             if nrdtype > 65535:
-                raise dns.exception.SyntaxError, "NSEC3 with bit > 65535"
+                raise dns.exception.SyntaxError("NSEC3 with bit > 65535")
             rdtypes.append(nrdtype)
         rdtypes.sort()
         window = 0
@@ -157,15 +157,15 @@ class NSEC3(dns.rdata.Rdata):
         windows = []
         while rdlen > 0:
             if rdlen < 3:
-                raise dns.exception.FormError, "NSEC3 too short"
+                raise dns.exception.FormError("NSEC3 too short")
             window = ord(wire[current])
             octets = ord(wire[current + 1])
             if octets == 0 or octets > 32:
-                raise dns.exception.FormError, "bad NSEC3 octets"
+                raise dns.exception.FormError("bad NSEC3 octets")
             current += 2
             rdlen -= 2
             if rdlen < octets:
-                raise dns.exception.FormError, "bad NSEC3 bitmap length"
+                raise dns.exception.FormError("bad NSEC3 bitmap length")
             bitmap = wire[current : current + octets]
             current += octets
             rdlen -= octets
index 8077f070ce3a52e22d755872818bc11444f2a28c..99ae9b9dff6eca36bcaaa60de38cf91087654260 100644 (file)
@@ -61,9 +61,9 @@ class NXT(dns.rdata.Rdata):
             else:
                 nrdtype = dns.rdatatype.from_text(token.value)
             if nrdtype == 0:
-                raise dns.exception.SyntaxError, "NXT with bit 0"
+                raise dns.exception.SyntaxError("NXT with bit 0")
             if nrdtype > 127:
-                raise dns.exception.SyntaxError, "NXT with bit > 127"
+                raise dns.exception.SyntaxError("NXT with bit > 127")
             i = nrdtype // 8
             bitmap[i] = chr(ord(bitmap[i]) | (0x80 >> (nrdtype % 8)))
         bitmap = dns.rdata._truncate_bitmap(bitmap)
index 86ff77fd4da054bdebf97818b4395ef58ba20da3..9ab08d881c552877090315192d30629210a9d759 100644 (file)
@@ -42,7 +42,7 @@ class IPSECKEY(dns.rdata.Rdata):
         super(IPSECKEY, self).__init__(rdclass, rdtype)
         if gateway_type == 0:
             if gateway != '.' and not gateway is None:
-                raise SyntaxError, 'invalid gateway for gateway type 0'
+                raise SyntaxError('invalid gateway for gateway type 0')
             gateway = None
         elif gateway_type == 1:
             # check that it's OK
@@ -53,8 +53,7 @@ class IPSECKEY(dns.rdata.Rdata):
         elif gateway_type == 3:
             pass
         else:
-            raise SyntaxError, \
-                  'invalid IPSECKEY gateway type: %d' % gateway_type
+            raise SyntaxError('invalid IPSECKEY gateway type: %d' % gateway_type)
         self.precedence = precedence
         self.gateway_type = gateway_type
         self.algorithm = algorithm
@@ -71,7 +70,7 @@ class IPSECKEY(dns.rdata.Rdata):
         elif self.gateway_type == 3:
             gateway = str(self.gateway.choose_relativity(origin, relativize))
         else:
-            raise ValueError, 'invalid gateway type'
+            raise ValueError('invalid gateway type')
         return '%d %d %d %s %s' % (self.precedence, self.gateway_type,
                                    self.algorithm, gateway,
                                    dns.rdata._base64ify(self.key))
@@ -112,7 +111,7 @@ class IPSECKEY(dns.rdata.Rdata):
         elif self.gateway_type == 3:
             self.gateway.to_wire(file, None, origin)
         else:
-            raise ValueError, 'invalid gateway type'
+            raise ValueError('invalid gateway type')
         file.write(self.key)
 
     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
@@ -140,7 +139,7 @@ class IPSECKEY(dns.rdata.Rdata):
             current += cused
             rdlen -= cused
         else:
-            raise dns.exception.FormError, 'invalid IPSECKEY gateway type'
+            raise dns.exception.FormError('invalid IPSECKEY gateway type')
         key = wire[current : current + rdlen]
         return cls(rdclass, rdtype, header[0], gateway_type, header[2],
                    gateway, key)
index a8aa2044f57dea8c87e7acf7282fd12950ccf15a..22b9131ccf3fe0c751801f542cf3131f54d4b453 100644 (file)
@@ -25,30 +25,30 @@ class NSAP(dns.rdata.Rdata):
     @see: RFC 1706"""
 
     __slots__ = ['address']
-    
+
     def __init__(self, rdclass, rdtype, address):
         super(NSAP, self).__init__(rdclass, rdtype)
         self.address = address
 
     def to_text(self, origin=None, relativize=True, **kw):
         return "0x%s" % self.address.encode('hex_codec')
-        
+
     def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
         address = tok.get_string()
         t = tok.get_eol()
         if address[0:2] != '0x':
-            raise dns.exception.SyntaxError, 'string does not start with 0x'
+            raise dns.exception.SyntaxError('string does not start with 0x')
         address = address[2:].replace('.', '')
         if len(address) % 2 != 0:
-            raise dns.exception.SyntaxError, 'hexstring has odd length'
+            raise dns.exception.SyntaxError('hexstring has odd length')
         address = address.decode('hex_codec')
         return cls(rdclass, rdtype, address)
-    
+
     from_text = classmethod(from_text)
 
     def to_wire(self, file, compress = None, origin = None):
         file.write(self.address)
-        
+
     def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
         address = wire[current : current + rdlen]
         return cls(rdclass, rdtype, address)
index 0882aa1c8d427698f0bbe16526a3e423a3e4194f..85aafb3d231d546cf3d68c5ed89cf0b9318fd87c 100644 (file)
@@ -67,7 +67,7 @@ class WKS(dns.rdata.Rdata):
                 serv = int(token.value)
             else:
                 if protocol != _proto_udp and protocol != _proto_tcp:
-                    raise NotImplementedError, "protocol must be TCP or UDP"
+                    raise NotImplementedError("protocol must be TCP or UDP")
                 if protocol == _proto_udp:
                     protocol_text = "udp"
                 else:
index f513a7d3a5e4ca92976641b5706606da5ad8b3d6..75c9272670bff9c3e002f0bf8b7f881c9e2b6084 100644 (file)
@@ -97,7 +97,7 @@ class KEYBase(dns.rdata.Rdata):
             for flag in flag_names:
                 v = _flags_from_text.get(flag)
                 if v is None:
-                    raise dns.exception.SyntaxError, 'unknown flag %s' % flag
+                    raise dns.exception.SyntaxError('unknown flag %s' % flag)
                 flags &= ~v[1]
                 flags |= v[0]
         protocol = tok.get_string()
@@ -106,8 +106,7 @@ class KEYBase(dns.rdata.Rdata):
         else:
             protocol = _protocol_from_text.get(protocol)
             if protocol is None:
-                raise dns.exception.SyntaxError, \
-                      'unknown protocol %s' % protocol
+                raise dns.exception.SyntaxError('unknown protocol %s' % protocol)
 
         algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
         chunks = []
index f856237955fd1c5a7dcfefbba0e7e04ab0d5ca82..43db2a48c0791c407acc403a33d2c12833aee412 100644 (file)
@@ -49,9 +49,9 @@ class TXTBase(dns.rdata.Rdata):
             if token.is_eol_or_eof():
                 break
             if not (token.is_quoted_string() or token.is_identifier()):
-                raise dns.exception.SyntaxError, "expected a string"
+                raise dns.exception.SyntaxError("expected a string")
             if len(token.value) > 255:
-                raise dns.exception.SyntaxError, "string too long"
+                raise dns.exception.SyntaxError("string too long")
             strings.append(token.value)
         if len(strings) == 0:
             raise dns.exception.UnexpectedEnd
index 0b8a4db031de427ace3d44b5b669310d96cc9134..372d7d83615b9474e0a1e4594e6eae375d99d4f6 100644 (file)
@@ -137,7 +137,7 @@ class Answer(object):
         elif attr == 'rdtype':
             return self.rrset.rdtype
         else:
-            raise AttributeError, attr
+            raise AttributeError(attr)
 
     def __len__(self):
         return len(self.rrset)
@@ -169,7 +169,7 @@ class Cache(object):
     since the epoch.)
     @type next_cleaning: float
     """
-    
+
     def __init__(self, cleaning_interval=300.0):
         """Initialize a DNS cache.
 
@@ -177,14 +177,14 @@ class Cache(object):
         cleanings.  The default is 300.0
         @type cleaning_interval: float.
         """
-        
+
         self.data = {}
         self.cleaning_interval = cleaning_interval
         self.next_cleaning = time.time() + self.cleaning_interval
 
     def maybe_clean(self):
         """Clean the cache if it's time to do so."""
-        
+
         now = time.time()
         if self.next_cleaning <= now:
             keys_to_delete = []
@@ -195,7 +195,7 @@ class Cache(object):
                 del self.data[k]
             now = time.time()
             self.next_cleaning = now + self.cleaning_interval
-            
+
     def get(self, key):
         """Get the answer associated with I{key}.  Returns None if
         no answer is cached for the key.
@@ -204,7 +204,7 @@ class Cache(object):
         query name, rdtype, and rdclass.
         @rtype: dns.resolver.Answer object or None
         """
-        
+
         self.maybe_clean()
         v = self.data.get(key)
         if v is None or v.expiration <= time.time():
@@ -219,7 +219,7 @@ class Cache(object):
         @param value: The answer being cached
         @type value: dns.resolver.Answer object
         """
-        
+
         self.maybe_clean()
         self.data[key] = value
 
@@ -232,7 +232,7 @@ class Cache(object):
         @param key: the key to flush
         @type key: (dns.name.Name, int, int) tuple or None
         """
-        
+
         if not key is None:
             if self.data.has_key(key):
                 del self.data[key]
@@ -549,7 +549,7 @@ class Resolver(object):
         of the appropriate type, or strings that can be converted into objects
         of the appropriate type.  E.g. For I{rdtype} the integer 2 and the
         the string 'NS' both mean to query for records with DNS rdata type NS.
-        
+
         @param qname: the query name
         @type qname: dns.name.Name object or string
         @param rdtype: the query type
@@ -566,7 +566,7 @@ class Resolver(object):
         @raises NoAnswer: the response did not contain an answer
         @raises NoNameservers: no non-broken nameservers are available to
         answer the question."""
-        
+
         if isinstance(qname, (str, unicode)):
             qname = dns.name.from_text(qname, None)
         if isinstance(rdtype, str):
@@ -749,7 +749,7 @@ def zone_for_name(name, rdclass=dns.rdataclass.IN, tcp=False, resolver=None):
     if resolver is None:
         resolver = get_default_resolver()
     if not name.is_absolute():
-        raise NotAbsolute, name
+        raise NotAbsolute(name)
     while 1:
         try:
             answer = resolver.query(name, dns.rdatatype.SOA, rdclass, tcp)
index ff9087354f03a0894a86b09a0594245dec4dd572..0a61b827b0c6fe8680ae98e37749e7b9775a2577 100644 (file)
@@ -72,4 +72,4 @@ def to_address(name):
         # run through inet_aton() to check syntax and make pretty.
         return dns.ipv6.inet_ntoa(dns.ipv6.inet_aton(text))
     else:
-        raise dns.exception.SyntaxError, 'unknown reverse-map address family'
+        raise dns.exception.SyntaxError('unknown reverse-map address family')
index 3ae2d2d8ec6bdfc2f9f5a0d10190192153f92302..7f6c4afed4a0a2f60328e7720df21d0676f345a3 100644 (file)
@@ -31,7 +31,7 @@ class RRset(dns.rdataset.Rdataset):
     """
 
     __slots__ = ['name', 'deleting']
-    
+
     def __init__(self, name, rdclass, rdtype, covers=dns.rdatatype.NONE,
                  deleting=None):
         """Create a new RRset."""
@@ -65,7 +65,7 @@ class RRset(dns.rdataset.Rdataset):
     def __eq__(self, other):
         """Two RRsets are equal if they have the same name and the same
         rdataset
-        
+
         @rtype: bool"""
         if not isinstance(other, RRset):
             return False
@@ -82,7 +82,7 @@ class RRset(dns.rdataset.Rdataset):
         if self.name != name or self.deleting != deleting:
             return False
         return True
-        
+
     def to_text(self, origin=None, relativize=True, **kw):
         """Convert the RRset into DNS master file format.
 
@@ -92,7 +92,7 @@ class RRset(dns.rdataset.Rdataset):
 
         Any additional keyword arguments are passed on to the rdata
         to_text() method.
-        
+
         @param origin: The origin for relative names, or None.
         @type origin: dns.name.Name object
         @param relativize: True if names should names be relativized
@@ -121,7 +121,7 @@ def from_text_list(name, ttl, rdclass, rdtype, text_rdatas):
 
     @rtype: dns.rrset.RRset object
     """
-    
+
     if isinstance(name, (str, unicode)):
         name = dns.name.from_text(name, None)
     if isinstance(rdclass, str):
@@ -134,7 +134,7 @@ def from_text_list(name, ttl, rdclass, rdtype, text_rdatas):
         rd = dns.rdata.from_text(r.rdclass, r.rdtype, t)
         r.add(rd)
     return r
-    
+
 def from_text(name, ttl, rdclass, rdtype, *text_rdatas):
     """Create an RRset with the specified name, TTL, class, and type and with
     the specified rdatas in text format.
@@ -155,7 +155,7 @@ def from_rdata_list(name, ttl, rdatas):
         name = dns.name.from_text(name, None)
 
     if len(rdatas) == 0:
-        raise ValueError, "rdata list must not be empty"
+        raise ValueError("rdata list must not be empty")
     r = None
     for rd in rdatas:
         if r is None:
@@ -164,7 +164,7 @@ def from_rdata_list(name, ttl, rdatas):
             first_time = False
         r.add(rd)
     return r
-    
+
 def from_rdata(name, ttl, *rdatas):
     """Create an RRset with the specified name and TTL, and with
     the specified rdata objects.
index 0d6b216fc29422a13c1cfa8d3f4e9fc8104bc91e..91f9fb876693d3cd5fb9945bfff2f3c6f3b7d052 100644 (file)
@@ -26,14 +26,14 @@ class Set(object):
     @type items: list"""
 
     __slots__ = ['items']
-    
+
     def __init__(self, items=None):
         """Initialize the set.
 
         @param items: the initial set of items
         @type items: any iterable or None
         """
-        
+
         self.items = []
         if not items is None:
             for item in items:
@@ -41,7 +41,7 @@ class Set(object):
 
     def __repr__(self):
         return "dns.simpleset.Set(%s)" % repr(self.items)
-        
+
     def add(self, item):
         """Add an item to the set."""
         if not item in self.items:
@@ -70,7 +70,7 @@ class Set(object):
         return new instances (e.g. union) once, and keep using them in
         subclasses.
         """
-        
+
         cls = self.__class__
         obj = cls.__new__(cls)
         obj.items = list(self.items)
@@ -79,7 +79,7 @@ class Set(object):
     def __copy__(self):
         """Make a (shallow) copy of the set."""
         return self._clone()
-        
+
     def copy(self):
         """Make a (shallow) copy of the set."""
         return self._clone()
@@ -91,7 +91,7 @@ class Set(object):
         @type other: Set object
         """
         if not isinstance(other, Set):
-            raise ValueError, 'other must be a Set instance'
+            raise ValueError('other must be a Set instance')
         if self is other:
             return
         for item in other.items:
@@ -104,7 +104,7 @@ class Set(object):
         @type other: Set object
         """
         if not isinstance(other, Set):
-            raise ValueError, 'other must be a Set instance'
+            raise ValueError('other must be a Set instance')
         if self is other:
             return
         # we make a copy of the list so that we can remove items from
@@ -120,7 +120,7 @@ class Set(object):
         @type other: Set object
         """
         if not isinstance(other, Set):
-            raise ValueError, 'other must be a Set instance'
+            raise ValueError('other must be a Set instance')
         if self is other:
             self.items = []
         else:
@@ -134,7 +134,7 @@ class Set(object):
         @type other: Set object
         @rtype: the same type as I{self}
         """
-        
+
         obj = self._clone()
         obj.union_update(other)
         return obj
@@ -241,9 +241,9 @@ class Set(object):
 
         @rtype: bool
         """
-        
+
         if not isinstance(other, Set):
-            raise ValueError, 'other must be a Set instance'
+            raise ValueError('other must be a Set instance')
         for item in self.items:
             if not item in other.items:
                 return False
@@ -256,7 +256,7 @@ class Set(object):
         """
 
         if not isinstance(other, Set):
-            raise ValueError, 'other must be a Set instance'
+            raise ValueError('other must be a Set instance')
         for item in other.items:
             if not item in self.items:
                 return False
index aea6f5edef8a650737bbe5f506bb1f0cf07f1ea5..4f68a2a4952c467567518b478a998a79b38735dc 100644 (file)
@@ -352,8 +352,7 @@ class Tokenizer(object):
                             return Token(COMMENT, token)
                         elif c == '':
                             if self.multiline:
-                                raise dns.exception.SyntaxError, \
-                                      'unbalanced parentheses'
+                                raise dns.exception.SyntaxError('unbalanced parentheses')
                             return Token(EOF)
                         elif self.multiline:
                             self.skip_whitespace()
@@ -386,7 +385,7 @@ class Tokenizer(object):
                             raise dns.exception.SyntaxError
                         c = chr(int(c) * 100 + int(c2) * 10 + int(c3))
                 elif c == '\n':
-                    raise dns.exception.SyntaxError, 'newline in quoted string'
+                    raise dns.exception.SyntaxError('newline in quoted string')
             elif c == '\\':
                 #
                 # It's an escape.  Put it and the next character into
@@ -400,7 +399,7 @@ class Tokenizer(object):
             token += c
         if token == '' and ttype != QUOTED_STRING:
             if self.multiline:
-                raise dns.exception.SyntaxError, 'unbalanced parentheses'
+                raise dns.exception.SyntaxError('unbalanced parentheses')
             ttype = EOF
         return Token(ttype, token, has_escape)
 
@@ -444,9 +443,9 @@ class Tokenizer(object):
 
         token = self.get().unescape()
         if not token.is_identifier():
-            raise dns.exception.SyntaxError, 'expecting an identifier'
+            raise dns.exception.SyntaxError('expecting an identifier')
         if not token.value.isdigit():
-            raise dns.exception.SyntaxError, 'expecting an integer'
+            raise dns.exception.SyntaxError('expecting an integer')
         return int(token.value)
 
     def get_uint8(self):
@@ -459,8 +458,7 @@ class Tokenizer(object):
 
         value = self.get_int()
         if value < 0 or value > 255:
-            raise dns.exception.SyntaxError, \
-                  '%d is not an unsigned 8-bit integer' % value
+            raise dns.exception.SyntaxError('%d is not an unsigned 8-bit integer' % value)
         return value
 
     def get_uint16(self):
@@ -473,8 +471,7 @@ class Tokenizer(object):
 
         value = self.get_int()
         if value < 0 or value > 65535:
-            raise dns.exception.SyntaxError, \
-                  '%d is not an unsigned 16-bit integer' % value
+            raise dns.exception.SyntaxError('%d is not an unsigned 16-bit integer' % value)
         return value
 
     def get_uint32(self):
@@ -487,13 +484,12 @@ class Tokenizer(object):
 
         token = self.get().unescape()
         if not token.is_identifier():
-            raise dns.exception.SyntaxError, 'expecting an identifier'
+            raise dns.exception.SyntaxError('expecting an identifier')
         if not token.value.isdigit():
-            raise dns.exception.SyntaxError, 'expecting an integer'
+            raise dns.exception.SyntaxError('expecting an integer')
         value = long(token.value)
         if value < 0 or value > 4294967296L:
-            raise dns.exception.SyntaxError, \
-                  '%d is not an unsigned 32-bit integer' % value
+            raise dns.exception.SyntaxError('%d is not an unsigned 32-bit integer' % value)
         return value
 
     def get_string(self, origin=None):
@@ -505,7 +501,7 @@ class Tokenizer(object):
 
         token = self.get().unescape()
         if not (token.is_identifier() or token.is_quoted_string()):
-            raise dns.exception.SyntaxError, 'expecting a string'
+            raise dns.exception.SyntaxError('expecting a string')
         return token.value
 
     def get_identifier(self, origin=None):
@@ -517,7 +513,7 @@ class Tokenizer(object):
 
         token = self.get().unescape()
         if not token.is_identifier():
-            raise dns.exception.SyntaxError, 'expecting an identifier'
+            raise dns.exception.SyntaxError('expecting an identifier')
         return token.value
 
     def get_name(self, origin=None):
@@ -528,7 +524,7 @@ class Tokenizer(object):
 
         token = self.get()
         if not token.is_identifier():
-            raise dns.exception.SyntaxError, 'expecting an identifier'
+            raise dns.exception.SyntaxError('expecting an identifier')
         return dns.name.from_text(token.value, origin)
 
     def get_eol(self):
@@ -541,12 +537,11 @@ class Tokenizer(object):
 
         token = self.get()
         if not token.is_eol_or_eof():
-            raise dns.exception.SyntaxError, \
-                  'expected EOL or EOF, got %d "%s"' % (token.ttype, token.value)
+            raise dns.exception.SyntaxError('expected EOL or EOF, got %d "%s"' % (token.ttype, token.value))
         return token.value
 
     def get_ttl(self):
         token = self.get().unescape()
         if not token.is_identifier():
-            raise dns.exception.SyntaxError, 'expecting an identifier'
+            raise dns.exception.SyntaxError('expecting an identifier')
         return dns.ttl.from_text(token.value)
index 175bb2e05044f267c453f6e69afca75aeb42789c..b4deeca859dcaac594acd4733326c17b64f5a4c7 100644 (file)
@@ -89,7 +89,7 @@ def sign(wire, keyname, secret, time, fudge, original_id, error,
     pre_mac = algorithm_name + time_mac
     ol = len(other_data)
     if ol > 65535:
-        raise ValueError, 'TSIG Other Data is > 65535 bytes'
+        raise ValueError('TSIG Other Data is > 65535 bytes')
     post_mac = struct.pack('!HH', error, ol) + other_data
     if first:
         ctx.update(pre_mac)
@@ -155,7 +155,7 @@ def validate(wire, keyname, secret, now, request_mac, tsig_start, tsig_rdata,
         elif error == BADTRUNC:
             raise PeerBadTruncation
         else:
-            raise PeerError, 'unknown TSIG error code %d' % error
+            raise PeerError('unknown TSIG error code %d' % error)
     time_low = time - fudge
     time_high = time + fudge
     if now < time_low or now > time_high:
@@ -212,5 +212,5 @@ def get_algorithm(algorithm):
     if algorithm in hashes:
         return (algorithm.to_digestable(), hashes[algorithm])
 
-    raise NotImplementedError, "TSIG algorithm " + str(algorithm) + \
-        " is not supported"
+    raise NotImplementedError("TSIG algorithm " + str(algorithm) +
+                              " is not supported")
index 1b1f34c202802abea9bf09ca8ca1d50606c84e3c..f295300517755cb7cc89d29b950bc7d1d74fead8 100644 (file)
@@ -19,7 +19,7 @@ import dns.exception
 
 class BadTTL(dns.exception.SyntaxError):
     pass
-                 
+
 def from_text(text):
     """Convert the text form of a TTL to an integer.
 
@@ -30,7 +30,7 @@ def from_text(text):
     @raises dns.ttl.BadTTL: the TTL is not well-formed
     @rtype: int
     """
-    
+
     if text.isdigit():
         total = long(text)
     else:
@@ -55,10 +55,10 @@ def from_text(text):
                 elif c == 's':
                     total += current
                 else:
-                    raise BadTTL, "unknown unit '%s'" % c
+                    raise BadTTL("unknown unit '%s'" % c)
                 current = 0
         if not current == 0:
-            raise BadTTL, "trailing integer"
+            raise BadTTL("trailing integer")
     if total < 0L or total > 2147483647L:
-        raise BadTTL, "TTL should be between 0 and 2^31 - 1 (inclusive)"
+        raise BadTTL("TTL should be between 0 and 2^31 - 1 (inclusive)")
     return total
index 4b49e42a4e08cae74368e640dfd442388351a811..93c157d8f01d22f5f94eba6a5e9d503465a8554d 100644 (file)
@@ -110,12 +110,10 @@ class Zone(object):
         if isinstance(name, (str, unicode)):
             name = dns.name.from_text(name, None)
         elif not isinstance(name, dns.name.Name):
-            raise KeyError, \
-                  "name parameter must be convertable to a DNS name"
+            raise KeyError("name parameter must be convertable to a DNS name")
         if name.is_absolute():
             if not name.is_subdomain(self.origin):
-                raise KeyError, \
-                      "name parameter must be a subdomain of the zone origin"
+                raise KeyError("name parameter must be a subdomain of the zone origin")
             if self.relativize:
                 name = name.relativize(self.origin)
         return name
@@ -330,7 +328,7 @@ class Zone(object):
         """
 
         if replacement.rdclass != self.rdclass:
-            raise ValueError, 'replacement.rdclass != zone.rdclass'
+            raise ValueError('replacement.rdclass != zone.rdclass')
         node = self.find_node(name, True)
         node.replace_rdataset(replacement)
 
@@ -612,13 +610,12 @@ class _MasterReader(object):
         except:
             rdclass = self.zone.rdclass
         if rdclass != self.zone.rdclass:
-            raise dns.exception.SyntaxError, "RR class is not zone's class"
+            raise dns.exception.SyntaxError("RR class is not zone's class")
         # Type
         try:
             rdtype = dns.rdatatype.from_text(token.value)
         except:
-            raise dns.exception.SyntaxError, \
-                  "unknown rdatatype '%s'" % token.value
+            raise dns.exception.SyntaxError("unknown rdatatype '%s'" % token.value)
         n = self.zone.nodes.get(name)
         if n is None:
             n = self.zone.node_factory()
@@ -629,7 +626,7 @@ class _MasterReader(object):
         except dns.exception.SyntaxError:
             # Catch and reraise.
             (ty, va) = sys.exc_info()[:2]
-            raise ty, va
+            raise va
         except:
             # All exceptions that occur in the processing of rdata
             # are treated as syntax errors.  This is not strictly
@@ -637,8 +634,7 @@ class _MasterReader(object):
             # We convert them to syntax errors so that we can emit
             # helpful filename:line info.
             (ty, va) = sys.exc_info()[:2]
-            raise dns.exception.SyntaxError, \
-                  "caught exception %s: %s" % (str(ty), str(va))
+            raise dns.exception.SyntaxError("caught exception %s: %s" % (str(ty), str(va)))
 
         rd.choose_relativity(self.zone.origin, self.relativize)
         covers = rd.covers()
@@ -676,7 +672,7 @@ class _MasterReader(object):
                     if u == '$TTL':
                         token = self.tok.get()
                         if not token.is_identifier():
-                            raise dns.exception.SyntaxError, "bad $TTL"
+                            raise dns.exception.SyntaxError("bad $TTL")
                         self.ttl = dns.ttl.from_text(token.value)
                         self.tok.get_eol()
                     elif u == '$ORIGIN':
@@ -687,8 +683,7 @@ class _MasterReader(object):
                     elif u == '$INCLUDE' and self.allow_include:
                         token = self.tok.get()
                         if not token.is_quoted_string():
-                            raise dns.exception.SyntaxError, \
-                                  "bad filename in $INCLUDE"
+                            raise dns.exception.SyntaxError("bad filename in $INCLUDE")
                         filename = token.value
                         token = self.tok.get()
                         if token.is_identifier():
@@ -696,8 +691,7 @@ class _MasterReader(object):
                                                             self.current_origin)
                             self.tok.get_eol()
                         elif not token.is_eol_or_eof():
-                            raise dns.exception.SyntaxError, \
-                                  "bad origin in $INCLUDE"
+                            raise dns.exception.SyntaxError("bad origin in $INCLUDE")
                         else:
                             new_origin = self.current_origin
                         self.saved_state.append((self.tok,
@@ -710,8 +704,7 @@ class _MasterReader(object):
                                                            filename)
                         self.current_origin = new_origin
                     else:
-                        raise dns.exception.SyntaxError, \
-                              "Unknown master file directive '" + u + "'"
+                        raise dns.exception.SyntaxError("Unknown master file directive '" + u + "'")
                     continue
                 self.tok.unget(token)
                 self._rr_line()
@@ -719,8 +712,7 @@ class _MasterReader(object):
             (filename, line_number) = self.tok.where()
             if detail is None:
                 detail = "syntax error"
-            raise dns.exception.SyntaxError, \
-                  "%s:%d: %s" % (filename, line_number, detail)
+            raise dns.exception.SyntaxError("%s:%d: %s" % (filename, line_number, detail))
 
         # Now that we're done reading, do some basic checking of the zone.
         if self.check_origin: