관리-도구
편집 파일: zonefile.cpython-39.pyc
a �����M�em������������������� ���@���s���d�Z�ddlZddlZddlmZmZmZmZmZm Z m Z �ddlZddl ZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZG�dd��dejj�ZG�dd��dejj�Zdd ��Ze ejjeejj �eejj �ee�e!e"e!e"f�Z#d d��Z$G�dd ��d �Z%G�dd��dej&j'�Z(G�dd��dej&j)�Z*ddej+j,ej+j,dddejj-df eee ejj e.f��ee!�ee ej+j/e.f��e ej+j/e.f�ee ej0j1e.f��ee e!e.f��eejj2�ee ejj e.f��e"eej3j4�d�dd�Z5dS�)z DNS Zones.�����N)�Any�Iterable�List�Optional�Set�Tuple�Unionc�������������������@���s���e�Zd�ZdZdS�)� UnknownOriginzUnknown originN��__name__� __module__�__qualname__�__doc__��r���r����0/usr/lib/python3.9/site-packages/dns/zonefile.pyr ���&���s���r ���c�������������������@���s���e�Zd�ZdZdS�)�CNAMEAndOtherDataz!A node has a CNAME and other dataNr ���r���r���r���r���r���*���s���r���c�����������������C���sz���t�jj�|�}|��|�}|d�u�r$d�S�|���}|t�jjjkrR|t�jjjkrRtd��n$|t�jjjkrv|t�jjjkrvtd��d�S�)Nz1rdataset type is not compatible with a CNAME nodez9CNAME rdataset is not compatible with a regular data node) �dns�nodeZNodeKindZclassify_rdatasetZget_nodeZclassifyZCNAMEZREGULARr���)�txn�name�rdatasetZ rdataset_kindr���Z node_kindr���r���r����_check_cname_and_other_data.���s"���� �� ���r���c�����������������C���s���|�����}�|��d�sd|��}�|�S�)N�$)�upper� startswith)�sr���r���r����_upper_dollarizeQ���s���� r���c�������������������@���s����e�Zd�ZdZdejjejjej j eeee e�f�eejj�ee�eejj�eejj�ee�d� dd�Zdd ��Zd d��Zdd ��Zeeeeeeef�d�dd�Zdd��Zdd�dd�ZdS�)�Readerz(Read a DNS zone file into a transaction.FTN) �tok�rdclassr���� allow_include�allow_directives� force_name� force_ttl� force_rdclass�force_rdtype�default_ttlc�����������������C���s����||�_�|j���\|�_|�_}|�j|�_d|�_d|�_|d�ur:|} | d�u�rPd|�_d|�_ n| |�_d|�_ |�j|�_ ||�_||�_g�|�_ d�|�_|��|du�r�h�d�|�_|r�|�j�d��n&|du�r�t��|�_ntdd��|D���|�_||�_||�_||�_| |�_|�j�t��d�S�)Nr���FT>���� $GENERATE�$TTL�$ORIGIN�$INCLUDEc�����������������s���s���|�]}t�|�V��qd�S��N)r���)�.0�dr���r���r���� <genexpr>���������z"Reader.__init__.<locals>.<genexpr>)r����manager�origin_information�zone_origin� relativize�current_origin�last_ttl�last_ttl_knownr&����default_ttl_known� last_name�zone_rdclassr����saved_state�current_file�allowed_directives�add�setr"���r#���r$���r%���Zcheck_put_rdatasetr���)�selfr���r���r���r ���r!���r"���r#���r$���r%���r&����_r���r���r����__init__[���s<���� zReader.__init__c�����������������C���s���|�j����}|���r�qq�d�S�r+���)r����get� is_eol_or_eof�r?����tokenr���r���r���� _eat_line����s���� zReader._eat_linec�����������������C���s���|�j����}|���stjj�|S�r+���)r���rB���� is_identifierr���� exception�SyntaxErrorrD���r���r���r����_get_identifier����s���� zReader._get_identifierc����������� ��� ���C���sH��d}|�j�dur|�j�}n�|�jdu�r$t�|�jjdd�}|���sN|�j�||�j�|�_n"|�j���}|���rddS�|�j� |��|�j}|� |�j�s�|�����dS�|�j r�|� |�j�}|�jdur�|�j}||�_d|�_nT|����}d}z"tj�|j�}||�_d|�_d}W�n$�tjj�y���|�j� |��Y�n0�|�jdu�r&|�j}nr|����}ztj�|j�}W�n>�tjj�yZ�����Y�n&�t�y~���|�j}|�j� |��Y�n0�||�jk�r�tj�d��|du��r|����}d}z"tj�|j�}||�_d|�_d}W�nB�tjj�y���|�j�r�|�j}n|�j�r|�j}|�j� |��Y�n0�|�jdu�r(|�j}nB|����}ztj �|j�}W�n&�t�yh���tj�d|j���Y�n0�z"tj!�|||�j|�j|�j |�j�}W�n\�tjj�y������Y�nD�t�y����t"�#��dd��\}}tj�d�$t%|�t%|����Y�n0�|�j�s|tj j&k�r|j'|�_d|�_|du��r|j'}|du��r4tj�d��|�j(�)|||��dS�) z&Process one line from a DNS zone file.NT)Zwant_leading�RR class is not zone's class�unknown rdatatype '%s'����zcaught exception {}: {}�Missing default TTL value)*r"���r4���r ���r���rB���Z is_whitespaceZas_namer8���rC����unget�is_subdomainr2���rF���r3���r#���r5���r6���rJ���r����ttl� from_text�value�BadTTLr$���� rdataclassrH���rI���� Exceptionr9���r7���r&���r%���� rdatatype�rdata�sys�exc_info�format�strZSOAZminimumr���r=���) r?���rE���r���rQ���r����rdtype�rd�ty�var���r���r����_rr_line����s����� �� zReader._rr_line)�side�returnc����������� ������C���s��t��d�}t��d�}t��d�}|�|�}|rJ|���\}}}} } |dkrJd}|�|�}|rz|���\}}}|dkrrd}d} d} |�|�}|r�|���\}}}} |dkr�d}d} |s�|s�|s�d}d}d}d} d} t|�}t| �} |dvr�tj�d |���| d v�r tj�d| ���|||| | fS�)Nz"^.*\$({(\+|-?)(\d+),(\d+),(.)}).*$z^.*\$({(\+|-?)(\d+)}).*$z^.*\$({(\+|-?)(\d+),(\d+)}).*$���+r���r-���)re����-zinvalid offset sign %s)r-����o�x�X�n�Nzinvalid type %s)�re�compile�match�groups�intr���rH���rI���) r?���rb���Zis_generate1Zis_generate2Zis_generate3Zg1�mod�sign�offset�width�baseZg2Zg3r���r���r���� _parse_modify��sD���� zReader._parse_modifyc�������������� ������s���|�j�du�rt�|�j���}z2tj�|j�\}}}|�j���}|���sHtj j �W�n�tyd���tj j �Y�n0�z$|j}|�j���}|���s�tj j �W�n�ty����tj j �Y�n0�z8tj�|j�}||�_ d|�_|�j���}|���s�tj j �W�nR�tjj�y0���|�j�s|�j�stj � d��|�j�r|�j}n|�j�r,|�j }Y�n0�z.tj�|j�}|�j���}|����s^tj j �W�n8�tj j �y����tj j �Y�n�t�y����|�j}Y�n0�||�jk�r�tj � d��z.tj�|j�}|�j���}|����s�tj j �W�n&�t�y���tj � d|j���Y�n0�|j} ttttd�dd�} ttttd ���fd d���|��|�\}}} }}|��| �\}}}}}t||d�|�D��]2}| ||| �}| |||�}��|||�}��|||�}|�d |�|�}| �d |�|�}tj�||�j�|�jj�|�_|�j}|�|�j��s|������dS�|�j �r|� |�j�}z tj!�||||�j�|�j |�j�}W�n\�tj j �yP�����Y�nD�t�y����t"�#��dd��\}}tj � dt|�t|�f���Y�n0�|�j$�%|||���qrdS�)zPProcess one line containing the GENERATE statement from a DNS zone file.NTrN���rK���rL���)�counter�offset_signrs���rc���c�����������������S���s���|dkr|d9�}|�|�S�)z0Calculate the index from the counter and offset.rf������r���)rw���rx���rs���r���r���r����_calculate_index���s����z/Reader._generate_line.<locals>._calculate_index)�indexru���rt���rc���c��������������������sT���|dv�rt�|�|��|�S���|�d|�}d�|ddd���d|��}|dkrP|���}|S�)zVFormat the index with the given base, and zero-fill it to the given width.)r-���rg���rh���ri���rh����.Nry���rk���)r[����zfill�joinr���)r{���ru���rt���ZhexaZnibbles�� _format_indexr���r���r�������s����z,Reader._generate_line.<locals>._format_index����z$%srM���zcaught exception %s: %s)&r4���r ���r���rB���r���ZgrangerR���rS���rG���rH���rI���rV���rQ���r5���r6���rT���r7���r&���rU���r9���rW���rp���r\���rv����range�replacer���� idna_codecr8���rP���r2���rF���r3���rX���rY���rZ���r���r=���)r?���rE����start�stop�stepZlhsrQ���r���r]���Zrhsrz���ZlmodZlsignZloffsetZlwidthZlbaseZrmodZrsignZroffsetZrwidthZrbase�iZlindex�rindexZlzfindexZrzfindexr���rX���r^���r_���r`���r���r���r����_generate_line@��s����� ��� zReader._generate_line)rc���c����������� ��� ���C���s����zr|�j��dd�}|���rr|�jdur.|�j����t|�j�dkrj|�j�d�\|�_�|�_|�_ |�_|�_ |�_|�_|�_ q�qr�n�|���r�q�n�|���r�|�j�����q�n�|jd�dk�r\t|�j�dk�r\|j���}||�jvr�tj�d|��d���|dk�r,|�j����}|����s tj�d ��tj�|j�|�_d|�_ |�j�����q|d k�rp|�j����|�_|�j�����|�jdu��r`|�j|�_|�j�|�j��q|dk�r2|�j����}|j}|�j����}|����r�tj�|j|�j|�j�j�}|�j�����n|� ���s�tj�d��n|�j}|�j�!|�j�|�j|�j |�j|�j |�j|�j|�j f��t"|d �|�_tj#�$|�j|�|�_�||�_q|dk�rF|��%���qtj�d|��d���q|�j��&|��|��'���qW�nt�tjj�y��}�zV|�j��(��\}}|du��r�d}tj�d|||f��}t)�*��d�}|�+|�d�W�Y�d}~n d}~0�0�dS�)z�Read a DNS zone file and build a zone object. @raises dns.zone.NoSOA: No SOA RR was found at the zone origin @raises dns.zone.NoNS: No NS RRset was found at the zone origin TNr���ry���r���zzone file directive 'z' is not allowedr(���zbad $TTLr)���r*���zbad origin in $INCLUDE�rr'���zUnknown zone file directive '�'zsyntax errorz %s:%d: %srM���),r���rB���Zis_eofr;����close�lenr:����popr4���r8���r5���r6���r&���r7���Zis_eolZ is_commentZget_eolrS���r<���r���r���rH���rI���rG���rQ���rR���Zget_namer2���r����_set_originr���r����rC����append�open� tokenizer� Tokenizerr����rO���ra����whererY���rZ����with_traceback) r?���rE����c�filenameZ new_originZdetailZline_number�ex�tbr���r���r����read���s����� � � � �� � �zReader.read)FTNNNNN)r���r���r ���r���r���r����r����rU���� RdataClass�transaction�Transaction�boolr���r���r\���r���r����Namerp���rW���� RdataTyperA���rF���rJ���ra���r���rv���r����r����r���r���r���r���r���X���s6����������� �2z-�r���c�����������������������st���e�Zd�Z��fdd�Zdd��Zdd��Zdd��Zd d ��Zdd��Zd d��Z dd��Z dd��Zdd��Zdd��Z dd��Z���ZS�)�RRsetsReaderTransactionc��������������������s"���|rJ��t����|||��i�|�_d�S�r+���)�superrA���� rdatasets)r?���r0����replacementZ read_only�� __class__r���r���rA���+��s����z RRsetsReaderTransaction.__init__c�����������������C���s���|�j��|||f�S�r+���)r����rB����r?���r���r]����coversr���r���r���� _get_rdataset0��s����z%RRsetsReaderTransaction._get_rdatasetc�����������������C���sT���g�}|�j����D�] \\}}}}||kr|�|��qt|�dkr@d�S�tj���}||_�|S��Nr���)r�����itemsr����r����r���r���ZNode)r?���r���r����Z rdataset_namer@���r���r���r���r���r���� _get_node3��s���� z!RRsetsReaderTransaction._get_nodec�����������������C���s���||�j�||j|jf<�d�S�r+���)r����r]���r����)r?���r���r���r���r���r���� _put_rdataset>��s����z%RRsetsReaderTransaction._put_rdatasetc�����������������C���sH���g�}|�j�D�]}|d�|kr |�|��q t|�dkrD|D�]}|�j�|=�q6d�S�r����)r����r����r����)r?���r����remove�keyr���r���r����_delete_nameA��s���� z$RRsetsReaderTransaction._delete_namec�����������������C���s*���z|�j�|||f=�W�n�ty$���Y�n0�d�S�r+���)r�����KeyErrorr����r���r���r����_delete_rdatasetK��s����z(RRsetsReaderTransaction._delete_rdatasetc�����������������C���s$���|�j�D�]\}}}||kr�dS�qdS��NTF)r����)r?���r���rj���r@���r���r���r����_name_existsQ��s����z$RRsetsReaderTransaction._name_existsc�����������������C���s���t�|�j�dkS�r����)r����r�����r?���r���r���r����_changedW��s����z RRsetsReaderTransaction._changedc�����������������C���sf���|rb|�����rbg�}|�j���D�]:\\}}}}tj�||j|j|j�}|� |��|� |��q|�j�|��d�S�r+���) r����r����r����r����rrset�RRsetr���r]���r�����updater����r0���� set_rrsets)r?���Zcommit�rrsetsr���r@���r���r����r���r���r����_end_transactionZ��s����� z(RRsetsReaderTransaction._end_transactionc�����������������C���s���d�S�r+���r���)r?����originr���r���r���r����e��s����z#RRsetsReaderTransaction._set_originc�����������������C���s���t��d�S�r+�����NotImplementedErrorr����r���r���r����_iterate_rdatasetsh��s����z*RRsetsReaderTransaction._iterate_rdatasetsc�����������������C���s���t��d�S�r+���r����r����r���r���r����_iterate_namesk��s����z&RRsetsReaderTransaction._iterate_names)r���r���r ���rA���r����r����r����r����r����r����r����r����r����r����r����� __classcell__r���r���r����r���r����*��s��� r����c�������������������@���sN���e�Zd�Zejjdejjfdd�Zdd��Z ddd�Z dd ��Zd d��Zdd ��Z dS�)�RRSetsReaderManagerFc�����������������C���s���||�_�||�_||�_g�|�_d�S�r+���)r����r3���r���r����)r?���r����r3���r���r���r���r���rA���p��s����zRRSetsReaderManager.__init__c�����������������C���s���t��d�S�r+���r����r����r���r���r����readerx��s����zRRSetsReaderManager.readerc�����������������C���s���|du�sJ��t�|�dd�S�r����)r����)r?���r����r���r���r����writer{��s����zRRSetsReaderManager.writerc�����������������C���s���|�j�S�r+���)r���r����r���r���r���� get_class��s����zRRSetsReaderManager.get_classc�����������������C���s$���|�j�rtjj}n|�j}|�j|�j�|fS�r+���)r3���r���r����emptyr����)r?���Z effectiver���r���r���r1������s���� z&RRSetsReaderManager.origin_informationc�����������������C���s ���||�_�d�S�r+���)r����)r?���r����r���r���r���r�������s����zRRSetsReaderManager.set_rrsetsN)F)r���r���r ���r���r����rootrU����INrA���r����r����r����r1���r����r���r���r���r���r����o��s���� r����F)�textr���rQ���r����default_rdclassr]���r&���r����r����r3���rc���c �����������������C���s��t�|t�rtj�|tjj|�}t�|t�r8tj�|||�}t�|t�rNtj�|�}t�|t�rdtj�|�}|dur|tjj� |�}nd}tjj� |�}|dur�tj j� |�}nd}t|| |�} | � d��D}tjj|�d|d�}t|||d|||||d� } | ����W�d����n1��s0����Y��| jS�)a� ��Read one or more rrsets from the specified text, possibly subject to restrictions. *text*, a file object or a string, is the input to process. *name*, a string, ``dns.name.Name``, or ``None``, is the owner name of the rrset. If not ``None``, then the owner name is "forced", and the input must not specify an owner name. If ``None``, then any owner names are allowed and must be present in the input. *ttl*, an ``int``, string, or None. If not ``None``, the the TTL is forced to be the specified value and the input must not specify a TTL. If ``None``, then a TTL may be specified in the input. If it is not specified, then the *default_ttl* will be used. *rdclass*, a ``dns.rdataclass.RdataClass``, string, or ``None``. If not ``None``, then the class is forced to the specified value, and the input must not specify a class. If ``None``, then the input may specify a class that matches *default_rdclass*. Note that it is not possible to return rrsets with differing classes; specifying ``None`` for the class simply allows the user to optionally type a class as that may be convenient when cutting and pasting. *default_rdclass*, a ``dns.rdataclass.RdataClass`` or string. The class of the returned rrsets. *rdtype*, a ``dns.rdatatype.RdataType``, string, or ``None``. If not ``None``, then the type is forced to the specified value, and the input must not specify a type. If ``None``, then a type must be present for each RR. *default_ttl*, an ``int``, string, or ``None``. If not ``None``, then if the TTL is not forced and is not specified, then this value will be used. if ``None``, then if the TTL is not forced an error will occur if the TTL is not specified. *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA encoder/decoder. If ``None``, the default IDNA 2003 encoder/decoder is used. Note that codecs only apply to the owner name; dnspython does not do IDNA for names in rdata, as there is no IDNA zonefile format. *origin*, a string, ``dns.name.Name``, or ``None``, is the origin for any relative names in the input, and also the origin to relativize to if *relativize* is ``True``. *relativize*, a bool. If ``True``, names are relativized to the *origin*; if ``False`` then any relative names in the input are made absolute by appending the *origin*. NTz<input>)r����F)r!���r"���r#���r$���r%���r&���)� isinstancer\���r���r���rR���r����rQ���rU���r����ZmakerW���r����r����r����r����r����r���r����r����)r����r���rQ���r���r����r]���r&���r����r����r3���r0���r���r���r����r���r���r����read_rrsets���s>����= �(r����)6r���rl���rY����typingr���r���r���r���r���r���r���Z dns.exceptionr���Z dns.grangeZdns.nameZdns.nodeZ dns.rdataZdns.rdataclassZ dns.rdatatypeZdns.rdtypes.ANY.SOAZ dns.rrsetZ dns.tokenizerZdns.transactionZdns.ttlrH���ZDNSExceptionr ���r���r���r����r����r���r����rp���r����ZSavedStateTyper���r���r����r����r����ZTransactionManagerr����rU���r����r����r\���r����rW���r����Z IDNACodecr����r����r����r���r���r���r����<module>���st���$ �����UE � �