-# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
+# Copyright (C) 2003-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.
-"""Common DNS Exceptions."""
+"""Common DNS Exceptions.
+Dnspython modules may also define their own exceptions, which will
+always be subclasses of ``DNSException``.
+"""
class DNSException(Exception):
-
"""Abstract base class shared by all dnspython exceptions.
It supports two basic modes of operation:
- a) Old/compatible mode is used if __init__ was called with
- empty \**kwargs.
- In compatible mode all \*args are passed to standard Python Exception class
- as before and all \*args are printed by standard __str__ implementation.
- Class variable msg (or doc string if msg is None) is returned from str()
- if \*args is empty.
-
- b) New/parametrized mode is used if __init__ was called with
- non-empty \**kwargs.
- In the new mode \*args has to be empty and all kwargs has to exactly match
- set in class variable self.supp_kwargs. All kwargs are stored inside
- self.kwargs and used in new __str__ implementation to construct
- formatted message based on self.fmt string.
-
- In the simplest case it is enough to override supp_kwargs and fmt
- class variables to get nice parametrized messages.
+ a) Old/compatible mode is used if ``__init__`` was called with
+ empty *kwargs*. In compatible mode all *args* are passed
+ to the standard Python Exception class as before and all *args* are
+ printed by the standard ``__str__`` implementation. Class variable
+ ``msg`` (or doc string if ``msg`` is ``None``) is returned from ``str()``
+ if *args* is empty.
+
+ b) New/parametrized mode is used if ``__init__`` was called with
+ non-empty *kwargs*.
+ In the new mode *args* must be empty and all kwargs must match
+ those set in class variable ``supp_kwargs``. All kwargs are stored inside
+ ``self.kwargs`` and used in a new ``__str__`` implementation to construct
+ a formatted message based on the ``fmt`` class variable, a ``string``.
+
+ In the simplest case it is enough to override the ``supp_kwargs``
+ and ``fmt`` class variables to get nice parametrized messages.
"""
+
msg = None # non-parametrized message
supp_kwargs = set() # accepted parameters for _fmt_kwargs (sanity check)
fmt = None # message parametrized with results from _fmt_kwargs
class FormError(DNSException):
-
"""DNS message is malformed."""
class SyntaxError(DNSException):
-
"""Text input is malformed."""
class UnexpectedEnd(SyntaxError):
-
"""Text input ended unexpectedly."""
class TooBig(DNSException):
-
"""The DNS message is too big."""
class Timeout(DNSException):
-
"""The DNS operation timed out."""
supp_kwargs = set(['timeout'])
fmt = "The DNS operation timed out after {timeout} seconds"