diff options
| author | Bob Halley <halley@dnspython.org> | 2020-05-19 13:08:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-19 13:08:12 -0700 |
| commit | 6dc132936d44f7bcd08063e0f2d96c52131f4c67 (patch) | |
| tree | 661e80d9a75afcd087c9c939b551f8c9c700ed46 | |
| parent | c28b04c4979caaaa117825191092ae3bc537e16d (diff) | |
| parent | a72125bc9a625c2c6cf51fb2501263f2e9a22127 (diff) | |
| download | dnspython-6dc132936d44f7bcd08063e0f2d96c52131f4c67.tar.gz | |
Merge pull request #474 from bwelling/sets
Replace dicts with sets.
| -rw-r--r-- | dns/rdataclass.py | 5 | ||||
| -rw-r--r-- | dns/rdatatype.py | 16 | ||||
| -rw-r--r-- | dns/tokenizer.py | 12 | ||||
| -rw-r--r-- | tests/stxt_module.py | 4 | ||||
| -rw-r--r-- | tests/test_rdata.py | 11 |
5 files changed, 22 insertions, 26 deletions
diff --git a/dns/rdataclass.py b/dns/rdataclass.py index 300de40..828812c 100644 --- a/dns/rdataclass.py +++ b/dns/rdataclass.py @@ -36,10 +36,7 @@ class RdataClass(enum.IntEnum): globals().update(RdataClass.__members__) -_metaclasses = { - NONE: True, - ANY: True -} +_metaclasses = {NONE, ANY} _unknown_class_pattern = re.compile('CLASS([0-9]+)$', re.I) diff --git a/dns/rdatatype.py b/dns/rdatatype.py index 68a5c2b..7bfa764 100644 --- a/dns/rdatatype.py +++ b/dns/rdatatype.py @@ -102,17 +102,9 @@ _registered_by_value = {} globals().update(RdataType.__members__.items()) -_metatypes = { - OPT: True -} - -_singletons = { - SOA: True, - NXT: True, - DNAME: True, - NSEC: True, - CNAME: True, -} +_metatypes = {OPT} + +_singletons = {SOA, NXT, DNAME, NSEC, CNAME} _unknown_type_pattern = re.compile('TYPE([0-9]+)$', re.I) @@ -239,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/dns/tokenizer.py b/dns/tokenizer.py index 547e030..791e994 100644 --- a/dns/tokenizer.py +++ b/dns/tokenizer.py @@ -24,16 +24,8 @@ import dns.exception import dns.name import dns.ttl -_DELIMITERS = { - ' ': True, - '\t': True, - '\n': True, - ';': True, - '(': True, - ')': True, - '"': True} - -_QUOTING_DELIMITERS = {'"': True} +_DELIMITERS = {' ', '\t', '\n', ';', '(', ')', '"'} +_QUOTING_DELIMITERS = {'"'} EOF = 0 EOL = 1 diff --git a/tests/stxt_module.py b/tests/stxt_module.py new file mode 100644 index 0000000..7f61235 --- /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 55c6c2c..b994a62 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") |
