관리-도구
편집 파일: renderer.cpython-38.pyc
U /?�f�+ � @ sl d Z ddlZddlZddlZddlZddlZddlZddlZdZ dZ dZdZej dd� �ZG dd � d �ZdS ) z*Help for building DNS wire format messages� N� � � c c s� | � d| � | �� }d V | �� }|| }|dkr�zF| �|| � z| � |�|d�� W n tk rv tjj�Y nX W 5 | �|� X d S )N� r �big)�write�tell�seek�to_bytes� OverflowError�dns� exception� FormError)�outputZ length_length�start�end�length� r �:/opt/hc_python/lib/python3.8/site-packages/dns/renderer.py�prefixed_length# s r c @ s� e Zd ZdZd)dd�Zdd� Zd d � Zejdd� �Z ejd d� �Z ejj fdd�Zdd� Zdd� Zd*dd�Zd+dd�Zejjfdd�Zejjfdd�Zdd� Zdd � Zd!d"� Zedd#�d$d%�Zdd&�d'd(�ZdS ),�Renderera� 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_rrset(dns.renderer.ADDITIONAL, ad_rrset_1) r.add_rrset(dns.renderer.ADDITIONAL, ad_rrset_2) r.add_edns(0, 0, 4096) r.write_header() r.add_tsig(keyname, secret, 300, 1, 0, '', request_mac) wire = r.get_wire() If padding is going to be used, then the OPT record MUST be written after everything else in the additional section except for the TSIG (if any). output, an io.BytesIO, where rendering is written id: the message id flags: the message flags max_size: the maximum size of the message origin: the origin to use when rendering relative names compress: the compression table section: an int, the section currently being rendered counts: list of the number of RRs in each section mac: the MAC of the rendered message (if TSIG was used) Nr � c C sv t �� | _|dkr"t�dd�| _n|| _|| _|| _|| _i | _ t | _ddddg| _| j� d� d| _d| _d| _dS )zInitialize a new renderer.Nr r s � F)�io�BytesIOr �random�randint�id�flags�max_size�origin�compress�QUESTION�section�countsr �mac�reserved� was_padded)�selfr r r r r r r �__init__b s zRenderer.__init__c C sV | j �|� | j �� g }| j�� D ]\}}||kr$|�|� q$|D ]}| j|= qDdS )z�Truncate the output buffer at offset *where*, and remove any compression table entries that pointed beyond the truncation point. N)r r �truncater! �items�append)r( �whereZkeys_to_delete�k�vr r r � _rollbacku s zRenderer._rollbackc C s&