-# 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,
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 = {
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():
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)
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:
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)
"""Create an rdataset with the specified class, type, and TTL, and with
the specified list of rdatas in text format.
- @rtype: dns.rdataset.Rdataset object
+ Returns a ``dns.rdataset.Rdataset`` object.
"""
if isinstance(rdclass, string_types):
"""Create an rdataset with the specified class, type, and TTL, and with
the specified rdatas in text format.
- @rtype: dns.rdataset.Rdataset object
+ Returns a ``dns.rdataset.Rdataset`` object.
"""
return from_text_list(rdclass, rdtype, ttl, text_rdatas)
"""Create an rdataset with the specified TTL, and with
the specified list of rdata objects.
- @rtype: dns.rdataset.Rdataset object
+ Returns a ``dns.rdataset.Rdataset`` object.
"""
if len(rdatas) == 0:
"""Create an rdataset with the specified TTL, and with
the specified rdata objects.
- @rtype: dns.rdataset.Rdataset object
+ Returns a ``dns.rdataset.Rdataset`` object.
"""
return from_rdata_list(ttl, rdatas)
"""Create an RRset with the specified name, TTL, class, and type, and with
the specified list of rdatas in text format.
- @rtype: dns.rrset.RRset object
+ Returns a ``dns.rrset.RRset`` object.
"""
if isinstance(name, string_types):
"""Create an RRset with the specified name, TTL, class, and type and with
the specified rdatas in text format.
- @rtype: dns.rrset.RRset object
+ Returns a ``dns.rrset.RRset`` object.
"""
return from_text_list(name, ttl, rdclass, rdtype, text_rdatas)
"""Create an RRset with the specified name and TTL, and with
the specified list of rdata objects.
- @rtype: dns.rrset.RRset object
+ Returns a ``dns.rrset.RRset`` object.
"""
if isinstance(name, string_types):
"""Create an RRset with the specified name and TTL, and with
the specified rdata objects.
- @rtype: dns.rrset.RRset object
+ Returns a ``dns.rrset.RRset`` object.
"""
return from_rdata_list(name, ttl, rdatas)
.. _exceptions:
+Exceptions
+==========
+
Common Exceptions
-=================
+-----------------
.. automodule:: dns.exception
:members:
dns.name Exceptions
-===================
+-------------------
.. autoexception:: dns.name.AbsoluteConcatenation
.. autoexception:: dns.name.BadEscape
.. autoexception:: dns.name.NoIDNA2008
.. autoexception:: dns.name.NoParent
+dns.rcode Exceptions
+--------------------
+
+.. autoexception:: dns.rcode.UnknownRcode
+
dns.rdataset Exceptions
-=======================
+-----------------------
.. autoexception:: dns.rdataset.DifferingCovers
.. autoexception:: dns.rdataset.IncompatibleTypes
.. _rdata-set-classes:
-DNS Rdataset Class
-==================
+Rdataset and RRset Classes
+==========================
An ``Rdataset`` is a set of ``Rdata`` objects which all have the same
rdatatype, rdataclass, and covered type. ``Rdatasets`` also have a