summaryrefslogtreecommitdiff
path: root/eventlet/support/dns/opcode.py
diff options
context:
space:
mode:
Diffstat (limited to 'eventlet/support/dns/opcode.py')
-rw-r--r--eventlet/support/dns/opcode.py44
1 files changed, 27 insertions, 17 deletions
diff --git a/eventlet/support/dns/opcode.py b/eventlet/support/dns/opcode.py
index 70d704f..5dcd2ab 100644
--- a/eventlet/support/dns/opcode.py
+++ b/eventlet/support/dns/opcode.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2007, 2009-2011 Nominum, Inc.
+# Copyright (C) 2001-2017 Nominum, Inc.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose with or without fee is hereby granted,
@@ -17,10 +17,15 @@
import dns.exception
+#: Query
QUERY = 0
+#: Inverse Query (historical)
IQUERY = 1
+#: Server Status (unspecified and unimplemented anywhere)
STATUS = 2
+#: Notify
NOTIFY = 4
+#: Dynamic Update
UPDATE = 5
_by_text = {
@@ -39,17 +44,17 @@ _by_value = dict((y, x) for x, y in _by_text.items())
class UnknownOpcode(dns.exception.DNSException):
-
"""An DNS opcode is unknown."""
def from_text(text):
"""Convert text into an opcode.
- @param text: the textual opcode
- @type text: string
- @raises UnknownOpcode: the opcode is unknown
- @rtype: int
+ *text*, a ``text``, the textual opcode
+
+ Raises ``dns.opcode.UnknownOpcode`` if the opcode is unknown.
+
+ Returns an ``int``.
"""
if text.isdigit():
@@ -65,8 +70,9 @@ def from_text(text):
def from_flags(flags):
"""Extract an opcode from DNS message flags.
- @param flags: int
- @rtype: int
+ *flags*, an ``int``, the DNS flags.
+
+ Returns an ``int``.
"""
return (flags & 0x7800) >> 11
@@ -75,7 +81,10 @@ def from_flags(flags):
def to_flags(value):
"""Convert an opcode to a value suitable for ORing into DNS message
flags.
- @rtype: int
+
+ *value*, an ``int``, the DNS opcode value.
+
+ Returns an ``int``.
"""
return (value << 11) & 0x7800
@@ -84,10 +93,11 @@ def to_flags(value):
def to_text(value):
"""Convert an opcode to text.
- @param value: the opcdoe
- @type value: int
- @raises UnknownOpcode: the opcode is unknown
- @rtype: string
+ *value*, an ``int`` the opcode value,
+
+ Raises ``dns.opcode.UnknownOpcode`` if the opcode is unknown.
+
+ Returns a ``text``.
"""
text = _by_value.get(value)
@@ -97,11 +107,11 @@ def to_text(value):
def is_update(flags):
- """True if the opcode in flags is UPDATE.
+ """Is the opcode in flags UPDATE?
+
+ *flags*, an ``int``, the DNS message flags.
- @param flags: DNS flags
- @type flags: int
- @rtype: bool
+ Returns a ``bool``.
"""
return from_flags(flags) == UPDATE