-# 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,
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-"""DNS Rdata Types.
-
-@var _by_text: The rdata type textual name to value mapping
-@type _by_text: dict
-@var _by_value: The rdata type value to textual name mapping
-@type _by_value: dict
-@var _metatypes: If an rdatatype is a metatype, there will be a mapping
-whose key is the rdatatype value and whose value is True in this dictionary.
-@type _metatypes: dict
-@var _singletons: If an rdatatype is a singleton, there will be a mapping
-whose key is the rdatatype value and whose value is True in this dictionary.
-@type _singletons: dict"""
+"""DNS Rdata Types."""
import re
_by_value = dict((y, x) for x, y in _by_text.items())
-
_metatypes = {
OPT: True
}
NXT: True,
DNAME: True,
NSEC: True,
- # CNAME is technically a singleton, but we allow multiple CNAMEs.
+ CNAME: True,
}
_unknown_type_pattern = re.compile('TYPE([0-9]+)$', re.I)
class UnknownRdatatype(dns.exception.DNSException):
-
"""DNS resource record type is unknown."""
def from_text(text):
"""Convert text into a DNS rdata type value.
- @param text: the text
- @type text: string
- @raises dns.rdatatype.UnknownRdatatype: the type is unknown
- @raises ValueError: the rdata type value is not >= 0 and <= 65535
- @rtype: int"""
+
+ The input text can be a defined DNS RR type mnemonic or
+ instance of the DNS generic type syntax.
+
+ For example, "NS" and "TYPE2" will both result in a value of 2.
+
+ Raises ``dns.rdatatype.UnknownRdatatype`` if the type is unknown.
+
+ Raises ``ValueError`` if the rdata type value is not >= 0 and <= 65535.
+
+ Returns an ``int``.
+ """
value = _by_text.get(text.upper())
if value is None:
def to_text(value):
- """Convert a DNS rdata type to text.
- @param value: the rdata type value
- @type value: int
- @raises ValueError: the rdata type value is not >= 0 and <= 65535
- @rtype: string"""
+ """Convert a DNS rdata type value to text.
+
+ If the value has a known mnemonic, it will be used, otherwise the
+ DNS generic type syntax will be used.
+
+ Raises ``ValueError`` if the rdata type value is not >= 0 and <= 65535.
+
+ Returns a ``str``.
+ """
if value < 0 or value > 65535:
raise ValueError("type must be between >= 0 and <= 65535")
def is_metatype(rdtype):
- """True if the type is a metatype.
- @param rdtype: the type
- @type rdtype: int
- @rtype: bool"""
+ """True if the specified type is a metatype.
+
+ *rdtype* is an ``int``.
+
+ The currently defined metatypes are TKEY, TSIG, IXFR, AXFR, MAILA,
+ MAILB, ANY, and OPT.
+
+ Returns a ``bool``.
+ """
if rdtype >= TKEY and rdtype <= ANY or rdtype in _metatypes:
return True
def is_singleton(rdtype):
- """True if the type is a singleton.
- @param rdtype: the type
- @type rdtype: int
- @rtype: bool"""
+ """Is the specified type a singleton type?
+
+ Singleton types can only have a single rdata in an rdataset, or a single
+ RR in an RRset.
+
+ The currently defined singleton types are CNAME, DNAME, NSEC, NXT, and
+ SOA.
+
+ *rdtype* is an ``int``.
+
+ Returns a ``bool``.
+ """
if rdtype in _singletons:
return True