dns :: renderer :: Renderer :: Class Renderer
[hide private]
[frames] | no frames]

Class Renderer

source code

object --+
         |
        Renderer

Helper class for building DNS wire-format messages.

Most applications can use the higher-level dns.message.Message class and its to_wire() method to generate wire-format messages. This class is for those applications which need finer control over the generation of messages.

Typical use:

   r = dns.renderer.Renderer(id=1, flags=0x80, max_size=512)
   r.add_question(qname, qtype, qclass)
   r.add_rrset(dns.renderer.ANSWER, rrset_1)
   r.add_rrset(dns.renderer.ANSWER, rrset_2)
   r.add_rrset(dns.renderer.AUTHORITY, ns_rrset)
   r.add_edns(0, 0, 4096)
   r.add_rrset(dns.renderer.ADDTIONAL, ad_rrset_1)
   r.add_rrset(dns.renderer.ADDTIONAL, ad_rrset_2)
   r.write_header()
   r.add_tsig(keyname, secret, 300, 1, 0, '', request_mac)
   wire = r.get_wire()
Instance Methods [hide private]
 
__init__(self, id=None, flags=0, max_size=65535, origin=None)
Initialize a new renderer.
source code
 
_rollback(self, where)
Truncate the output buffer at offset where, and remove any compression table entries that pointed beyond the truncation point.
source code
 
_set_section(self, section)
Set the renderer's current section.
source code
 
add_question(self, qname, rdtype, rdclass=1)
Add a question to the message.
source code
 
add_rrset(self, section, rrset, **kw)
Add the rrset to the specified section.
source code
 
add_rdataset(self, section, name, rdataset, **kw)
Add the rdataset to the specified section, using the specified name as the owner name.
source code
 
add_edns(self, edns, ednsflags, payload, options=None)
Add an EDNS OPT record to the message.
source code
 
add_tsig(self, keyname, secret, fudge, id, tsig_error, other_data, request_mac, algorithm=<DNS name HMAC-MD5.SIG-ALG.REG.INT.>)
Add a TSIG signature to the message.
source code
 
write_header(self)
Write the DNS message header.
source code
string
get_wire(self)
Return the wire format message.
source code

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

Instance Variables [hide private]
dict compress
the compression table
int list of length 4 counts
list of the number of RRs in each section
int flags
the message flags
int id
the message id
string mac
the MAC of the rendered message (if TSIG was used)
int max_size
the maximum size of the message
dns.name.Name object origin
the origin to use when rendering relative names
BytesIO object output
where rendering is written
int (dns.renderer.QUESTION, dns.renderer.ANSWER, dns.renderer.AUTHORITY, or dns.renderer.ADDITIONAL) section
the section currently being rendered
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, id=None, flags=0, max_size=65535, origin=None)
(Constructor)

source code 

Initialize a new renderer.

Parameters:
  • id (int) - the message id
  • flags (int) - the DNS message flags
  • max_size (int) - the maximum message size; the default is 65535. If rendering results in a message greater than max_size, then dns.exception.TooBig will be raised.
  • origin (dns.name.Name or None.) - the origin to use when rendering relative names
Overrides: object.__init__

_rollback(self, where)

source code 

Truncate the output buffer at offset where, and remove any compression table entries that pointed beyond the truncation point.

Parameters:
  • where (int) - the offset

_set_section(self, section)

source code 

Set the renderer's current section.

Sections must be rendered order: QUESTION, ANSWER, AUTHORITY, ADDITIONAL. Sections may be empty.

Parameters:
  • section (int) - the section
Raises:

add_question(self, qname, rdtype, rdclass=1)

source code 

Add a question to the message.

Parameters:
  • qname (dns.name.Name) - the question name
  • rdtype (int) - the question rdata type
  • rdclass (int) - the question rdata class

add_rrset(self, section, rrset, **kw)

source code 

Add the rrset to the specified section.

Any keyword arguments are passed on to the rdataset's to_wire() routine.

Parameters:
  • section (int) - the section
  • rrset (dns.rrset.RRset object) - the rrset

add_rdataset(self, section, name, rdataset, **kw)

source code 

Add the rdataset to the specified section, using the specified name as the owner name.

Any keyword arguments are passed on to the rdataset's to_wire() routine.

Parameters:
  • section (int) - the section
  • name (dns.name.Name object) - the owner name
  • rdataset (dns.rdataset.Rdataset object) - the rdataset

add_edns(self, edns, ednsflags, payload, options=None)

source code 

Add an EDNS OPT record to the message.

Parameters:
  • edns (int) - The EDNS level to use.
  • ednsflags (int) - EDNS flag values.
  • payload (int) - The EDNS sender's payload field, which is the maximum size of UDP datagram the sender can handle.
  • options (list of dns.edns.Option instances) - The EDNS options list

See Also: RFC 2671

add_tsig(self, keyname, secret, fudge, id, tsig_error, other_data, request_mac, algorithm=<DNS name HMAC-MD5.SIG-ALG.REG.INT.>)

source code 

Add a TSIG signature to the message.

Parameters:
  • keyname (dns.name.Name object) - the TSIG key name
  • secret (string) - the secret to use
  • fudge (int) - TSIG time fudge
  • id (int) - the message id to encode in the tsig signature
  • tsig_error (int) - TSIG error code; default is 0.
  • other_data (string) - TSIG other data.
  • request_mac (string) - This message is a response to the request which had the specified MAC.
  • algorithm (dns.name.Name object) - the TSIG algorithm to use

write_header(self)

source code 

Write the DNS message header.

Writing the DNS message header is done after all sections have been rendered, but before the optional TSIG signature is added.