Package dns :: Module message :: Class Message
[hide private]
[frames] | no frames]

Class Message

source code

object --+
         |
        Message
Known Subclasses:

A DNS message.

Instance Methods [hide private]
 
__eq__(self, other)
Two messages are equal if they have the same content in the header, question, answer, and authority sections.
source code
 
__init__(self, id=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__ne__(self, other) source code
 
__repr__(self)
repr(x)
source code
 
__str__(self)
str(x)
source code
 
find_rrset(self, section, name, rdclass, rdtype, covers=0, deleting=None, create=False, force_unique=False)
Find the RRset with the given attributes in the specified section.
source code
 
get_rrset(self, section, name, rdclass, rdtype, covers=0, deleting=None, create=False, force_unique=False)
Get the RRset with the given attributes in the specified section.
source code
 
is_response(self, other)
Is this message a response to *other*?
source code
 
opcode(self)
Return the opcode.
source code
 
rcode(self)
Return the rcode.
source code
 
section_from_number(self, number)
Return the "section number" of the specified section for use in indexing.
source code
 
section_number(self, section)
Return the "section number" of the specified section for use in indexing.
source code
 
set_opcode(self, opcode)
Set the opcode.
source code
 
set_rcode(self, rcode)
Set the rcode.
source code
 
to_text(self, origin=None, relativize=True, **kw)
Convert the message to text.
source code
 
to_wire(self, origin=None, max_size=0, **kw)
Return a string containing the message in DNS compressed wire format.
source code
 
use_edns(self, edns=0, ednsflags=0, payload=1280, request_payload=None, options=None)
Configure EDNS behavior.
source code
 
use_tsig(self, keyring, keyname=None, fudge=300, original_id=None, tsig_error=0, other_data='', algorithm=<DNS name HMAC-MD5.SIG-ALG.REG.INT.>)
When sending, a TSIG signature using the specified keyring and keyname should be added.
source code
 
want_dnssec(self, wanted=True)
Enable or disable 'DNSSEC desired' flag in requests.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__eq__(self, other)
(Equality operator)

source code 

Two messages are equal if they have the same content in the header, question, answer, and authority sections.

Returns a ``bool``.

__init__(self, id=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

find_rrset(self, section, name, rdclass, rdtype, covers=0, deleting=None, create=False, force_unique=False)

source code 

Find the RRset with the given attributes in the specified section.

*section*, an ``int`` section number, or one of the section attributes of this message. This specifies the the section of the message to search. For example:

   my_message.find_rrset(my_message.answer, name, rdclass, rdtype)
   my_message.find_rrset(dns.message.ANSWER, name, rdclass, rdtype)

*name*, a ``dns.name.Name``, the name of the RRset.

*rdclass*, an ``int``, the class of the RRset.

*rdtype*, an ``int``, the type of the RRset.

*covers*, an ``int`` or ``None``, the covers value of the RRset. The default is ``None``.

*deleting*, an ``int`` or ``None``, the deleting value of the RRset. The default is ``None``.

*create*, a ``bool``. If ``True``, create the RRset if it is not found. The created RRset is appended to *section*.

*force_unique*, a ``bool``. If ``True`` and *create* is also ``True``, create a new RRset regardless of whether a matching RRset exists already. The default is ``False``. This is useful when creating DDNS Update messages, as order matters for them.

Raises ``KeyError`` if the RRset was not found and create was ``False``.

Returns a ``dns.rrset.RRset object``.

get_rrset(self, section, name, rdclass, rdtype, covers=0, deleting=None, create=False, force_unique=False)

source code 

Get the RRset with the given attributes in the specified section.

If the RRset is not found, None is returned.

*section*, an ``int`` section number, or one of the section attributes of this message. This specifies the the section of the message to search. For example:

   my_message.get_rrset(my_message.answer, name, rdclass, rdtype)
   my_message.get_rrset(dns.message.ANSWER, name, rdclass, rdtype)

*name*, a ``dns.name.Name``, the name of the RRset.

*rdclass*, an ``int``, the class of the RRset.

*rdtype*, an ``int``, the type of the RRset.

*covers*, an ``int`` or ``None``, the covers value of the RRset. The default is ``None``.

*deleting*, an ``int`` or ``None``, the deleting value of the RRset. The default is ``None``.

*create*, a ``bool``. If ``True``, create the RRset if it is not found. The created RRset is appended to *section*.

*force_unique*, a ``bool``. If ``True`` and *create* is also ``True``, create a new RRset regardless of whether a matching RRset exists already. The default is ``False``. This is useful when creating DDNS Update messages, as order matters for them.

Returns a ``dns.rrset.RRset object`` or ``None``.

is_response(self, other)

source code 

Is this message a response to *other*?

Returns a ``bool``.

opcode(self)

source code 

Return the opcode.

Returns an ``int``.

rcode(self)

source code 

Return the rcode.

Returns an ``int``.

section_from_number(self, number)

source code 

Return the "section number" of the specified section for use in indexing. The question section is 0, the answer section is 1, the authority section is 2, and the additional section is 3.

*section* is one of the section attributes of this message.

Raises ``ValueError`` if the section isn't known.

Returns an ``int``.

section_number(self, section)

source code 

Return the "section number" of the specified section for use in indexing. The question section is 0, the answer section is 1, the authority section is 2, and the additional section is 3.

*section* is one of the section attributes of this message.

Raises ``ValueError`` if the section isn't known.

Returns an ``int``.

set_opcode(self, opcode)

source code 

Set the opcode.

*opcode*, an ``int``, is the opcode to set.

set_rcode(self, rcode)

source code 

Set the rcode.

*rcode*, an ``int``, is the rcode to set.

to_text(self, origin=None, relativize=True, **kw)

source code 

Convert the message to text.

The *origin*, *relativize*, and any other keyword arguments are passed to the RRset ``to_wire()`` method.

Returns a ``text``.

to_wire(self, origin=None, max_size=0, **kw)

source code 

Return a string containing the message in DNS compressed wire format.

Additional keyword arguments are passed to the RRset ``to_wire()`` method.

*origin*, a ``dns.name.Name`` or ``None``, the origin to be appended to any relative names.

*max_size*, an ``int``, the maximum size of the wire format output; default is 0, which means "the message's request payload, if nonzero, or 65535".

Raises ``dns.exception.TooBig`` if *max_size* was exceeded.

Returns a ``binary``.

use_edns(self, edns=0, ednsflags=0, payload=1280, request_payload=None, options=None)

source code 

Configure EDNS behavior.

*edns*, an ``int``, is the EDNS level to use. Specifying ``None``, ``False``, or ``-1`` means "do not use EDNS", and in this case the other parameters are ignored. Specifying ``True`` is equivalent to specifying 0, i.e. "use EDNS0".

*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.

use_tsig(self, keyring, keyname=None, fudge=300, original_id=None, tsig_error=0, other_data='', algorithm=<DNS name HMAC-MD5.SIG-ALG.REG.INT.>)

source code 

When sending, a TSIG signature using the specified keyring and keyname should be added.

See the documentation of the Message class for a complete description of the keyring dictionary.

*keyring*, a ``dict``, the TSIG keyring to use. If a *keyring* is specified but a *keyname* is not, then the key used will be the first key in the *keyring*. Note that the order of keys in a dictionary is not defined, so applications should supply a keyname when a keyring is used, unless they know the keyring contains only one key.

*keyname*, a ``dns.name.Name`` or ``None``, the name of the TSIG key to use; defaults to ``None``. The key must be defined in the keyring.

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

*original_id*, an ``int``, the TSIG original id. If ``None``, the message's id is used.

*tsig_error*, an ``int``, the TSIG error code.

*other_data*, a ``binary``, the TSIG other data.

*algorithm*, a ``dns.name.Name``, the TSIG algorithm to use.

want_dnssec(self, wanted=True)

source code 

Enable or disable 'DNSSEC desired' flag in requests.

*wanted*, a ``bool``. If ``True``, then DNSSEC data is desired in the response, EDNS is enabled if required, and then the DO bit is set. If ``False``, the DO bit is cleared if EDNS is enabled.