]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
more doco overhaul
authorBob Halley <halley@dnspython.org>
Sun, 15 Jan 2017 14:10:09 +0000 (06:10 -0800)
committerBob Halley <halley@dnspython.org>
Sun, 15 Jan 2017 14:10:09 +0000 (06:10 -0800)
dns/edns.py
dns/flags.py
dns/opcode.py
doc/exceptions.rst
doc/message-edns.rst [new file with mode: 0644]
doc/message-flags.rst [new file with mode: 0644]
doc/message-opcode.rst [new file with mode: 0644]
doc/message-rcode.rst [new file with mode: 0644]
doc/message.rst

index 36ed06df0cf38596f21d30eba51c7d4e9d7216df..22104d8702ff67a3f6f014d032ffc2794d53f79e 100644 (file)
@@ -22,10 +22,26 @@ import struct
 
 import dns.inet
 
-
+#: NSID
 NSID = 3
+#: DAU
+DAU = 5
+#: DHU
+DHU = 6
+#: N3U
+N3U = 7
+#: ECS (client-subnet)
 ECS = 8
-
+#: EXPIRE
+EXPIRE = 9
+#: COOKIE
+COOKIE = 10
+#: KEEPALIVE
+KEEPALIVE = 11
+#: PADDING
+PADDING = 12
+#: CHAIN
+CHAIN = 13
 
 class Option(object):
 
@@ -220,6 +236,12 @@ _type_to_class = {
 }
 
 def get_option_class(otype):
+    """Return the class for the specified option type.
+
+    The GenericOption class is used if a more specific class is not
+    known.
+    """
+
     cls = _type_to_class.get(otype)
     if cls is None:
         cls = GenericOption
index e1d993bfa775d791acf872cd93b42fe5bc4884fa..f9a62b3625c7d9ac8387666554dc1c80e0bab050 100644 (file)
@@ -91,7 +91,9 @@ def _to_text(flags, table, order):
 def from_text(text):
     """Convert a space-separated list of flag text values into a flags
     value.
-    @rtype: int"""
+
+    Returns an ``int``
+    """
 
     return _from_text(text, _by_text)
 
@@ -99,7 +101,9 @@ def from_text(text):
 def to_text(flags):
     """Convert a flags value into a space-separated list of flag text
     values.
-    @rtype: string"""
+
+    Returns a ``text``.
+    """
 
     return _to_text(flags, _by_value, _flags_order)
 
@@ -107,7 +111,9 @@ def to_text(flags):
 def edns_from_text(text):
     """Convert a space-separated list of EDNS flag text values into a EDNS
     flags value.
-    @rtype: int"""
+
+    Returns an ``int``
+    """
 
     return _from_text(text, _edns_by_text)
 
@@ -115,6 +121,8 @@ def edns_from_text(text):
 def edns_to_text(flags):
     """Convert an EDNS flags value into a space-separated list of EDNS flag
     text values.
-    @rtype: string"""
+
+    Returns a ``text``.
+    """
 
     return _to_text(flags, _edns_by_value, _edns_flags_order)
index 70d704fb3a76f9ae86664858fd2fbd297fe41741..5dcd2abffc5b56d86c233cf52faffe580bd555a0 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,
 
 import dns.exception
 
+#: Query
 QUERY = 0
+#: Inverse Query (historical)
 IQUERY = 1
+#: Server Status (unspecified and unimplemented anywhere)
 STATUS = 2
+#: Notify
 NOTIFY = 4
+#: Dynamic Update
 UPDATE = 5
 
 _by_text = {
@@ -39,17 +44,17 @@ _by_value = dict((y, x) for x, y in _by_text.items())
 
 
 class UnknownOpcode(dns.exception.DNSException):
-
     """An DNS opcode is unknown."""
 
 
 def from_text(text):
     """Convert text into an opcode.
 
-    @param text: the textual opcode
-    @type text: string
-    @raises UnknownOpcode: the opcode is unknown
-    @rtype: int
+    *text*, a ``text``, the textual opcode
+
+    Raises ``dns.opcode.UnknownOpcode`` if the opcode is unknown.
+
+    Returns an ``int``.
     """
 
     if text.isdigit():
@@ -65,8 +70,9 @@ def from_text(text):
 def from_flags(flags):
     """Extract an opcode from DNS message flags.
 
-    @param flags: int
-    @rtype: int
+    *flags*, an ``int``, the DNS flags.
+
+    Returns an ``int``.
     """
 
     return (flags & 0x7800) >> 11
@@ -75,7 +81,10 @@ def from_flags(flags):
 def to_flags(value):
     """Convert an opcode to a value suitable for ORing into DNS message
     flags.
-    @rtype: int
+
+    *value*, an ``int``, the DNS opcode value.
+
+    Returns an ``int``.
     """
 
     return (value << 11) & 0x7800
@@ -84,10 +93,11 @@ def to_flags(value):
 def to_text(value):
     """Convert an opcode to text.
 
-    @param value: the opcdoe
-    @type value: int
-    @raises UnknownOpcode: the opcode is unknown
-    @rtype: string
+    *value*, an ``int`` the opcode value,
+
+    Raises ``dns.opcode.UnknownOpcode`` if the opcode is unknown.
+
+    Returns a ``text``.
     """
 
     text = _by_value.get(value)
@@ -97,11 +107,11 @@ def to_text(value):
 
 
 def is_update(flags):
-    """True if the opcode in flags is UPDATE.
+    """Is the opcode in flags UPDATE?
+
+    *flags*, an ``int``, the DNS message flags.
 
-    @param flags: DNS flags
-    @type flags: int
-    @rtype: bool
+    Returns a ``bool``.
     """
 
     return from_flags(flags) == UPDATE
index aebabc758115cdb5e4b422457f6d9d9ca56d6143..8f50843f6092a5e2ef4da5be3cedd5b2c0dee5b0 100644 (file)
@@ -34,6 +34,11 @@ dns.name Exceptions
 .. autoexception:: dns.name.NoIDNA2008
 .. autoexception:: dns.name.NoParent
 
+dns.opcode Exceptions
+---------------------
+
+.. autoexception:: dns.opcode.UnknownOpcode
+                   
 dns.rcode Exceptions
 --------------------
 
diff --git a/doc/message-edns.rst b/doc/message-edns.rst
new file mode 100644 (file)
index 0000000..ce4f2f8
--- /dev/null
@@ -0,0 +1,33 @@
+.. _message-edns:
+
+Message EDNS Options
+--------------------
+
+EDNS allows for larger messages and also provides an extension
+mechanism for the protocol.  EDNS *options* are typed data, and are
+treated much like Rdata.  For example, if dnsython encouters the EDNS
+``ECS`` option code when parsing a DNS wire format message, it
+will create a ``dns.edns.ECSOption`` object to represent it.
+
+.. autodata:: dns.edns.NSID
+.. autodata:: dns.edns.DAU
+.. autodata:: dns.edns.DHU
+.. autodata:: dns.edns.N3U
+.. autodata:: dns.edns.ECS
+.. autodata:: dns.edns.EXPIRE
+.. autodata:: dns.edns.COOKIE
+.. autodata:: dns.edns.KEEPALIVE
+.. autodata:: dns.edns.PADDING
+.. autodata:: dns.edns.CHAIN
+
+.. autoclass:: dns.edns.Option
+   :members:
+
+.. autoclass:: dns.edns.GenericOption
+   :members:
+
+.. autoclass:: dns.edns.ECSOption
+   :members:
+   
+.. autofunction:: dns.edns.get_option_class
+.. autofunction:: dns.edns.option_from_wire
diff --git a/doc/message-flags.rst b/doc/message-flags.rst
new file mode 100644 (file)
index 0000000..2f79343
--- /dev/null
@@ -0,0 +1,33 @@
+.. _message-flags:
+
+Message Flags
+=============
+
+DNS message flags are used for signalling of various kinds
+in the DNS protocol.  For example, the ``QR`` flag indicates
+that a message is a response to a prior query.
+
+Messages flags are encoded in two locations: the DNS header
+and the EDNS flags field.
+
+Header Flags
+------------
+
+.. autodata:: dns.flags.QR
+.. autodata:: dns.flags.AA
+.. autodata:: dns.flags.TC
+.. autodata:: dns.flags.RD
+.. autodata:: dns.flags.RA
+.. autodata:: dns.flags.AD
+.. autodata:: dns.flags.CD
+
+.. autofunction:: dns.flags.from_text
+.. autofunction:: dns.flags.to_text
+              
+EDNS Flags
+----------
+
+.. autodata:: dns.flags.DO
+
+.. autofunction:: dns.flags.edns_from_text
+.. autofunction:: dns.flags.edns_to_text
diff --git a/doc/message-opcode.rst b/doc/message-opcode.rst
new file mode 100644 (file)
index 0000000..ad931e8
--- /dev/null
@@ -0,0 +1,20 @@
+.. _message-opcode:
+
+Message Opcodes
+---------------
+
+DNS Opcodes describe what kind of operation a DNS message is requesting
+or replying to.  Opcodes are embedded in the flags field in the DNS
+header.
+
+.. autodata:: dns.opcode.QUERY
+.. autodata:: dns.opcode.IQUERY
+.. autodata:: dns.opcode.STATUS
+.. autodata:: dns.opcode.NOTIFY
+.. autodata:: dns.opcode.UPDATE
+
+.. autofunction:: dns.opcode.from_text
+.. autofunction:: dns.opcode.to_text
+.. autofunction:: dns.opcode.from_flags
+.. autofunction:: dns.opcode.to_flags
+.. autofunction:: dns.opcode.is_update
diff --git a/doc/message-rcode.rst b/doc/message-rcode.rst
new file mode 100644 (file)
index 0000000..6dd1bb4
--- /dev/null
@@ -0,0 +1,27 @@
+.. _message-rcode:
+
+Message Rcodes
+--------------
+
+A DNS Rcode describes the result of a DNS request.  If EDNS is not in
+use, then the rcode is encoded solely in the DNS header.   If EDNS is
+in use, then the rcode is encoded using bits form both the header and
+the EDNS OPT RR.
+
+.. autodata:: dns.rcode.NOERROR
+.. autodata:: dns.rcode.FORMERR
+.. autodata:: dns.rcode.SERVFAIL
+.. autodata:: dns.rcode.NXDOMAIN
+.. autodata:: dns.rcode.NOTIMP
+.. autodata:: dns.rcode.REFUSED
+.. autodata:: dns.rcode.YXDOMAIN
+.. autodata:: dns.rcode.YXRRSET
+.. autodata:: dns.rcode.NXRRSET
+.. autodata:: dns.rcode.NOTAUTH
+.. autodata:: dns.rcode.NOTZONE
+.. autodata:: dns.rcode.BADVERS
+
+.. autofunction:: dns.rcode.from_text
+.. autofunction:: dns.rcode.to_text
+.. autofunction:: dns.rcode.from_flags
+.. autofunction:: dns.rcode.to_flags
index 2a68f4301bb1f92e094c0ef2dd3485c784580e8a..fb2f8bf2c4ef2d1ee274ca0d134d583a4fa4453d 100644 (file)
@@ -14,3 +14,7 @@ a textual form, and also read from that form.
 
    message-class
    message-make
+   message-flags
+   message-opcode
+   message-rcode
+   message-edns