Your IP : 3.139.80.194
3
�b�W�. � @ sh d Z ddlmZ ddlZddlZddlZddlZddlZddl m
Z
dZdZdZ
dZG dd � d e�ZdS )
z*Help for building DNS wire format messages� )�BytesION� )�long� � c @ st e Zd ZdZddd�Zdd� Zd d
� Zejj fdd�Z
d
d� Zdd� Zddd�Z
ejjfdd�Zdd� Zdd� ZdS )�Rendererai 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
Nr � c C sh t � | _|dkr tjdd�| _n|| _|| _|| _|| _i | _t | _
ddddg| _| jjd� d| _
dS )a� 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.
Nr i�� � � � s )r �output�randomZrandint�id�flags�max_size�origin�compress�QUESTION�section�counts�write�mac)�selfr r r r � r �/usr/lib/python3.6/renderer.py�__init__N s zRenderer.__init__c C s^ | j j|� | j j� g }x(| jj� D ]\}}||kr&|j|� q&W x|D ]}| j|= qJW dS )z�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 �seek�truncater �items�append)r �whereZkeys_to_delete�k�vr r r � _rollbackk s
zRenderer._rollbackc C s&