diff options
Diffstat (limited to 'eventlet/support/dns/rcode.py')
| -rw-r--r-- | eventlet/support/dns/rcode.py | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/eventlet/support/dns/rcode.py b/eventlet/support/dns/rcode.py index 314815f..eb4d1d6 100644 --- a/eventlet/support/dns/rcode.py +++ b/eventlet/support/dns/rcode.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, @@ -18,18 +18,29 @@ import dns.exception from ._compat import long - +#: No error NOERROR = 0 +#: Form error FORMERR = 1 +#: Server failure SERVFAIL = 2 +#: Name does not exist ("Name Error" in RFC 1025 terminology). NXDOMAIN = 3 +#: Not implemented NOTIMP = 4 +#: Refused REFUSED = 5 +#: Name exists. YXDOMAIN = 6 +#: RRset exists. YXRRSET = 7 +#: RRset does not exist. NXRRSET = 8 +#: Not authoritative. NOTAUTH = 9 +#: Name not in zone. NOTZONE = 10 +#: Bad EDNS version. BADVERS = 16 _by_text = { @@ -55,17 +66,17 @@ _by_value = dict((y, x) for x, y in _by_text.items()) class UnknownRcode(dns.exception.DNSException): - """A DNS rcode is unknown.""" def from_text(text): """Convert text into an rcode. - @param text: the textual rcode - @type text: string - @raises UnknownRcode: the rcode is unknown - @rtype: int + *text*, a ``text``, the textual rcode or an integer in textual form. + + Raises ``dns.rcode.UnknownRcode`` if the rcode mnemonic is unknown. + + Returns an ``int``. """ if text.isdigit(): @@ -81,12 +92,13 @@ def from_text(text): def from_flags(flags, ednsflags): """Return the rcode value encoded by flags and ednsflags. - @param flags: the DNS flags - @type flags: int - @param ednsflags: the EDNS flags - @type ednsflags: int - @raises ValueError: rcode is < 0 or > 4095 - @rtype: int + *flags*, an ``int``, the DNS flags field. + + *ednsflags*, an ``int``, the EDNS flags field. + + Raises ``ValueError`` if rcode is < 0 or > 4095 + + Returns an ``int``. """ value = (flags & 0x000f) | ((ednsflags >> 20) & 0xff0) @@ -98,10 +110,11 @@ def from_flags(flags, ednsflags): def to_flags(value): """Return a (flags, ednsflags) tuple which encodes the rcode. - @param value: the rcode - @type value: int - @raises ValueError: rcode is < 0 or > 4095 - @rtype: (int, int) tuple + *value*, an ``int``, the rcode. + + Raises ``ValueError`` if rcode is < 0 or > 4095. + + Returns an ``(int, int)`` tuple. """ if value < 0 or value > 4095: @@ -114,11 +127,15 @@ def to_flags(value): def to_text(value): """Convert rcode into text. - @param value: the rcode - @type value: int - @rtype: string + *value*, and ``int``, the rcode. + + Raises ``ValueError`` if rcode is < 0 or > 4095. + + Returns a ``text``. """ + if value < 0 or value > 4095: + raise ValueError('rcode must be >= 0 and <= 4095') text = _by_value.get(value) if text is None: text = str(value) |
