]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
doc overhaul for rdatatypes; make CNAME singleton
authorBob Halley <halley@dnspython.org>
Sun, 1 Jan 2017 17:28:42 +0000 (09:28 -0800)
committerBob Halley <halley@dnspython.org>
Sun, 1 Jan 2017 17:28:42 +0000 (09:28 -0800)
ChangeLog
dns/rdatatype.py

index b62d7882fcb91294c11101b1c201576007ef2724..87d1da9870b6ed3b5dfda4f036cb7b95d079f426 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-01-01  Bob Halley  <halley@dnspython.org>
+
+       * dns/rdatatype.py: CNAME is now a singleton, as the reasons
+         for permitting multiple CNAMEs are now largely historical.
+
 2016-11-15  Bob Halley  <halley@dnspython.org>
 
        * Fixed regression where trailing zeros in APL RRs were not
index 33a7461bd1c6b135ccf9ae9691b1e2b04c7c97dd..48d2aa6706f559eb1628228e140e3e508bad2988 100644 (file)
@@ -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,
 # 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
 
@@ -180,7 +169,6 @@ _by_text = {
 
 _by_value = dict((y, x) for x, y in _by_text.items())
 
-
 _metatypes = {
     OPT: True
 }
@@ -190,24 +178,30 @@ _singletons = {
     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:
@@ -221,11 +215,15 @@ def from_text(text):
 
 
 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")
@@ -236,10 +234,15 @@ def to_text(value):
 
 
 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
@@ -247,10 +250,18 @@ def is_metatype(rdtype):
 
 
 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