Ticket #2276: patch.1

File patch.1, 4.2 KB (added by agatonsax, 7 years ago)

Added documentation and test

Line 
1Index: twisted/names/test/test_dns.py
2===================================================================
3--- twisted/names/test/test_dns.py      (revision 23403)
4+++ twisted/names/test/test_dns.py      (working copy)
5@@ -102,8 +102,37 @@
6             hk2 = hash(k2)
7             self.assertEquals(hk1, hk2, "%s != %s (for %s)" % (hk1,hk2,k))
8 
9+    def testCharstr(self):
10+        for n in self.names:
11+            # encode the name
12+            f = StringIO()
13+            dns.Charstr(n).encode(f)
14 
15+            # decode the name
16+            f.seek(0, 0)
17+            result = dns.Charstr()
18+            result.decode(f)
19+            self.assertEquals(result.string, n)
20 
21+    naptrs = [(100, 10, "u", "sip+E2U","!^.*$!sip:information@domain.tld!"),
22+        (100, 50, "s", "http+I2L+I2C+I2R" ,"" ,"_http._tcp.gatech.edu.")]
23+
24+    def testNAPTR(self):
25+        for (order,preference,flags,service,regexp,replacement) in naptrs:             
26+            rin = dns.Record_NAPTR(order,preference,flags,service,regexp,replacement)
27+            e = StringIO()
28+            rin.encode(e)
29+            e.seek(0,0)
30+            rout = dns.Record_NAPTR()
31+            rout.decode(e)
32+            self.assertEquals(rin.order, rout.order)
33+            self.assertEquals(rin.preference, rout.preference)
34+            self.assertEquals(rin.flags, rout.flags)
35+            self.assertEquals(rin.service, rout.service)
36+            self.assertEquals(rin.regexp, rout.regexp)
37+            self.assertEquals(rin.replacement, rout.replacement)
38+            self.assertEquals(rin.ttl, rout.ttl)
39+
40 class MessageTestCase(unittest.TestCase):
41     def testEmptyMessage(self):
42         """
43Index: twisted/names/dns.py
44===================================================================
45--- twisted/names/dns.py        (revision 23403)
46+++ twisted/names/dns.py        (working copy)
47@@ -208,7 +208,8 @@
48         """
49         Encode this Character string into the appropriate byte format.
50 
51-        @type strio: file @param strio: The byte representation of this Charstr
52+        @type strio: file
53+        @param strio: The byte representation of this Charstr
54             will be written to this file.
55 
56         @type compDict: dict @param compDict: dictionary of Charstrs that have
57@@ -1020,6 +1021,52 @@
58 
59 
60 class Record_NAPTR(tputil.FancyEqMixin, tputil.FancyStrMixin):
61+    """
62+    The location of the server(s) for a specific protocol and domain.
63+
64+    This is an experimental record type.
65+
66+    @type order: C{int}
67+    @ivar order: An integer specifying the order in which the NAPTR records
68+        MUST be processed to ensure the correct ordering of rules. 
69+        Low numbers are processed before high numbers
70+
71+    @type preference: C{int}
72+    @ivar preference: An integer that specifies the order in which NAPTR
73+        records with equal "order" values SHOULD be processed, low
74+        numbers being processed before high numbers.
75+
76+    @type flag: L{Charstr}
77+    @ivar flag: A <character-string> containing flags to control aspects of the
78+        rewriting and interpretation of the fields in the record.  Flags
79+        are single characters from the set [A-Z0-9].  The case of the
80+        alphabetic characters is not significant.
81+
82+        At this time only four flags, "S", "A", "U", and "P", are defined.
83+
84+    @type service: L{Charstr}
85+    @ivar service: Specifies the service(s) available down this rewrite path.
86+        It may also specify the particular protocol that is used to talk with a
87+        service.  A protocol MUST be specified if the flags field states
88+        that the NAPTR is terminal.
89+
90+    @type regexp: L{Charstr}
91+    @ivar regexp: A STRING containing a substitution expression that is applied to
92+        the original string held by the client in order to construct the
93+        next domain name to lookup.
94+
95+    @type replacement: L{Name}
96+    @ivar replacement: The next NAME to query for NAPTR, SRV, or address records
97+        depending on the value of the flags field.  This MUST be a fully
98+        qualified domain-name.
99+
100+    @type ttl: C{int}
101+    @ivar ttl: The maximum number of seconds which this record should be
102+        cached.
103+
104+    @see: U{http://www.faqs.org/rfcs/rfc2915.html}
105+    """
106+   
107     implements(IEncodable, IRecord)
108     TYPE = NAPTR
109