summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2020-08-01 07:05:53 -0700
committerBob Halley <halley@dnspython.org>2020-08-01 07:05:53 -0700
commit017704f9b4dfb8eaecf0c2b47565bc69b2ac4e2f (patch)
treeb675df9e834cc052db8054f745735f575ec9fc93
parent049eedd8ab25f211d0fcd88726098327cc27ddb2 (diff)
downloaddnspython-017704f9b4dfb8eaecf0c2b47565bc69b2ac4e2f.tar.gz
Backwards compatibility constants compatible with pylint and mypy.
-rw-r--r--dns/constants/_dnssec_algorithm.py21
-rw-r--r--dns/constants/_edns_optiontype.py14
-rw-r--r--dns/constants/_flags_ednsflag.py5
-rw-r--r--dns/constants/_flags_flag.py11
-rw-r--r--dns/constants/_message_messagesection.py8
-rw-r--r--dns/constants/_opcode_opcode.py9
-rw-r--r--dns/constants/_rcode_rcode.py25
-rw-r--r--dns/constants/_rdataclass_rdataclass.py13
-rw-r--r--dns/constants/_rdatatype_rdatatype.py77
-rw-r--r--dns/constants/_rdtypes_dnskeybase_flag.py7
-rw-r--r--dns/constants/_update_updatesection.py8
-rw-r--r--dns/dnssec.py5
-rw-r--r--dns/edns.py5
-rw-r--r--dns/flags.py10
-rw-r--r--dns/message.py4
-rw-r--r--dns/opcode.py4
-rw-r--r--dns/rcode.py4
-rw-r--r--dns/rdataclass.py4
-rw-r--r--dns/rdatatype.py4
-rw-r--r--dns/rdtypes/dnskeybase.py9
-rw-r--r--dns/update.py4
-rwxr-xr-xsetup.py2
-rw-r--r--tests/test_flags.py4
-rwxr-xr-xutil/constants-tool79
24 files changed, 315 insertions, 21 deletions
diff --git a/dns/constants/_dnssec_algorithm.py b/dns/constants/_dnssec_algorithm.py
new file mode 100644
index 0000000..2a18edf
--- /dev/null
+++ b/dns/constants/_dnssec_algorithm.py
@@ -0,0 +1,21 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+#
+# This is a generated file, do not edit.
+
+RSAMD5 = 1
+DH = 2
+DSA = 3
+ECC = 4
+RSASHA1 = 5
+DSANSEC3SHA1 = 6
+RSASHA1NSEC3SHA1 = 7
+RSASHA256 = 8
+RSASHA512 = 10
+ECCGOST = 12
+ECDSAP256SHA256 = 13
+ECDSAP384SHA384 = 14
+ED25519 = 15
+ED448 = 16
+INDIRECT = 252
+PRIVATEDNS = 253
+PRIVATEOID = 254
diff --git a/dns/constants/_edns_optiontype.py b/dns/constants/_edns_optiontype.py
new file mode 100644
index 0000000..5753e4b
--- /dev/null
+++ b/dns/constants/_edns_optiontype.py
@@ -0,0 +1,14 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+#
+# This is a generated file, do not edit.
+
+NSID = 3
+DAU = 5
+DHU = 6
+N3U = 7
+ECS = 8
+EXPIRE = 9
+COOKIE = 10
+KEEPALIVE = 11
+PADDING = 12
+CHAIN = 13
diff --git a/dns/constants/_flags_ednsflag.py b/dns/constants/_flags_ednsflag.py
new file mode 100644
index 0000000..35ca3de
--- /dev/null
+++ b/dns/constants/_flags_ednsflag.py
@@ -0,0 +1,5 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+#
+# This is a generated file, do not edit.
+
+DO = 32768
diff --git a/dns/constants/_flags_flag.py b/dns/constants/_flags_flag.py
new file mode 100644
index 0000000..7280943
--- /dev/null
+++ b/dns/constants/_flags_flag.py
@@ -0,0 +1,11 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+#
+# This is a generated file, do not edit.
+
+QR = 32768
+AA = 1024
+TC = 512
+RD = 256
+RA = 128
+AD = 32
+CD = 16
diff --git a/dns/constants/_message_messagesection.py b/dns/constants/_message_messagesection.py
new file mode 100644
index 0000000..b8af789
--- /dev/null
+++ b/dns/constants/_message_messagesection.py
@@ -0,0 +1,8 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+#
+# This is a generated file, do not edit.
+
+QUESTION = 0
+ANSWER = 1
+AUTHORITY = 2
+ADDITIONAL = 3
diff --git a/dns/constants/_opcode_opcode.py b/dns/constants/_opcode_opcode.py
new file mode 100644
index 0000000..9faceb6
--- /dev/null
+++ b/dns/constants/_opcode_opcode.py
@@ -0,0 +1,9 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+#
+# This is a generated file, do not edit.
+
+QUERY = 0
+IQUERY = 1
+STATUS = 2
+NOTIFY = 4
+UPDATE = 5
diff --git a/dns/constants/_rcode_rcode.py b/dns/constants/_rcode_rcode.py
new file mode 100644
index 0000000..ab6db3a
--- /dev/null
+++ b/dns/constants/_rcode_rcode.py
@@ -0,0 +1,25 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+#
+# This is a generated file, do not edit.
+
+NOERROR = 0
+FORMERR = 1
+SERVFAIL = 2
+NXDOMAIN = 3
+NOTIMP = 4
+REFUSED = 5
+YXDOMAIN = 6
+YXRRSET = 7
+NXRRSET = 8
+NOTAUTH = 9
+NOTZONE = 10
+DSOTYPENI = 11
+BADVERS = 16
+BADSIG = 16
+BADKEY = 17
+BADTIME = 18
+BADMODE = 19
+BADNAME = 20
+BADALG = 21
+BADTRUNC = 22
+BADCOOKIE = 23
diff --git a/dns/constants/_rdataclass_rdataclass.py b/dns/constants/_rdataclass_rdataclass.py
new file mode 100644
index 0000000..a0f57fc
--- /dev/null
+++ b/dns/constants/_rdataclass_rdataclass.py
@@ -0,0 +1,13 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+#
+# This is a generated file, do not edit.
+
+RESERVED0 = 0
+IN = 1
+INTERNET = 1
+CH = 3
+CHAOS = 3
+HS = 4
+HESIOD = 4
+NONE = 254
+ANY = 255
diff --git a/dns/constants/_rdatatype_rdatatype.py b/dns/constants/_rdatatype_rdatatype.py
new file mode 100644
index 0000000..0764104
--- /dev/null
+++ b/dns/constants/_rdatatype_rdatatype.py
@@ -0,0 +1,77 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+#
+# This is a generated file, do not edit.
+
+TYPE0 = 0
+NONE = 0
+A = 1
+NS = 2
+MD = 3
+MF = 4
+CNAME = 5
+SOA = 6
+MB = 7
+MG = 8
+MR = 9
+NULL = 10
+WKS = 11
+PTR = 12
+HINFO = 13
+MINFO = 14
+MX = 15
+TXT = 16
+RP = 17
+AFSDB = 18
+X25 = 19
+ISDN = 20
+RT = 21
+NSAP = 22
+NSAP_PTR = 23
+SIG = 24
+KEY = 25
+PX = 26
+GPOS = 27
+AAAA = 28
+LOC = 29
+NXT = 30
+SRV = 33
+NAPTR = 35
+KX = 36
+CERT = 37
+A6 = 38
+DNAME = 39
+OPT = 41
+APL = 42
+DS = 43
+SSHFP = 44
+IPSECKEY = 45
+RRSIG = 46
+NSEC = 47
+DNSKEY = 48
+DHCID = 49
+NSEC3 = 50
+NSEC3PARAM = 51
+TLSA = 52
+HIP = 55
+NINFO = 56
+CDS = 59
+CDNSKEY = 60
+OPENPGPKEY = 61
+CSYNC = 62
+SPF = 99
+UNSPEC = 103
+EUI48 = 108
+EUI64 = 109
+TKEY = 249
+TSIG = 250
+IXFR = 251
+AXFR = 252
+MAILB = 253
+MAILA = 254
+ANY = 255
+URI = 256
+CAA = 257
+AVC = 258
+AMTRELAY = 259
+TA = 32768
+DLV = 32769
diff --git a/dns/constants/_rdtypes_dnskeybase_flag.py b/dns/constants/_rdtypes_dnskeybase_flag.py
new file mode 100644
index 0000000..360a3c3
--- /dev/null
+++ b/dns/constants/_rdtypes_dnskeybase_flag.py
@@ -0,0 +1,7 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+#
+# This is a generated file, do not edit.
+
+SEP = 1
+REVOKE = 128
+ZONE = 256
diff --git a/dns/constants/_update_updatesection.py b/dns/constants/_update_updatesection.py
new file mode 100644
index 0000000..3779944
--- /dev/null
+++ b/dns/constants/_update_updatesection.py
@@ -0,0 +1,8 @@
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+#
+# This is a generated file, do not edit.
+
+ZONE = 0
+PREREQ = 1
+UPDATE = 2
+ADDITIONAL = 3
diff --git a/dns/dnssec.py b/dns/dnssec.py
index 8919996..411cb12 100644
--- a/dns/dnssec.py
+++ b/dns/dnssec.py
@@ -63,8 +63,9 @@ class Algorithm(dns.enum.IntEnum):
def _maximum(cls):
return 255
-
-globals().update(Algorithm.__members__)
+# pylint: disable=C0413,W0401,W0614
+from dns.constants._dnssec_algorithm import * # noqa
+# pylint: enable=C0413,W0401,W0614
def algorithm_from_text(text):
diff --git a/dns/edns.py b/dns/edns.py
index 087592b..d3a40f4 100644
--- a/dns/edns.py
+++ b/dns/edns.py
@@ -50,7 +50,10 @@ class OptionType(dns.enum.IntEnum):
def _maximum(cls):
return 65535
-globals().update(OptionType.__members__)
+# pylint: disable=C0413,W0401,W0614
+from dns.constants._edns_optiontype import * # noqa
+# pylint: enable=C0413,W0401,W0614
+
class Option:
diff --git a/dns/flags.py b/dns/flags.py
index 4eb6d90..589f4d8 100644
--- a/dns/flags.py
+++ b/dns/flags.py
@@ -37,18 +37,16 @@ class Flag(enum.IntFlag):
#: Checking Disabled
CD = 0x0010
-globals().update(Flag.__members__)
-
-
# EDNS flags
class EDNSFlag(enum.IntFlag):
#: DNSSEC answer OK
DO = 0x8000
-
-globals().update(EDNSFlag.__members__)
-
+# pylint: disable=C0413,W0401,W0614
+from dns.constants._flags_flag import * # noqa
+from dns.constants._flags_ednsflag import * # noqa
+# pylint: enable=C0413,W0401,W0614
def _from_text(text, enum_class):
flags = 0
diff --git a/dns/message.py b/dns/message.py
index 1dfb028..1f32e86 100644
--- a/dns/message.py
+++ b/dns/message.py
@@ -107,7 +107,9 @@ class MessageSection(dns.enum.IntEnum):
def _maximum(cls):
return 3
-globals().update(MessageSection.__members__)
+# pylint: disable=C0413,W0401,W0614
+from dns.constants._message_messagesection import * # noqa
+# pylint: enable=C0413,W0401,W0614
DEFAULT_EDNS_PAYLOAD = 1232
MAX_CHAIN = 16
diff --git a/dns/opcode.py b/dns/opcode.py
index 5a76326..0bd6526 100644
--- a/dns/opcode.py
+++ b/dns/opcode.py
@@ -40,7 +40,9 @@ class Opcode(dns.enum.IntEnum):
def _unknown_exception_class(cls):
return UnknownOpcode
-globals().update(Opcode.__members__)
+# pylint: disable=C0413,W0401,W0614
+from dns.constants._opcode_opcode import * # noqa
+# pylint: enable=C0413,W0401,W0614
class UnknownOpcode(dns.exception.DNSException):
diff --git a/dns/rcode.py b/dns/rcode.py
index 846bf6d..3206b06 100644
--- a/dns/rcode.py
+++ b/dns/rcode.py
@@ -72,7 +72,9 @@ class Rcode(dns.enum.IntEnum):
def _unknown_exception_class(cls):
return UnknownRcode
-globals().update(Rcode.__members__)
+# pylint: disable=C0413,W0401,W0614
+from dns.constants._rcode_rcode import * # noqa
+# pylint: enable=C0413,W0401,W0614
class UnknownRcode(dns.exception.DNSException):
"""A DNS rcode is unknown."""
diff --git a/dns/rdataclass.py b/dns/rdataclass.py
index 7943a95..4ec41e3 100644
--- a/dns/rdataclass.py
+++ b/dns/rdataclass.py
@@ -48,7 +48,9 @@ class RdataClass(dns.enum.IntEnum):
def _unknown_exception_class(cls):
return UnknownRdataclass
-globals().update(RdataClass.__members__)
+# pylint: disable=C0413,W0401,W0614
+from dns.constants._rdataclass_rdataclass import * # noqa
+# pylint: enable=C0413,W0401,W0614
_metaclasses = {RdataClass.NONE, RdataClass.ANY}
diff --git a/dns/rdatatype.py b/dns/rdatatype.py
index c793d5a..8cf60e6 100644
--- a/dns/rdatatype.py
+++ b/dns/rdatatype.py
@@ -115,7 +115,9 @@ class RdataType(dns.enum.IntEnum):
_registered_by_text = {}
_registered_by_value = {}
-globals().update(RdataType.__members__)
+# pylint: disable=C0413,W0401,W0614
+from dns.constants._rdatatype_rdatatype import * # noqa
+# pylint: enable=C0413,W0401,W0614
_metatypes = {RdataType.OPT}
diff --git a/dns/rdtypes/dnskeybase.py b/dns/rdtypes/dnskeybase.py
index 0243d6f..66a13d8 100644
--- a/dns/rdtypes/dnskeybase.py
+++ b/dns/rdtypes/dnskeybase.py
@@ -23,15 +23,18 @@ import dns.exception
import dns.dnssec
import dns.rdata
-# wildcard import
-__all__ = ["SEP", "REVOKE", "ZONE"] # noqa: F822
class Flag(enum.IntFlag):
SEP = 0x0001
REVOKE = 0x0080
ZONE = 0x0100
-globals().update(Flag.__members__)
+# pylint: disable=C0413,W0401,W0614
+from dns.constants._rdtypes_dnskeybase_flag import * # noqa
+# pylint: enable=C0413,W0401,W0614
+
+# wildcard import
+__all__ = ["SEP", "REVOKE", "ZONE"] # noqa: F822,F405
class DNSKEYBase(dns.rdata.Rdata):
diff --git a/dns/update.py b/dns/update.py
index 8e79650..ac1557c 100644
--- a/dns/update.py
+++ b/dns/update.py
@@ -38,7 +38,9 @@ class UpdateSection(dns.enum.IntEnum):
def _maximum(cls):
return 3
-globals().update(UpdateSection.__members__)
+# pylint: disable=C0413,W0401,W0614
+from dns.constants._update_updatesection import * # noqa
+# pylint: enable=C0413,W0401,W0614
class UpdateMessage(dns.message.Message):
diff --git a/setup.py b/setup.py
index d7d965d..ff63867 100755
--- a/setup.py
+++ b/setup.py
@@ -50,7 +50,7 @@ direct manipulation of DNS zones, messages, names, and records.""",
'license' : 'ISC',
'url' : 'http://www.dnspython.org',
'packages' : ['dns', 'dns.rdtypes', 'dns.rdtypes.IN', 'dns.rdtypes.ANY',
- 'dns.rdtypes.CH'],
+ 'dns.rdtypes.CH', 'dns.constants'],
'package_data' : {'dns': ['py.typed']},
'download_url' : \
'http://www.dnspython.org/kits/{}/dnspython-{}.tar.gz'.format(version, version),
diff --git a/tests/test_flags.py b/tests/test_flags.py
index 3f5fc69..b5554b2 100644
--- a/tests/test_flags.py
+++ b/tests/test_flags.py
@@ -57,13 +57,13 @@ class FlagsTestCase(unittest.TestCase):
self.assertEqual(dns.flags.to_text(flags), "QR AA RD RA")
def test_rcode_badvers(self):
- rcode = dns.rcode.BADVERS
+ rcode = dns.rcode.Rcode.BADVERS
self.assertEqual(rcode.value, 16)
self.assertEqual(rcode.name, 'BADVERS')
self.assertEqual(dns.rcode.to_text(rcode), 'BADVERS')
def test_rcode_badsig(self):
- rcode = dns.rcode.BADSIG
+ rcode = dns.rcode.Rcode.BADSIG
self.assertEqual(rcode.value, 16)
# Yes, we mean BADVERS on the next line. BADSIG and BADVERS have
# the same code.
diff --git a/util/constants-tool b/util/constants-tool
new file mode 100755
index 0000000..952d5c8
--- /dev/null
+++ b/util/constants-tool
@@ -0,0 +1,79 @@
+#!/usr/bin/env python3
+
+# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
+
+from importlib import import_module
+import sys
+
+enum_names = [
+ 'dns.dnssec.Algorithm',
+ 'dns.edns.OptionType',
+ 'dns.flags.Flag',
+ 'dns.flags.EDNSFlag',
+ 'dns.message.MessageSection',
+ 'dns.opcode.Opcode',
+ 'dns.rcode.Rcode',
+ 'dns.rdataclass.RdataClass',
+ 'dns.rdatatype.RdataType',
+ 'dns.rdtypes.dnskeybase.Flag',
+ 'dns.update.UpdateSection',
+]
+
+def generate():
+ for enum_name in enum_names:
+ dot = enum_name.rindex('.')
+ module_name = enum_name[:dot]
+ type_name = enum_name[dot + 1:]
+ mod = import_module(module_name)
+ enum = getattr(mod, type_name)
+ mname = module_name.lower().replace('.', '_')
+ mname = mname[4:] # strip off 'dns.' too
+ tname = type_name.lower()
+ with open(f'dns/constants/_{mname}_{tname}.py', 'w') as f:
+ print('# Copyright (C) Dnspython Contributors, see LICENSE ' +
+ 'for text of ISC license', file=f)
+ print('#\n# This is a generated file, do not edit.\n', file=f)
+ # We have to use __members__.items() and not "in enum" because
+ # otherwise we miss values that have multiple names (e.g. NONE
+ # and TYPE0 for rdatatypes).
+ for name, value in enum.__members__.items():
+ print(f'{name} = {value}', file=f)
+
+def check():
+ ok = True
+ for enum_name in enum_names:
+ dot = enum_name.rindex('.')
+ module_name = enum_name[:dot]
+ type_name = enum_name[dot + 1:]
+ mod = import_module(module_name)
+ enum = getattr(mod, type_name)
+ mname = module_name.lower()[4:] # strip off 'dns.' too
+ tname = type_name.lower()
+ cmod = import_module(f'dns.constants._{mname}_{tname}')
+ for name, value in enum.__members__.items():
+ try:
+ if value != getattr(cmod, name):
+ ok = False
+ print(f'{name} != {value}', file=sys.stderr)
+ except Exception:
+ ok = False
+ print('exception checking', name, file=sys.stderr)
+ return ok
+
+def usage():
+ print('usage: constants-tool [generate|check]', file=sys.stderr)
+ sys.exit(1)
+
+def main():
+ if len(sys.argv) < 2:
+ usage()
+ if sys.argv[1] == 'generate':
+ generate()
+ elif sys.argv[1] == 'check':
+ if not check():
+ sys.exit(2)
+ else:
+ usage()
+
+if __name__ == '__main__':
+ main()