o
    Þý°j3  ã                   @   s.  d dl Z d dlmZ d dl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	G dd„ de jƒZG dd„ de	jjƒZe	jjG dd	„ d	eƒƒZG d
d„ de	jje	jj ƒZG dd„ de	jjƒZedd�G dd„ dƒƒZe	jjG dd„ de	jj ƒƒZ!G dd„ de	j"j#ƒZ#dS )é    N)Ú	dataclass)ÚCallableÚMutableMappingÚTupleÚcastc                   @   s   e Zd ZdZdZdZdS )Ú	NodeFlagsé   é   é   N)Ú__name__Ú
__module__Ú__qualname__ÚORIGINÚ
DELEGATIONÚGLUE© r   r   ú€/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/dns/btreezone.pyr      s    r   c                       sP   e Zd ZddgZddedB f‡ fdd„Zdd„ Zdd	„ Zd
d„ Zdd„ Z	‡  Z
S )ÚNodeÚflagsÚidNc                    s*   t ƒ  ¡  |d u rtdƒ}|| _d| _d S ©Nr   )ÚsuperÚ__init__r   r   r   )Úselfr   ©Ú	__class__r   r   r   &   s
   

zNode.__init__c                 C   ó   | j tj@ dkS r   )r   r   r   ©r   r   r   r   Úis_delegation0   ó   zNode.is_delegationc                 C   r   r   )r   r   r   r   r   r   r   Úis_glue3   r   zNode.is_gluec                 C   r   r   )r   r   r   r   r   r   r   Ú	is_origin6   r   zNode.is_originc                 C   s   | j tjtjB @ dkS r   )r   r   r   r   r   r   r   r   Úis_origin_or_glue9   s   zNode.is_origin_or_glue©N)r   r   r   Ú	__slots__r   r   r   r    r!   r"   Ú__classcell__r   r   r   r   r   #   s    
r   c                       sð   e Zd Zdef‡ fdd„Zejjdfdejj	dejj
dejj
ded	ejjf
‡ fd
d„Zejjdfdejj	dejj
dejj
ded	ejjdB f
‡ fdd„Zejjfdejj	dejj
dejj
d	dfdd„Zdejjd	dfdd„Zd	efdd„Z‡  ZS )ÚImmutableNodeÚnodec                    s4   t ƒ  ¡  |j| _tdd„ |jD ƒƒ| _|j| _d S )Nc                 S   s   g | ]}t j |¡‘qS r   )ÚdnsÚrdatasetÚImmutableRdataset)Ú.0Úrdsr   r   r   Ú
<listcomp>C   s    z*ImmutableNode.__init__.<locals>.<listcomp>)r   r   r   ÚtupleÚ	rdatasetsr   )r   r'   r   r   r   r   ?   s   
ÿzImmutableNode.__init__FÚrdclassÚrdtypeÚcoversÚcreateÚreturnc                    ó   |rt dƒ‚tƒ  |||d¡S ©NÚ	immutableF)Ú	TypeErrorr   Úfind_rdataset©r   r0   r1   r2   r3   r   r   r   r9   G   ó   zImmutableNode.find_rdatasetNc                    r5   r6   )r8   r   Úget_rdatasetr:   r   r   r   r<   R   r;   zImmutableNode.get_rdatasetc                 C   ó   t dƒ‚©Nr7   ©r8   )r   r0   r1   r2   r   r   r   Údelete_rdataset]   s   zImmutableNode.delete_rdatasetÚreplacementc                 C   r=   r>   r?   )r   rA   r   r   r   Úreplace_rdatasete   s   zImmutableNode.replace_rdatasetc                 C   s   dS ©NTr   r   r   r   r   Úis_immutableh   s   zImmutableNode.is_immutable)r   r   r   r   r   r(   Ú	rdatatypeÚNONEÚ
rdataclassÚ
RdataClassÚ	RdataTypeÚboolr)   ÚRdatasetr9   r<   r@   rB   rD   r%   r   r   r   r   r&   =   sP    ûþýüûúûþýüû
úüþýü
ûr&   c                   @   sH   e Zd ZdejjdeejjdB ef fdd„Zdejjdefdd„Z	dS )ÚDelegationsÚnamer4   Nc                 C   sn   |   ¡ }|j|dd� | ¡ }|du rdS | ¡ }| |¡\}}}|tjjjk}|s1|tjjj	kr5||fS dS )aF  Get the delegation applicable to *name*, if it exists.

        If there delegation, then return a tuple consisting of the name of
        the delegation point, and a boolean which is `True` if the name is a proper
        subdomain of the delegation point, and `False` if it is equal to the delegation
        point.
        F©ÚbeforeN©NF)
ÚcursorÚseekÚprevÚkeyÚfullcomparer(   rM   ÚNameRelationÚ	SUBDOMAINÚEQUAL)r   rM   rQ   rS   ÚcutÚrelnÚ_Úis_subdomainr   r   r   Úget_delegationm   s   zDelegations.get_delegationc                 C   s4   |   ¡ }|j|dd� |  |¡\}}|du rdS |S )z0Is *name* glue, i.e. is it beneath a delegation?FrN   N)rQ   rR   r]   )r   rM   rQ   rY   r\   r   r   r   r    ‚   s   zDelegations.is_glue)
r   r   r   r(   rM   ÚNamer   rJ   r]   r    r   r   r   r   rL   l   s    &rL   c                       sà   e Zd Zddejjdef‡ fdd„Zdejj	defdd	„Z
dejj	deejjejj	f f‡ fd
d„Zdejj	deddfdd„Zdejj	ddfdd„Zdejj	dejjddfdd„Zdejj	dejjdejjddfdd„Z‡  ZS )ÚWritableVersionFÚzonerA   c                    s^   t ƒ  |d¡ |s)t|tjjƒsJ ‚|jd }tjj|j	d�| _	t
|jd�| _d S t
ƒ | _d S )NTéÿÿÿÿ)Úoriginal)r   r   Ú
isinstancer(   Ú	versionedÚZoneÚ	_versionsÚbtreeÚ	BTreeDictÚnodesrL   Údelegations)r   r`   rA   Úversionr   r   r   r   �   s   
ÿzWritableVersion.__init__rM   r4   c                 C   s    | j jr
|tjjkS || j jkS r#   )r`   Ú
relativizer(   rM   ÚemptyÚorigin)r   rM   r   r   r   Ú
_is_origin™   s   zWritableVersion._is_originc                    s`   t ƒ  |¡\}}tt|ƒ}|  |¡r| jtjO  _||fS | j 	|¡r,| jtj
O  _||fS r#   )r   Ú_maybe_cow_with_namer   r   ro   r   r   r   rj   r    r   ©r   rM   r'   r   r   r   rp   ¡   s   

þz$WritableVersion._maybe_cow_with_namer    Nc           	      C   sð   | j  ¡ }| |d¡ g }	 | ¡ }|d u rnS| ¡ }| |¡s!nIttjj	| 
¡ ƒ}|| jvrG| j ¡ }| j|_|j |j¡ | j |¡ |}t|t	ƒsNJ ‚|rY| jtjO  _n	| jtj M  _| ||f¡ q|D ]	\}}|| j |< qld S rP   )ri   rQ   rR   ÚnextrT   r\   r   r(   r'   r   ÚvalueÚchangedr`   Únode_factoryr   r/   ÚextendÚaddrc   r   r   r   Úappend)	r   rM   r    rQ   ÚupdatesÚeltÚenamer'   Únew_noder   r   r   Úupdate_glue_flag¬   s4   



éÿz WritableVersion.update_glue_flagc                 C   sZ   |   |¡}| j |¡}|d ur+| ¡ r| j |¡ |  |d¡ | j|= | j |¡ d S d S rP   )	Ú_validate_nameri   Úgetr   rj   Údiscardr}   rt   rw   rq   r   r   r   Údelete_nodeË   s   
ûzWritableVersion.delete_noder)   c                 C   sd   |   |¡\}}|jtjjkr+| ¡ s+| jtjO  _|| j	vr+| j	 
|¡ |  |d¡ | |¡ d S rC   )rp   r1   r(   rE   ÚNSr"   r   r   r   rj   rw   r}   rB   )r   rM   r)   r'   r   r   r   Úput_rdatasetÕ   s   
zWritableVersion.put_rdatasetr1   r2   c                 C   s|   |   |¡\}}|tjjkr'|| jv r'| jtj M  _| j |¡ |  	|d¡ | 
| jj||¡ t|ƒdkr<| j|= d S d S )NFr   )rp   r(   rE   r‚   rj   r   r   r   r€   r}   r@   r`   r0   Úlenri   )r   rM   r1   r2   r'   r   r   r   r@   â   s   ÿzWritableVersion.delete_rdataset)F)r   r   r   r(   r`   re   rJ   r   rM   r^   ro   r   r'   r   rp   r}   r�   r)   rK   rƒ   rE   rI   r@   r%   r   r   r   r   r_   Œ   s4    ÿþ
ÿÿ
þþýüûr_   T)Úfrozenc                   @   sZ   e Zd ZU ejjed< ejjed< ejjdB ed< ejjed< eed< eed< dd	„ ZdS )
ÚBoundsrM   ÚleftNÚrightÚclosest_encloserÚis_equalr   c              
   C   sL   | j rd}nd}| jrd}nd}| j› d|› d| j› d| j› |› d| j› �
S )Nú=ú<z zonecutÚ ú z < z; )rŠ   r   r‡   rM   rˆ   r‰   )r   ÚopÚzonecutr   r   r   Ú__str__û   s   "ÿÿzBounds.__str__)	r   r   r   r(   rM   r^   Ú__annotations__rJ   r‘   r   r   r   r   r†   ò   s   
 r†   c                       s@   e Zd Zdejjf‡ fdd„Zdejje	B de
fdd„Z‡  ZS )ÚImmutableVersionrk   c                    sš   t |tƒs	tdƒ‚tƒ  |jd¡ |j| _|j| _|jD ]}|j	 
|¡}|r-t|ƒ|j	|< qtttjjtjjf |j	ƒ| _	| j	 ¡  |j| _| j ¡  d S )NzIa dns.btreezone.ImmutableVersion requires a dns.btreezone.WritableVersionT)rc   r_   Ú
ValueErrorr   r   r`   r   rn   rt   ri   r   r&   r   r   r(   rM   r^   r'   r   Úmake_immutablerj   )r   rk   rM   r'   r   r   r   r     s    
ÿ
€
zImmutableVersion.__init__rM   r4   c                 C   s8  | j dusJ ‚| j | j ¡}| j |¡}| j |¡\}}|dur%|}d}n|}d}ttjj| j	ƒ 
¡ }| |d¡ | ¡ }|dusCJ ‚| ¡  	 | ¡ }	|	du sV|	 ¡  ¡ sWnqH| ¡  |¡}
|	durm|	 ¡ }| |¡}ntjjdt|ƒf}d}tj |t|
d |d ƒ d… ¡}t|| ¡ |||
d tjjjk|ƒS )aT  Return the 'bounds' of *name* in its zone.

        The bounds information is useful when making an authoritative response, as
        it can be used to determine whether the query name is at or beneath a delegation
        point.  The other data in the ``Bounds`` object is useful for making on-the-fly
        DNSSEC signatures.

        The left bound of *name* is *name* itself if it is in the zone, or the greatest
        predecessor which is in the zone.

        The right bound of *name* is the least successor of *name*, or ``None`` if
        no name in the zone is greater than *name*.

        The closest encloser of *name* is *name* itself, if *name* is in the zone;
        otherwise it is the name with the largest number of labels in common with
        *name* that is in the zone, either explicitly or by the implied existence
        of empty non-terminals.

        The bounds *is_equal* field is ``True`` if and only if *name* is equal to
        its left bound.

        The bounds *is_delegation* field is ``True`` if and only if the left bound is a
        delegation point.
        NTFra   r	   r   )rn   r`   r~   rj   r]   r   r(   rg   rh   ri   rQ   rR   rS   rr   rs   r    rT   rU   rM   ÚNAMERELN_COMMONANCESTORr„   r^   Úmaxr†   rV   rX   )r   rM   rn   rY   r[   Útargetr   Úcr‡   rˆ   Úleft_comparisonÚ	right_keyÚright_comparisonr‰   r   r   r   Úbounds  sN   ýýÿúzImmutableVersion.bounds)r   r   r   r(   r`   ÚVersionr   rM   r^   Ústrr†   r�   r%   r   r   r   r   r“   
  s    "r“   c                   @   s¾   e Zd ZU eZeg ejjf ed< e	eg e
ejjejjf f ejjejjef ƒZeg e
ejjejjf f ed< eZeejjegejjf dB ed< eZeejjgejjf dB ed< dS )re   ru   Úmap_factoryNÚwritable_version_factoryÚimmutable_version_factory)r   r   r   r   ru   r   r(   r'   r’   r   r   rM   r^   rg   rh   r    r_   r¡   r`   re   rJ   rž   r“   r¢   r   r   r   r   re   d  s   
 $þþÿ$ÿre   )$ÚenumÚdataclassesr   Útypingr   r   r   r   Ú	dns.btreer(   Údns.immutableÚdns.nameÚdns.nodeÚdns.rdataclassÚdns.rdatasetÚdns.rdatatypeÚdns.versionedÚdns.zoneÚIntFlagr   r'   r   r7   r&   rg   ÚBTreeSetrM   r^   rL   r`   r_   r†   rž   r“   rd   re   r   r   r   r   Ú<module>   s.   . fY