mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 15:32:38 -07:00
Update dnspython-2.2.0
This commit is contained in:
parent
4b28040d59
commit
4d62245cf5
111 changed files with 9077 additions and 5877 deletions
148
lib/dns/rcode.py
148
lib/dns/rcode.py
|
@ -1,4 +1,6 @@
|
|||
# Copyright (C) 2001-2007, 2009-2011 Nominum, Inc.
|
||||
# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
|
||||
|
||||
# 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,
|
||||
|
@ -15,78 +17,90 @@
|
|||
|
||||
"""DNS Result Codes."""
|
||||
|
||||
import dns.enum
|
||||
import dns.exception
|
||||
from ._compat import long
|
||||
|
||||
class Rcode(dns.enum.IntEnum):
|
||||
#: No error
|
||||
NOERROR = 0
|
||||
#: Format 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
|
||||
#: DSO-TYPE Not Implemented
|
||||
DSOTYPENI = 11
|
||||
#: Bad EDNS version.
|
||||
BADVERS = 16
|
||||
#: TSIG Signature Failure
|
||||
BADSIG = 16
|
||||
#: Key not recognized.
|
||||
BADKEY = 17
|
||||
#: Signature out of time window.
|
||||
BADTIME = 18
|
||||
#: Bad TKEY Mode.
|
||||
BADMODE = 19
|
||||
#: Duplicate key name.
|
||||
BADNAME = 20
|
||||
#: Algorithm not supported.
|
||||
BADALG = 21
|
||||
#: Bad Truncation
|
||||
BADTRUNC = 22
|
||||
#: Bad/missing Server Cookie
|
||||
BADCOOKIE = 23
|
||||
|
||||
NOERROR = 0
|
||||
FORMERR = 1
|
||||
SERVFAIL = 2
|
||||
NXDOMAIN = 3
|
||||
NOTIMP = 4
|
||||
REFUSED = 5
|
||||
YXDOMAIN = 6
|
||||
YXRRSET = 7
|
||||
NXRRSET = 8
|
||||
NOTAUTH = 9
|
||||
NOTZONE = 10
|
||||
BADVERS = 16
|
||||
@classmethod
|
||||
def _maximum(cls):
|
||||
return 4095
|
||||
|
||||
_by_text = {
|
||||
'NOERROR': NOERROR,
|
||||
'FORMERR': FORMERR,
|
||||
'SERVFAIL': SERVFAIL,
|
||||
'NXDOMAIN': NXDOMAIN,
|
||||
'NOTIMP': NOTIMP,
|
||||
'REFUSED': REFUSED,
|
||||
'YXDOMAIN': YXDOMAIN,
|
||||
'YXRRSET': YXRRSET,
|
||||
'NXRRSET': NXRRSET,
|
||||
'NOTAUTH': NOTAUTH,
|
||||
'NOTZONE': NOTZONE,
|
||||
'BADVERS': BADVERS
|
||||
}
|
||||
|
||||
# We construct the inverse mapping programmatically to ensure that we
|
||||
# cannot make any mistakes (e.g. omissions, cut-and-paste errors) that
|
||||
# would cause the mapping not to be a true inverse.
|
||||
|
||||
_by_value = dict((y, x) for x, y in _by_text.items())
|
||||
@classmethod
|
||||
def _unknown_exception_class(cls):
|
||||
return UnknownRcode
|
||||
|
||||
globals().update(Rcode.__members__)
|
||||
|
||||
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 ``str``, 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():
|
||||
v = int(text)
|
||||
if v >= 0 and v <= 4095:
|
||||
return v
|
||||
v = _by_text.get(text.upper())
|
||||
if v is None:
|
||||
raise UnknownRcode
|
||||
return v
|
||||
return Rcode.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,28 +112,30 @@ 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:
|
||||
raise ValueError('rcode must be >= 0 and <= 4095')
|
||||
v = value & 0xf
|
||||
ev = long(value & 0xff0) << 20
|
||||
ev = (value & 0xff0) << 20
|
||||
return (v, ev)
|
||||
|
||||
|
||||
def to_text(value):
|
||||
def to_text(value, tsig=False):
|
||||
"""Convert rcode into text.
|
||||
|
||||
@param value: the rcode
|
||||
@type value: int
|
||||
@rtype: string
|
||||
*value*, an ``int``, the rcode.
|
||||
|
||||
Raises ``ValueError`` if rcode is < 0 or > 4095.
|
||||
|
||||
Returns a ``str``.
|
||||
"""
|
||||
|
||||
text = _by_value.get(value)
|
||||
if text is None:
|
||||
text = str(value)
|
||||
return text
|
||||
if tsig and value == Rcode.BADVERS:
|
||||
return 'BADSIG'
|
||||
return Rcode.to_text(value)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue