Repository URL to install this package:
|
Version:
2.5 ▾
|
ó
EYc @ s d Z d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m
Z
d Z d Z d Z
d Z d e f d
YZ d S( s* Help for building DNS wire format messagesiÿÿÿÿ( t BytesIONi ( t longi i i t Rendererc B s e Z d Z d
d d d
d Z d Z d Z e j j d Z
d Z d Z d
d Z
e j j d
Z d Z d Z RS( si Helper class for building DNS wire-format messages.
Most applications can use the higher-level L{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()
@ivar output: where rendering is written
@type output: BytesIO object
@ivar id: the message id
@type id: int
@ivar flags: the message flags
@type flags: int
@ivar max_size: the maximum size of the message
@type max_size: int
@ivar origin: the origin to use when rendering relative names
@type origin: dns.name.Name object
@ivar compress: the compression table
@type compress: dict
@ivar section: the section currently being rendered
@type section: int (dns.renderer.QUESTION, dns.renderer.ANSWER,
dns.renderer.AUTHORITY, or dns.renderer.ADDITIONAL)
@ivar counts: list of the number of RRs in each section
@type counts: int list of length 4
@ivar mac: the MAC of the rendered message (if TSIG was used)
@type mac: string
i iÿÿ c C s t | _ | d k r0 t j d d | _ n | | _ | | _ | | _ | | _ i | _ t
| _ d d d d g | _ | j j
d d | _ d S( só Initialize a new renderer.
@param id: the message id
@type id: int
@param flags: the DNS message flags
@type flags: int
@param max_size: the maximum message size; the default is 65535.
If rendering results in a message greater than I{max_size},
then L{dns.exception.TooBig} will be raised.
@type max_size: int
@param origin: the origin to use when rendering relative names
@type origin: dns.name.Name or None.
i iÿÿ t i t Nt ( R t outputt Nonet randomt randintt idt flagst max_sizet origint compresst QUESTIONt sectiont countst writet mac( t selfR
R R R
( ( sR /home/tvault/.virtenv/lib/python2.7/site-packages/eventlet/support/dns/renderer.pyt __init__N s c C s~ | j j | | j j g } x9 | j j D]( \ } } | | k r3 | j | q3 q3 Wx | D] } | j | =qf Wd S( sÕ Truncate the output buffer at offset I{where}, and remove any
compression table entries that pointed beyond the truncation
point.
@param where: the offset
@type where: int
N( R t seekt truncateR t itemst append( R t wheret keys_to_deletet kt v( ( sR /home/tvault/.virtenv/lib/python2.7/site-packages/eventlet/support/dns/renderer.pyt _rollbackk s
c C s= | j | k r9 | j | k r- t j j n | | _ n d S( sZ Set the renderer's current section.
Sections must be rendered order: QUESTION, ANSWER, AUTHORITY,
ADDITIONAL. Sections may be empty.
@param section: the section
@type section: int
@raises dns.exception.FormError: an attempt was made to set
a section value less than the current section.
N( R t dnst exceptiont FormError( R R ( ( sR /home/tvault/.virtenv/lib/python2.7/site-packages/eventlet/support/dns/renderer.pyt _set_section} s c C s¨ | j t | j j } | j | j | j | j | j j t j d | | | j j } | | j
k r | j | t j
j n | j t c d 7<d S( s Add a question to the message.
@param qname: the question name
@type qname: dns.name.Name
@param rdtype: the question rdata type
@type rdtype: int
@param rdclass: the question rdata class
@type rdclass: int
s !HHi N( R" R R t tellt to_wireR R
R t structt packR R R R t TooBigR ( R t qnamet rdtypet rdclasst beforet after( ( sR /home/tvault/.virtenv/lib/python2.7/site-packages/eventlet/support/dns/renderer.pyt add_question s
c K s | j | | j j } | j | j | j | j | } | j j } | | j k rw | j | t j j
n | j | c | 7<d S( s Add the rrset to the specified section.
Any keyword arguments are passed on to the rdataset's to_wire()
routine.
@param section: the section
@type section: int
@param rrset: the rrset
@type rrset: dns.rrset.RRset object
N( R" R R# R$ R R
R R R R R' R ( R R t rrsett kwR+ t nR, ( ( sR /home/tvault/.virtenv/lib/python2.7/site-packages/eventlet/support/dns/renderer.pyt add_rrset£ s
!
c K s | j | | j j } | j | | j | j | j | } | j j } | | j k rz | j | t j j
n | j | c | 7<d S( s© 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.
@param section: the section
@type section: int
@param name: the owner name
@type name: dns.name.Name object
@param rdataset: the rdataset
@type rdataset: dns.rdataset.Rdataset object
N( R" R R# R$ R R
R R R R R' R ( R R t namet rdatasetR/ R+ R0 R, ( ( sR /home/tvault/.virtenv/lib/python2.7/site-packages/eventlet/support/dns/renderer.pyt add_rdataset¸ s
c
C s | t d M} | | d >O} | j t | j j } | j j t j d d t j j
| | d | d
k rÂ| j j } xÇ | D]¿ } t j d | j d } | j j | | j j } | j
| j | j j }
|
| d k sü t | j j | d t j d |
| } | j j | | j j d d q W| j j } | | d k srt | j j | d t j d | | } | j j | | j j d d n | j j } | | j k rü| j | t j j n | j t c d 7<d
S( sØ Add an EDNS OPT record to the message.
@param edns: The EDNS level to use.
@type edns: int
@param ednsflags: EDNS flag values.
@type ednsflags: int
@param payload: The EDNS sender's payload field, which is the maximum
size of UDP datagram the sender can handle.
@type payload: int
@param options: The EDNS options list
@type options: list of dns.edns.Option instances
@see: RFC 2671
Iÿÿ ÿ i s !BHHIHi s !HHi i s !Hi N( R R" t
ADDITIONALR R# R R% R&