From: Brian Wellington Date: Tue, 19 May 2020 17:21:53 +0000 (-0700) Subject: Fix type registration for singleton types. X-Git-Tag: v2.0.0rc1~192^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F474%2Fhead;p=thirdparty%2Fdnspython.git Fix type registration for singleton types. --- diff --git a/dns/rdatatype.py b/dns/rdatatype.py index fc8c7173..7bfa7645 100644 --- a/dns/rdatatype.py +++ b/dns/rdatatype.py @@ -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 index 00000000..7f612357 --- /dev/null +++ b/tests/stxt_module.py @@ -0,0 +1,4 @@ +import dns.rdtypes.txtbase + +class STXT(dns.rdtypes.txtbase.TXTBase): + """Test singleton TXT-like record""" diff --git a/tests/test_rdata.py b/tests/test_rdata.py index 55c6c2c0..b994a625 100644 --- a/tests/test_rdata.py +++ b/tests/test_rdata.py @@ -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")