o
    Þý°jeo  ã                   @   sà  d Z ddlZddlZddlmZmZmZmZmZ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ZddlZddlZddlZddlZddlZddlZG dd„ dejjƒZG dd„ dejjƒZdd	„ ZeejjejjdB ejjdB edB e e!e e!f Z"d
d„ Z#G dd„ dƒZ$G dd„ dej%j&ƒZ'G dd„ dej%j(ƒZ)ddej*j+ej*j+dddejj,df	dedejje-B dB de dB dej*j.e-B dB dej*j.e-B dej/j0e-B dB de e-B dB dejj1dB dejje-B dB de!deej2j3 fdd„Z4dS ) z
DNS Zones.é    N)ÚAnyÚIterableÚListÚSetÚTupleÚcastc                   @   ó   e Zd ZdZdS )ÚUnknownOriginzUnknown originN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/dns/zonefile.pyr	   &   ó    r	   c                   @   r   )ÚCNAMEAndOtherDataz!A node has a CNAME and other dataNr
   r   r   r   r   r   *   r   r   c                 C   s|   t jj |¡}|  |¡}|d u rd S | ¡ }|t jjjkr(|t jjjkr(tdƒ‚|t jjjkr:|t jjjkr<tdƒ‚d S d S )Nz1rdataset type is not compatible with a CNAME nodez9CNAME rdataset is not compatible with a regular data node)	ÚdnsÚnodeÚNodeKindÚclassify_rdatasetÚget_nodeÚclassifyÚCNAMEÚREGULARr   )ÚtxnÚnameÚrdatasetÚrdataset_kindr   Ú	node_kindr   r   r   Ú_check_cname_and_other_data.   s   
ÿýr    c                 C   s   |   ¡ } |  d¡sd|  } | S )Nú$)ÚupperÚ
startswith)Úsr   r   r   Ú_upper_dollarizeQ   s   
r%   c                   @   sÐ   e Zd ZdZ							ddejjdejjdej	j
ded	eee B d
ejjdB dedB dejjdB dejjdB dedB fdd„Zdd„ Zdd„ Zdd„ Zdedeeeeeef fdd„Zdd„ Zd dd„ZdS )!Ú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 ur|}
|
d u r(d| _d| _	n|
| _d| _	| j| _
|| _|| _g | _d | _|  |du rRh d£| _|rQ| j d¡ n|du r[tƒ | _n
tdd„ |D ƒƒ| _|| _|| _|| _|	| _| j t¡ d S )Nr   FT>   ú$TTLú$ORIGINú	$GENERATEú$INCLUDEc                 s   s   � | ]}t |ƒV  qd S ©N)r%   )Ú.0Údr   r   r   Ú	<genexpr>†   s   € 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.   Úcheck_put_rdatasetr    )Úselfr'   r(   r   r)   r*   r+   r,   r-   r.   r/   Ú_r   r   r   Ú__init__[   s>   
€
zReader.__init__c                 C   s   	 | j  ¡ }| ¡ rd S qr4   )r'   ÚgetÚis_eol_or_eof©rH   Útokenr   r   r   Ú	_eat_line�   s
   
ýzReader._eat_linec                 C   s   | j  ¡ }| ¡ stjj‚|S r4   )r'   rK   Úis_identifierr   Ú	exceptionÚSyntaxErrorrM   r   r   r   Ú_get_identifier“   s   
zReader._get_identifierc           
   
   C   sj  d}| j dur| j }nV| jdu rt‚| jjdd�}| ¡ s'| j || j¡| _n| j ¡ }| ¡ r2dS | j 	|¡ | j}|du rEt
j d¡‚| jdusLJ ‚| | j¡sX|  ¡  dS | jra| | j¡}| jdurp| j}|| _d| _n)|  ¡ }d}zt
j |j¡}|| _d| _d}W n t
jjy˜   | j 	|¡ Y nw | jdur¢| j}n4|  ¡ }z	t
j |j¡}W n t
jjy¹   ‚  tyÊ   | j}| j 	|¡ Y nw || jkrÖt
j d¡‚|du �r|  ¡ }d}zt
j |j¡}|| _d| _d}W n! t
jj�y   | j�r| j}n| j�r| j}| j 	|¡ Y nw | jdu�r| j}n!|  ¡ }z	t
j  |j¡}W n t�y>   t
j d|j› d�¡‚w zt
j! ||| j| j| j| j¡}W n, t
jj�y[   ‚  t�y|   t" #¡ dd… \}}t
j d	t$|ƒ› d
t$|ƒ› �¡‚w | j�s |t
j j%k�r t&t
j'j(j%j%|ƒ}	|	j)| _d| _|du �r |	j)}|du �r«t
j d¡‚| j* +|||¡ dS )z&Process one line from a DNS zone file.NT)Úwant_leadingzthe last used name is undefinedúRR class is not zone's classúunknown rdatatype 'ú'é   úcaught exception ú: úMissing default TTL value),r+   r<   r	   r'   rK   Úis_whitespaceÚas_namer@   rL   Úungetr   rQ   rR   r:   Úis_subdomainrO   r;   r,   r=   r>   rS   ÚttlÚ	from_textÚvalueÚBadTTLr-   Ú
rdataclassÚ	ExceptionrA   r?   r/   r.   Ú	rdatatypeÚrdataÚsysÚexc_infoÚstrÚSOAr   ÚrdtypesÚANYÚminimumr   rE   )
rH   rN   r   r`   r(   ÚrdtypeÚrdÚtyÚvaÚsoa_rdr   r   r   Ú_rr_line™   s¾   



ÿ
þ

ûÿú ù	

zReader._rr_lineÚsideÚreturnc                 C   s  t  d¡}t  d¡}t  d¡}d}d}d}d}d}	| |¡}
|
r0|
 ¡ \}}}}}	|dkr/d}n0| |¡}|rI| ¡ \}}}|dkrDd}d}d}	n| |¡}|r`| ¡ \}}}}|dkr^d}d}	t|ƒ}t|ƒ}|dvrutj d	|› �¡‚|	d
vr‚tj d|	› �¡‚|||||	fS )Nz"^.*\$({(\+|-?)(\d+),(\d+),(.)}).*$z^.*\$({(\+|-?)(\d+)}).*$z^.*\$({(\+|-?)(\d+),(\d+)}).*$Ú ú+Ú0r6   )rx   ú-zinvalid offset sign )r6   ÚoÚxÚXÚnÚNzinvalid type )ÚreÚcompileÚmatchÚgroupsÚintr   rQ   rR   )rH   ru   Úis_generate1Úis_generate2Úis_generate3ÚmodÚsignÚoffsetÚwidthÚbaseÚg1Úg2Úg3ÚioffsetÚiwidthr   r   r   Ú_parse_modify  sD   



€

zReader._parse_modifyc                    s²  | j du rt‚| j ¡ }ztj |j¡\}}}| j ¡ }| ¡ s$tj	j
‚W n ty0   tj	j
‚w z|j}| j ¡ }| ¡ sBtj	j
‚W n tyN   tj	j
‚w ztj |j¡}|| _d| _| j ¡ }| ¡ sjtj	j
‚W n+ tjjy–   | js€| js€tj	 
d¡‚| jr‡| j}n| jrŽ| j}ntj	 
d¡‚Y nw ztj |j¡}| j ¡ }| ¡ s¬tj	j
‚W n tj	j
yº   tj	j
‚ tyÅ   | j}Y nw || jkrÑtj	 
d¡‚ztj |j¡}| j ¡ }| ¡ sætj	j
‚W n tyù   tj	 
d|j› d�¡‚w |j}	dtdtd	td
tfdd„}
dtdtdtd
tf‡ fdd„‰ |  |¡\}}}}}|  |	¡\}}}}}t||d |ƒD ]¡}|
|||ƒ}|
|||ƒ}ˆ |||ƒ}ˆ |||ƒ}| d|› �|¡}|	 d|› �|¡}tj || j | jj¡| _| j}| jdu�sxJ ‚| | j¡�s†|  ¡   dS | j �r�|  | j¡}ztj! |||| j | j | j¡}W n, tj	j
�y«   ‚  t�yÌ   t" #¡ dd… \}}tj	 
dt|ƒ› dt|ƒ› �¡‚w | j$ %|||¡ �q5dS )zPProcess one line containing the GENERATE statement from a DNS
        zone file.NTr[   rU   rV   rW   ÚcounterÚoffset_signrŠ   rv   c                 S   s   |dkr|d9 }| | S )z0Calculate the index from the counter and offset.rz   éÿÿÿÿr   )r“   r”   rŠ   r   r   r   Ú_calculate_index‰  s   z/Reader._generate_line.<locals>._calculate_indexÚindexrŒ   r‹   c                    sT   |dv rt | |ƒ |¡S ˆ | d|ƒ}d |ddd… ¡d|… }|dkr(| ¡ }|S )zVFormat the index with the given base, and zero-fill it
            to the given width.)r6   r{   r|   r}   r|   Ú.Nr•   r   )ÚformatÚzfillÚjoinr"   )r—   rŒ   r‹   ÚhexaÚnibbles©Ú_format_indexr   r   rŸ   �  s   z,Reader._generate_line.<locals>._format_indexé   r!   rX   rY   rZ   )&r<   r	   r'   rK   r   Úgrangera   rb   rP   rQ   rR   re   r`   r=   r>   rc   r?   r/   rd   rA   rf   r„   rj   r’   ÚrangeÚreplacer   Ú
idna_codecr@   r:   r_   rO   r;   rg   rh   ri   r   rE   )rH   rN   ÚstartÚstopÚstepÚlhsr`   r(   ro   Úrhsr–   ÚlmodÚlsignÚloffsetÚlwidthÚlbaseÚrmodÚrsignÚroffsetÚrwidthÚrbaseÚiÚlindexÚrindexÚlzfindexÚrzfindexr   rg   rp   rq   rr   r   rž   r   Ú_generate_lineB  sÌ   


ÿÿ
ÿÿ
ÿ€õ
ÿ
ÿ

ÿÿÿúÿùÒzReader._generate_linec           	   
   C   sÌ  �z-	 | j  dd¡}| ¡ r9| jdur| j ¡  t| jƒdkr6| j d¡\| _ | _| _	| _| _
| _| _| _qW dS | ¡ r>q| ¡ rH| j  ¡  q|jd dk�r$t| jƒdk�r$|j ¡ }|| jvrltj d|› d�¡‚|d	kr�| j  ¡ }| ¡ stj d
¡‚tj |j¡| _d| _| j  ¡  n“|dkr°| j  ¡ | _| j  ¡  | jdu r¨| j| _| j | j¡ ns|dk�r| j  ¡ }|j}| j  ¡ }| ¡ rØtj |j| j| j j¡}| j  ¡  n|  ¡ sâtj d¡‚| j}| j !| j | j| j	| j| j
| j| j| jf¡ t"|dd�| _tj# $| j|¡| _ || _n|dk�r|  %¡  n
tj d|› d�¡‚q| j  &|¡ |  '¡  q tjj�ye } z(| j  (¡ \}}|du �rGd}tj |› d|› d|› �¡}t) *¡ d }| +|¡d‚d}~ww )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
        r    TNr   r•   r!   zzone file directive 'z' is not allowedr0   zbad $TTLr1   r3   zbad origin in $INCLUDEzutf-8)Úencodingr2   zUnknown zone file directive 'rW   zsyntax errorú:rZ   rX   ),r'   rK   Úis_eofrC   ÚcloseÚlenrB   Úpopr<   r@   r=   r>   r/   r?   Úis_eolÚ
is_commentÚget_eolrb   rD   r"   r   rQ   rR   rP   r`   ra   Úget_namer:   r   Ú_set_originr   r¤   rL   ÚappendÚopenÚ	tokenizerÚ	Tokenizerr¹   r^   rt   Úwhererh   ri   Úwith_traceback)	rH   rN   ÚcÚfilenameÚ
new_originÚdetailÚline_numberÚexÚtbr   r   r   ÚreadÎ  s®   



÷
 


ÿ





ÿøÿ


ÿ¯R
€úzReader.read)FTNNNNN)rv   N)r   r   r   r   r   rÇ   rÈ   rd   Ú
RdataClassÚtransactionÚTransactionÚboolr   rj   r   ÚNamer„   rf   Ú	RdataTyperJ   rO   rS   rt   r   r’   r¹   rÒ   r   r   r   r   r&   X   sJ    õþýüû
ú
ùø
	÷

ö
õ2 |- r&   c                       st   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚRRsetsReaderTransactionc                    s"   |rJ ‚t ƒ  |||¡ i | _d S r4   )ÚsuperrJ   Ú	rdatasets)rH   r8   ÚreplacementÚ	read_only©Ú	__class__r   r   rJ   2  s   
z RRsetsReaderTransaction.__init__c                 C   s   | j  |||f¡S r4   )rÛ   rK   ©rH   r   ro   Úcoversr   r   r   Ú_get_rdataset7  s   z%RRsetsReaderTransaction._get_rdatasetc                 C   sT   g }| j  ¡ D ]\\}}}}||kr| |¡ qt|ƒdkr d S tj ¡ }||_ |S ©Nr   )rÛ   ÚitemsrÅ   r¾   r   r   ÚNode)rH   r   rÛ   Úrdataset_namerI   r   r   r   r   r   Ú	_get_node:  s   
€
z!RRsetsReaderTransaction._get_nodec                 C   s   || j ||j|jf< d S r4   )rÛ   ro   rá   )rH   r   r   r   r   r   Ú_put_rdatasetE  s   z%RRsetsReaderTransaction._put_rdatasetc                 C   sL   g }| j D ]}|d |kr| |¡ qt|ƒdkr"|D ]}| j |= qd S d S rã   )rÛ   rÅ   r¾   )rH   r   ÚremoveÚkeyr   r   r   Ú_delete_nameH  s   

€
þz$RRsetsReaderTransaction._delete_namec                 C   s*   z
| j |||f= W d S  ty   Y d S w r4   )rÛ   ÚKeyErrorrà   r   r   r   Ú_delete_rdatasetR  s
   ÿz(RRsetsReaderTransaction._delete_rdatasetc                 C   s$   | j D ]\}}}||kr dS qdS ©NTF)rÛ   )rH   r   r~   rI   r   r   r   Ú_name_existsX  s
   ÿz$RRsetsReaderTransaction._name_existsc                 C   s   t | jƒdkS rã   )r¾   rÛ   ©rH   r   r   r   Ú_changed^  s   z RRsetsReaderTransaction._changedc                 C   sn   |r3|   ¡ r5g }| j ¡ D ]\\}}}}tj ||j|j|j¡}| 	|¡ | 
|¡ q| j |¡ d S d S d S r4   )rñ   rÛ   rä   r   ÚrrsetÚRRsetr(   ro   rá   ÚupdaterÅ   r8   Ú
set_rrsets)rH   ÚcommitÚrrsetsr   rI   r   rò   r   r   r   Ú_end_transactiona  s   ÿ
øz(RRsetsReaderTransaction._end_transactionc                 C   s   d S r4   r   )rH   Úoriginr   r   r   rÄ   l  ó   z#RRsetsReaderTransaction._set_originc                 C   ó   t ‚r4   ©ÚNotImplementedErrorrð   r   r   r   Ú_iterate_rdatasetso  rú   z*RRsetsReaderTransaction._iterate_rdatasetsc                 C   rû   r4   rü   rð   r   r   r   Ú_iterate_namesr  rú   z&RRsetsReaderTransaction._iterate_names)r   r   r   rJ   râ   rç   rè   rë   rí   rï   rñ   rø   rÄ   rþ   rÿ   Ú__classcell__r   r   rÞ   r   rÙ   1  s    
rÙ   c                   @   sz   e Zd ZejjdejjfdejjdB de	dejj
fdd„Zdd	„ Zdd
d„Zdd„ Zdd„ Zdeejj ddfdd„ZdS )ÚRRSetsReaderManagerFrù   Nr;   r(   c                 C   s   || _ || _|| _g | _d S r4   )rù   r;   r(   r÷   )rH   rù   r;   r(   r   r   r   rJ   w  s   
zRRSetsReaderManager.__init__c                 C   rû   r4   rü   rð   r   r   r   Úreader‚  rú   zRRSetsReaderManager.readerc                 C   s   |du sJ ‚t | ddƒS rî   )rÙ   )rH   rÜ   r   r   r   Úwriter…  s   zRRSetsReaderManager.writerc                 C   s   | j S r4   )r(   rð   r   r   r   Ú	get_class‰  s   zRRSetsReaderManager.get_classc                 C   s$   | j rtjj}n| j}| j| j |fS r4   )r;   r   r   Úemptyrù   )rH   Ú	effectiver   r   r   r9   Œ  s   
z&RRSetsReaderManager.origin_informationr÷   rv   c                 C   s
   || _ d S r4   )r÷   )rH   r÷   r   r   r   rõ   “  s   
zRRSetsReaderManager.set_rrsets)F)r   r   r   r   r   Úrootrd   ÚINr×   rÖ   rÓ   rJ   r  r  r  r9   r   rò   ró   rõ   r   r   r   r   r  v  s     ü
þý
ü
r  FÚtextr   r`   r(   Údefault_rdclassro   r/   r¤   rù   r;   rv   c
                 C   s  t |tƒrtj |tjj|¡}t |tƒrtj |||¡}t |tƒr'tj |¡}t |tƒr2tj |¡}|dur>tjj 	|¡}nd}tjj 	|¡}|durStj
j 	|¡}nd}t||	|ƒ}
|
 d¡�$}tjj| d|d�}t|||d|||||d�	}| ¡  W d  ƒ |
jS 1 s‡w   Y  |
jS )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/   )Ú
isinstancerj   r   r   ra   r  r`   rd   rÓ   Úmakerf   rØ   r  r  rÇ   rÈ   r&   rÒ   r÷   )r	  r   r`   r(   r
  ro   r/   r¤   rù   r;   r8   r   r'   r  r   r   r   Úread_rrsets—  sD   
=


÷

óòr  )5r   r€   rh   Útypingr   r   r   r   r   r   Údns.exceptionr   Ú
dns.grangeÚdns.nameÚdns.nodeÚ	dns.rdataÚdns.rdataclassÚdns.rdatatypeÚdns.rdtypes.ANY.SOAÚ	dns.rrsetÚdns.tokenizerÚdns.transactionÚdns.ttlrQ   ÚDNSExceptionr	   r   r    rÇ   rÈ   r   r×   r„   rÖ   ÚSavedStateTyper%   r&   rÔ   rÕ   rÙ   ÚTransactionManagerr  rd   r  r  rj   rÓ   rf   rØ   Ú	IDNACodecrò   ró   r  r   r   r   r   Ú<module>   sŠ    

ùÿ   \E#öÿþýü
ûú
ù
ø	÷
ö
õ