summaryrefslogtreecommitdiff
path: root/dns/opcode.py
diff options
context:
space:
mode:
authorBrian Wellington <bwelling@xbill.org>2020-05-19 13:18:05 -0700
committerBrian Wellington <bwelling@xbill.org>2020-05-19 13:18:05 -0700
commit044c8afd92070648f3e76ed054be69d264f114c2 (patch)
tree075003f55cf0a034d52c183ed9f07b37f1000503 /dns/opcode.py
parent2df0596e9405049faae662b6cfcb687dae3eb001 (diff)
downloaddnspython-044c8afd92070648f3e76ed054be69d264f114c2.tar.gz
Enum refactoring.
Consolidate the common methods related to enum classes.
Diffstat (limited to 'dns/opcode.py')
-rw-r--r--dns/opcode.py30
1 files changed, 12 insertions, 18 deletions
diff --git a/dns/opcode.py b/dns/opcode.py
index d81d255..509916e 100644
--- a/dns/opcode.py
+++ b/dns/opcode.py
@@ -17,11 +17,10 @@
"""DNS Opcodes."""
-import enum
-
+import dns.enum
import dns.exception
-class Opcode(enum.IntEnum):
+class Opcode(dns.enum.IntEnum):
#: Query
QUERY = 0
#: Inverse Query (historical)
@@ -33,6 +32,14 @@ class Opcode(enum.IntEnum):
#: Dynamic Update
UPDATE = 5
+ @classmethod
+ def _maximum(cls):
+ return 15
+
+ @classmethod
+ def _unknown_exception_class(cls):
+ return UnknownOpcode
+
globals().update(Opcode.__members__)
@@ -50,17 +57,7 @@ def from_text(text):
Returns an ``int``.
"""
- if text.isdigit():
- value = int(text)
- if value >= 0 and value <= 15:
- try:
- return Opcode(value)
- except ValueError:
- return value
- try:
- return Opcode[text.upper()]
- except KeyError:
- raise UnknownOpcode
+ return Opcode.from_text(text)
def from_flags(flags):
@@ -96,10 +93,7 @@ def to_text(value):
Returns a ``str``.
"""
- try:
- return Opcode(value).name
- except ValueError:
- return str(value)
+ return Opcode.to_text(value)
def is_update(flags):