]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Fix type registration for singleton types. 474/head
authorBrian Wellington <bwelling@xbill.org>
Tue, 19 May 2020 17:21:53 +0000 (10:21 -0700)
committerBrian Wellington <bwelling@xbill.org>
Tue, 19 May 2020 17:21:53 +0000 (10:21 -0700)
dns/rdatatype.py
tests/stxt_module.py [new file with mode: 0644]
tests/test_rdata.py

index fc8c717399aad934aeab569cf0cac0220e65224d..7bfa76459067c127a158b7f0c72e90c519168820 100644 (file)
@@ -231,4 +231,4 @@ def register_type(rdtype, rdtype_text, is_singleton=False):
     _registered_by_text[rdtype_text] = rdtype
     _registered_by_value[rdtype] = rdtype_text
     if is_singleton:
-        _singletons[rdtype] = True
+        _singletons.add(rdtype)
diff --git a/tests/stxt_module.py b/tests/stxt_module.py
new file mode 100644 (file)
index 0000000..7f61235
--- /dev/null
@@ -0,0 +1,4 @@
+import dns.rdtypes.txtbase
+
+class STXT(dns.rdtypes.txtbase.TXTBase):
+    """Test singleton TXT-like record"""
index 55c6c2c0d506ef88d55c631b20ecdffb002d9069..b994a6256718b0fcb1e93af7ed9b498f4f160b69 100644 (file)
@@ -23,6 +23,7 @@ import dns.rdata
 import dns.rdataclass
 import dns.rdatatype
 
+import tests.stxt_module
 import tests.ttxt_module
 
 class RdataTestCase(unittest.TestCase):
@@ -49,6 +50,16 @@ class RdataTestCase(unittest.TestCase):
             dns.rdata.register_type(tests.ttxt_module, TTXTTWO, 'TTXTTWO')
         self.assertRaises(dns.rdata.RdatatypeExists, bad)
 
+    def test_module_registration_singleton(self):
+        STXT = 64002
+        dns.rdata.register_type(tests.stxt_module, STXT, 'STXT',
+                                is_singleton=True)
+        rdata1 = dns.rdata.from_text(dns.rdataclass.IN, STXT, 'hello')
+        rdata2 = dns.rdata.from_text(dns.rdataclass.IN, STXT, 'world')
+        rdataset = dns.rdataset.from_rdata(3600, rdata1, rdata2)
+        self.assertEqual(len(rdataset), 1)
+        self.assertEqual(rdataset[0].strings, (b'world',))
+
     def test_replace(self):
         a1 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, "1.2.3.4")
         a2 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, "2.3.4.5")