]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
add SPF support
authorBob Halley <halley@dnspython.org>
Wed, 21 Jun 2006 23:01:46 +0000 (23:01 +0000)
committerBob Halley <halley@dnspython.org>
Wed, 21 Jun 2006 23:01:46 +0000 (23:01 +0000)
ChangeLog
dns/rdatatype.py
dns/rdtypes/ANY/TXT.py
dns/rdtypes/txtbase.py [new file with mode: 0644]
tests/example
tests/example1.good
tests/example2.good

index 65045e4bc90a4cc8b0efaa25c7ad37fb74a7e896..162c108c0f24ed82e8d988d2973e71d2c6b6ec02 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2006-06-21  Bob Halley  <halley@dnspython.org>
+
+       * dns/rdtypes/ANY/SPF.py: Added support for the SPF RR type.
+
 2006-06-02  Bob Halley  <halley@dnspython.org>
 
        * (Version 1.4.0 released)
index 839ad01bd74ea14748b9d4e1e9b164c902851038..0f29bd7e00de06495f38925fef76f26148818db8 100644 (file)
@@ -74,6 +74,7 @@ SSHFP = 44
 RRSIG = 46
 NSEC = 47
 DNSKEY = 48
+SPF = 99
 UNSPEC = 103
 TKEY = 249
 TSIG = 250
@@ -128,6 +129,7 @@ _by_text = {
     'RRSIG' : RRSIG,
     'NSEC' : NSEC,
     'DNSKEY' : DNSKEY,
+    'SPF' : SPF,
     'UNSPEC' : UNSPEC,
     'TKEY' : TKEY,
     'TSIG' : TSIG,
index 0aa5f2fa8d0b0c8b0dbe805d10fe717fbfc11e9a..60a79a6c4dd0b54d0d50512b42bb5f0a47326a6d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2003-2005 Nominum, Inc.
+# Copyright (C) 2003-2006 Nominum, Inc.
 #
 # Permission to use, copy, modify, and distribute this software and its
 # documentation for any purpose with or without fee is hereby granted,
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-import dns.exception
-import dns.rdata
-import dns.tokenizer
+import dns.rdtypes.txtbase
 
-class TXT(dns.rdata.Rdata):
-    """TXT record
-
-    @ivar strings: the text strings
-    @type strings: list of string
-    @see: RFC 1035"""
-
-    __slots__ = ['strings']
-    
-    def __init__(self, rdclass, rdtype, strings):
-        super(TXT, self).__init__(rdclass, rdtype)
-        if isinstance(strings, str):
-            strings = [ strings ]
-        self.strings = strings[:]
-
-    def to_text(self, origin=None, relativize=True, **kw):
-        txt = ''
-        prefix = ''
-        for s in self.strings:
-            txt += '%s"%s"' % (prefix, dns.rdata._escapify(s))
-            prefix = ' '
-        return txt
-        
-    def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
-        strings = []
-        while 1:
-            (ttype, s) = tok.get()
-            if ttype == dns.tokenizer.EOL or ttype == dns.tokenizer.EOF:
-                break
-            if ttype != dns.tokenizer.QUOTED_STRING and \
-               ttype != dns.tokenizer.IDENTIFIER:
-                raise dns.exception.SyntaxError, "expected a string"
-            if len(s) > 255:
-                raise dns.exception.SyntaxError, "string too long"
-            strings.append(s)
-        if len(strings) == 0:
-            raise dns.exception.UnexpectedEnd
-        return cls(rdclass, rdtype, strings)
-    
-    from_text = classmethod(from_text)
-
-    def to_wire(self, file, compress = None, origin = None):
-        for s in self.strings:
-            l = len(s)
-            assert l < 256
-            byte = chr(l)
-            file.write(byte)
-            file.write(s)
-        
-    def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
-        strings = []
-        while rdlen > 0:
-            l = ord(wire[current])
-            current += 1
-            rdlen -= 1
-            if l > rdlen:
-                raise dns.exception.FormError
-            s = wire[current : current + l]
-            current += l
-            rdlen -= l
-            strings.append(s)
-        return cls(rdclass, rdtype, strings)
-
-    from_wire = classmethod(from_wire)
-
-    def _cmp(self, other):
-        return cmp(self.strings, other.strings)
+class TXT(dns.rdtypes.txtbase.TXTBase):
+    """TXT record"""
+    pass
diff --git a/dns/rdtypes/txtbase.py b/dns/rdtypes/txtbase.py
new file mode 100644 (file)
index 0000000..ec3c046
--- /dev/null
@@ -0,0 +1,88 @@
+# Copyright (C) 2003-2005 Nominum, Inc.
+#
+# Permission to use, copy, modify, and distribute this software and its
+# documentation for any purpose with or without fee is hereby granted,
+# provided that the above copyright notice and this permission notice
+# appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+"""TXT-like base class."""
+
+import dns.exception
+import dns.rdata
+import dns.tokenizer
+
+class TXTBase(dns.rdata.Rdata):
+    """Base class for rdata that is like a TXT record
+
+    @ivar strings: the text strings
+    @type strings: list of string
+    @see: RFC 1035"""
+
+    __slots__ = ['strings']
+    
+    def __init__(self, rdclass, rdtype, strings):
+        super(TXTBase, self).__init__(rdclass, rdtype)
+        if isinstance(strings, str):
+            strings = [ strings ]
+        self.strings = strings[:]
+
+    def to_text(self, origin=None, relativize=True, **kw):
+        txt = ''
+        prefix = ''
+        for s in self.strings:
+            txt += '%s"%s"' % (prefix, dns.rdata._escapify(s))
+            prefix = ' '
+        return txt
+        
+    def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
+        strings = []
+        while 1:
+            (ttype, s) = tok.get()
+            if ttype == dns.tokenizer.EOL or ttype == dns.tokenizer.EOF:
+                break
+            if ttype != dns.tokenizer.QUOTED_STRING and \
+               ttype != dns.tokenizer.IDENTIFIER:
+                raise dns.exception.SyntaxError, "expected a string"
+            if len(s) > 255:
+                raise dns.exception.SyntaxError, "string too long"
+            strings.append(s)
+        if len(strings) == 0:
+            raise dns.exception.UnexpectedEnd
+        return cls(rdclass, rdtype, strings)
+    
+    from_text = classmethod(from_text)
+
+    def to_wire(self, file, compress = None, origin = None):
+        for s in self.strings:
+            l = len(s)
+            assert l < 256
+            byte = chr(l)
+            file.write(byte)
+            file.write(s)
+        
+    def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
+        strings = []
+        while rdlen > 0:
+            l = ord(wire[current])
+            current += 1
+            rdlen -= 1
+            if l > rdlen:
+                raise dns.exception.FormError
+            s = wire[current : current + l]
+            current += l
+            rdlen -= l
+            strings.append(s)
+        return cls(rdclass, rdtype, strings)
+
+    from_wire = classmethod(from_wire)
+
+    def _cmp(self, other):
+        return cmp(self.strings, other.strings)
index 4833201dd3dcd9c3e57288ccb2bced30c7461233..f705e101f09ec2c7f3b1b3d48b42ea4d6cccbdcc 100644 (file)
@@ -205,3 +205,4 @@ dnskey02            DNSKEY  HOST|FLAG4 DNSSEC RSAMD5 (
 ;
 unknown3               A       \# 4 7f000002
 sshfp1                 SSHFP   1 1 aa549bfe898489c02d1715d97d79c57ba2fa76ab
+spf                    SPF     "v=spf1 mx -all"
index d80b8ed4e0fda13811e42df59b44ee726ac282b6..fbbbdb8cb70292bd028e8be954ad866f74b24483 100644 (file)
@@ -78,6 +78,7 @@ rt02 3600 IN RT 65535 .
 s 300 IN NS ns.s
 ns.s 300 IN A 73.80.65.49
 sig01 3600 IN SIG NXT 1 3 3600 20200101000000 20030101000000 2143 foo MxFcby9k/yvedMfQgKzhH5er0Mu/vILz 45IkskceFGgiWCn/GxHhai6VAuHAoNUz 4YoU1tVfSCSqQYn6//11U6Nld80jEeC8 aTrO+KKmCaY=
+spf 3600 IN SPF "v=spf1 mx -all"
 srv01 3600 IN SRV 0 0 0 .
 srv02 3600 IN SRV 65535 65535 65535 old-slow-box.example.com.
 sshfp1 3600 IN SSHFP 1 1 aa549bfe898489c02d1715d97d79c57ba2fa76ab
index 62d6ace1cea1777a1ed9836f31fb6725d83b0be2..32256a0f8bfdc483641bc6f1aa6a160415c017f0 100644 (file)
@@ -78,6 +78,7 @@ rt02.example. 3600 IN RT 65535 .
 s.example. 300 IN NS ns.s.example.
 ns.s.example. 300 IN A 73.80.65.49
 sig01.example. 3600 IN SIG NXT 1 3 3600 20200101000000 20030101000000 2143 foo.example. MxFcby9k/yvedMfQgKzhH5er0Mu/vILz 45IkskceFGgiWCn/GxHhai6VAuHAoNUz 4YoU1tVfSCSqQYn6//11U6Nld80jEeC8 aTrO+KKmCaY=
+spf.example. 3600 IN SPF "v=spf1 mx -all"
 srv01.example. 3600 IN SRV 0 0 0 .
 srv02.example. 3600 IN SRV 65535 65535 65535 old-slow-box.example.com.
 sshfp1.example. 3600 IN SSHFP 1 1 aa549bfe898489c02d1715d97d79c57ba2fa76ab