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

Class Renderer

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()

Method Summary
  __init__(self, id, flags, max_size, origin)
Initialize a new renderer.
a new object with type S, a subtype of T __new__(S, ...)
  add_edns(self, edns, ednsflags, payload)
Add an EDNS OPT record to the message.
  add_question(self, qname, rdtype, rdclass)
Add a question to the message.
  add_rdataset(self, section, name, rdataset, **kw)
Add the rdataset to the specified section, using the specified name as the owner name.
  add_rrset(self, section, rrset, **kw)
Add the rrset to the specified section.
  add_tsig(self, keyname, secret, fudge, id, tsig_error, other_data, request_mac)
Add a TSIG signature to the message.
string get_wire(self)
Return the wire format message.
  write_header(self)
Write the DNS message header.
  _rollback(self, where)
Truncate the output buffer at offset where, and remove any compression table entries that pointed beyond the truncation point.
  _set_section(self, section)
Set the renderer's current section.

Instance Variable Summary
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
cStringIO.StringIO 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

Method Details

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

Initialize a new renderer.
Parameters:
id - the message id
           (type=int)
flags - the DNS message flags
           (type=int)
max_size - 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.
           (type=int)
origin - the origin to use when rendering relative names
           (type=dns.name.Namem or None.)

__new__(S, ...)

Returns:
a new object with type S, a subtype of T

add_edns(self, edns, ednsflags, payload)

Add an EDNS OPT record to the message.
Parameters:
edns - The EDNS level to use.
           (type=int)
ednsflags - EDNS flag values.
           (type=int)
payload - The EDNS sender's payload field, which is the maximum size of UDP datagram the sender can handle.
           (type=int)

See also: RFC 2671

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

Add a question to the message.
Parameters:
qname - the question name
           (type=dns.name.Name)
rdtype - the question rdata type
           (type=int)
rdclass - the question rdata class
           (type=int)

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

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 - the section
           (type=int)
name - the owner name
           (type=dns.name.Name object)
rdataset - the rdataset
           (type=dns.rdataset.Rdataset object)

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

Add the rrset to the specified section.

Any keyword arguments are passed on to the rdataset's to_wire() routine.
Parameters:
section - the section
           (type=int)
rrset - the rrset
           (type=dns.rrset.RRset object)

add_tsig(self, keyname, secret, fudge, id, tsig_error, other_data, request_mac)

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

get_wire(self)

Return the wire format message.
Returns:
string

write_header(self)

Write the DNS message header.

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

_rollback(self, where)

Truncate the output buffer at offset where, and remove any compression table entries that pointed beyond the truncation point.
Parameters:
where - the offset
           (type=int)

_set_section(self, section)

Set the renderer's current section.

Sections must be rendered order: QUESTION, ANSWER, AUTHORITY, ADDITIONAL. Sections may be empty.
Parameters:
section - the section
           (type=int)
Raises:
dns.exception.FormError - an attempt was made to set a section value less than the current section.

Instance Variable Details

compress

the compression table
Type:
dict

counts

list of the number of RRs in each section
Type:
int list of length 4

flags

the message flags
Type:
int

id

the message id
Type:
int

mac

the MAC of the rendered message (if TSIG was used)
Type:
string

max_size

the maximum size of the message
Type:
int

origin

the origin to use when rendering relative names
Type:
dns.name.Name object

output

where rendering is written
Type:
cStringIO.StringIO object

section

the section currently being rendered
Type:
int (dns.renderer.QUESTION, dns.renderer.ANSWER, dns.renderer.AUTHORITY, or dns.renderer.ADDITIONAL)

Generated by Epydoc 1.1 on Sat Jul 19 02:54:32 2003 http://epydoc.sf.net