dnspython  1.16.0
About: dnspython is a DNS toolkit (for Python 2.x) that supports almost all record types.
  Fossies Dox: dnspython-1.16.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

dns.message Namespace Reference

Classes

class  _TextReader
 
class  _WireReader
 
class  BadEDNS
 
class  BadTSIG
 
class  Message
 
class  ShortHeader
 
class  TrailingJunk
 
class  UnknownHeaderField
 
class  UnknownTSIGKey
 

Functions

def from_wire (wire, keyring=None, request_mac=b'', xfr=False, origin=None, tsig_ctx=None, multi=False, first=True, question_only=False, one_rr_per_rrset=False, ignore_trailing=False)
 
def from_text (text)
 
def from_file (f)
 
def make_query (qname, rdtype, rdclass=dns.rdataclass.IN, use_edns=None, want_dnssec=False, ednsflags=None, payload=None, request_payload=None, options=None)
 
def make_response (query, recursion_available=False, our_payload=8192, fudge=300)
 

Variables

int QUESTION = 0
 
int ANSWER = 1
 
int AUTHORITY = 2
 
int ADDITIONAL = 3
 

Function Documentation

◆ from_file()

def dns.message.from_file (   f)
Read the next text format message from the specified file.

*f*, a ``file`` or ``text``.  If *f* is text, it is treated as the
pathname of a file to open.

Raises ``dns.message.UnknownHeaderField`` if a header is unknown.

Raises ``dns.exception.SyntaxError`` if the text is badly formed.

Returns a ``dns.message.Message object``

Definition at line 1031 of file message.py.

References dns.message.from_text().

◆ from_text()

def dns.message.from_text (   text)
Convert the text format message into a message object.

*text*, a ``text``, the text format message.

Raises ``dns.message.UnknownHeaderField`` if a header is unknown.

Raises ``dns.exception.SyntaxError`` if the text is badly formed.

Returns a ``dns.message.Message object``

Definition at line 1007 of file message.py.

Referenced by dns.message.from_file().

◆ from_wire()

def dns.message.from_wire (   wire,
  keyring = None,
  request_mac = b'',
  xfr = False,
  origin = None,
  tsig_ctx = None,
  multi = False,
  first = True,
  question_only = False,
  one_rr_per_rrset = False,
  ignore_trailing = False 
)
Convert a DNS wire format message into a message
object.

*keyring*, a ``dict``, the keyring to use if the message is signed.

*request_mac*, a ``binary``.  If the message is a response to a
TSIG-signed request, *request_mac* should be set to the MAC of
that request.

*xfr*, a ``bool``, should be set to ``True`` if this message is part of
a zone transfer.

*origin*, a ``dns.name.Name`` or ``None``.  If the message is part
of a zone transfer, *origin* should be the origin name of the
zone.

*tsig_ctx*, a ``hmac.HMAC`` objext, the ongoing TSIG context, used
when validating zone transfers.

*multi*, a ``bool``, should be set to ``True`` if this message
part of a multiple message sequence.

*first*, a ``bool``, should be set to ``True`` if this message is
stand-alone, or the first message in a multi-message sequence.

*question_only*, a ``bool``.  If ``True``, read only up to
the end of the question section.

*one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its
own RRset.

*ignore_trailing*, a ``bool``.  If ``True``, ignore trailing
junk at end of the message.

Raises ``dns.message.ShortHeader`` if the message is less than 12 octets
long.

Raises ``dns.messaage.TrailingJunk`` if there were octets in the message
past the end of the proper DNS message, and *ignore_trailing* is ``False``.

Raises ``dns.message.BadEDNS`` if an OPT record was in the
wrong section, or occurred more than once.

Raises ``dns.message.BadTSIG`` if a TSIG record was not the last
record of the additional data section.

Returns a ``dns.message.Message``.

Definition at line 759 of file message.py.

Referenced by dns.query.receive_tcp(), dns.query.receive_udp(), and dns.query.xfr().

◆ make_query()

def dns.message.make_query (   qname,
  rdtype,
  rdclass = dns.rdataclass.IN,
  use_edns = None,
  want_dnssec = False,
  ednsflags = None,
  payload = None,
  request_payload = None,
  options = None 
)
Make a query message.

The query name, type, and class may all be specified either
as objects of the appropriate type, or as strings.

The query will have a randomly chosen query id, and its DNS flags
will be set to dns.flags.RD.

qname, a ``dns.name.Name`` or ``text``, the query name.

*rdtype*, an ``int`` or ``text``, the desired rdata type.

*rdclass*, an ``int`` or ``text``,  the desired rdata class; the default
is class IN.

*use_edns*, an ``int``, ``bool`` or ``None``.  The EDNS level to use; the
default is None (no EDNS).
See the description of dns.message.Message.use_edns() for the possible
values for use_edns and their meanings.

*want_dnssec*, a ``bool``.  If ``True``, DNSSEC data is desired.

*ednsflags*, an ``int``, the EDNS flag values.

*payload*, an ``int``, is the EDNS sender's payload field, which is the
maximum size of UDP datagram the sender can handle.  I.e. how big
a response to this message can be.

*request_payload*, an ``int``, is the EDNS payload size to use when
sending this message.  If not specified, defaults to the value of
*payload*.

*options*, a list of ``dns.edns.Option`` objects or ``None``, the EDNS
options.

Returns a ``dns.message.Message``

Definition at line 1061 of file message.py.

References dns.rdataclass.from_text(), dns.rdatatype.from_text(), and dns.name.from_text().

Referenced by dns.resolver.Resolver.query(), and dns.query.xfr().

◆ make_response()

def dns.message.make_response (   query,
  recursion_available = False,
  our_payload = 8192,
  fudge = 300 
)
Make a message which is a response for the specified query.
The message returned is really a response skeleton; it has all
of the infrastructure required of a response, but none of the
content.

The response's question section is a shallow copy of the query's
question section, so the query's question RRsets should not be
changed.

*query*, a ``dns.message.Message``, the query to respond to.

*recursion_available*, a ``bool``, should RA be set in the response?

*our_payload*, an ``int``, the payload size to advertise in EDNS
responses.

*fudge*, an ``int``, the TSIG time fudge.

Returns a ``dns.message.Message`` object.

Definition at line 1138 of file message.py.

Variable Documentation

◆ ADDITIONAL

int dns.message.ADDITIONAL = 3

Definition at line 81 of file message.py.

◆ ANSWER

int dns.message.ANSWER = 1

Definition at line 75 of file message.py.

◆ AUTHORITY

int dns.message.AUTHORITY = 2

Definition at line 78 of file message.py.

◆ QUESTION

int dns.message.QUESTION = 0

Definition at line 72 of file message.py.