
    h3                        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e j$                        Z G d de	j(                  j*                        Ze	j,                  j,                   G d d	e             Z G d
 de	j0                  j2                  e	j4                  j6                           Z G d de	j:                  j<                        Z ed       G d d             Ze	j,                  j,                   G d de	j:                  j@                               Z! G d de	jD                  jF                        Z#y)    N)	dataclass)CallableMutableMappingTuplecastc                       e Zd ZdZdZdZy)	NodeFlags         N)__name__
__module____qualname__ORIGIN
DELEGATIONGLUE     K/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/dns/btreezone.pyr	   r	      s    FJDr   r	   c                   L     e Zd ZddgZd	dedz  f fdZd Zd Zd Zd Z	 xZ
S )
NodeflagsidNc                 X    t         |           |t        d      }|| _        d| _        y Nr   )super__init__r	   r   r   )selfr   	__class__s     r   r   zNode.__init__&   s,    = aLE
r   c                 B    | j                   t        j                  z  dk7  S r   )r   r	   r   r   s    r   is_delegationzNode.is_delegation0   s    

Y111a77r   c                 B    | j                   t        j                  z  dk7  S r   )r   r	   r   r!   s    r   is_gluezNode.is_glue3   s    

Y^^+11r   c                 B    | j                   t        j                  z  dk7  S r   )r   r	   r   r!   s    r   	is_originzNode.is_origin6   s    

Y---!33r   c                 d    | j                   t        j                  t        j                  z  z  dk7  S r   )r   r	   r   r   r!   s    r   is_origin_or_gluezNode.is_origin_or_glue9   s%    

i..?@QFFr   N)r   r   r   	__slots__r	   r   r"   r$   r&   r(   __classcell__r   s   @r   r   r   #   s2    $Ii$. 824Gr   r   c                       e Zd Zdef f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	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
z  f
 fdZej                  j                  fdej                  j                  dej                  j                  dej                  j                  dd
fdZdej                  j                  dd
fdZdefdZ xZS )ImmutableNodenodec                     t         |           |j                  | _        t        |j                  D cg c]!  }t
        j                  j                  |      # c}      | _        |j                  | _        y c c}w r)   )	r   r   r   tuple	rdatasetsdnsrdatasetImmutableRdatasetr   )r   r/   rdsr   s      r   r   zImmutableNode.__init__?   sY    ''<@NNKSS\\++C0K
 ZZ
 Ls   &A8Frdclassrdtypecoverscreatereturnc                 B    |rt        d      t        | 	  |||d      S N	immutableF)	TypeErrorr   find_rdatasetr   r7   r8   r9   r:   r   s        r   r@   zImmutableNode.find_rdatasetG   s)     K((w$WffeDDr   Nc                 B    |rt        d      t        | 	  |||d      S r=   )r?   r   get_rdatasetrA   s        r   rC   zImmutableNode.get_rdatasetR   s)     K((w#GVVUCCr   c                     t        d      Nr>   r?   )r   r7   r8   r9   s       r   delete_rdatasetzImmutableNode.delete_rdataset]   s     $$r   replacementc                     t        d      rE   rF   )r   rH   s     r   replace_rdatasetzImmutableNode.replace_rdatasete   s    $$r   c                      yNTr   r!   s    r   is_immutablezImmutableNode.is_immutableh   s    r   )r   r   r   r   r   r3   	rdatatypeNONE
rdataclass
RdataClass	RdataTypeboolr4   Rdatasetr@   rC   rG   rJ   rM   r+   r,   s   @r   r.   r.   =   s    T   +.--*<*<	E**	E ''	E ''		E
 	E 
			E +.--*<*<	D**	D ''	D ''		D
 	D 
			%	D +.--*<*<	%**% ''% ''	%
 
%%CLL,A,A %d %d r   r.   c                       e Zd Zdej                  j
                  deej                  j
                  dz  ef   fdZdej                  j
                  defdZ	y)Delegationsnamer;   Nc                 b   | j                         }|j                  |d       |j                         }|y|j                         }|j	                  |      \  }}}|t
        j                  j                  j                  k(  }|s'|t
        j                  j                  j                  k(  r||fS y)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beforeNF)
cursorseekprevkeyfullcomparer3   rW   NameRelation	SUBDOMAINEQUAL)r   rW   r\   r^   cutreln_is_subdomains           r   get_delegationzDelegations.get_delegationm   s     D'{{}<hhj%%c*
asxx44>>>4388#8#8#>#>>$$r   c                 z    | j                         }|j                  |d       | j                  |      \  }}|y|S )z0Is *name* glue, i.e. is it beneath a delegation?FrY   )r\   r]   rh   )r   rW   r\   rd   rg   s        r   r$   zDelegations.is_glue   s@    D' //5\;r   )
r   r   r   r3   rW   Namer   rS   rh   r$   r   r   r   rV   rV   l   sP    388== U388==4;OQU;U5V *CHHMM d r   rV   c                       e Zd Zddej                  j
                  def fdZdej                  j                  defdZ
dej                  j                  deej                  j                  ej                  j                  f   f fdZdej                  j                  dedd	fd
Zdej                  j                  dd	fdZdej                  j                  dej"                  j$                  dd	fdZdej                  j                  dej(                  j*                  dej(                  j*                  dd	fdZ xZS )WritableVersionzonerH   c                 H   t         |   |d       |st        |t        j                  j
                        sJ |j                  d   }t        j                  j                  |j                        | _	        t        |j                        | _        y t               | _        y )NT)original)r   r   
isinstancer3   	versionedZone	_versionsbtree	BTreeDictnodesrV   delegations)r   rm   rH   versionr   s       r   r   zWritableVersion.__init__   s    t$dCMM$6$6777nnR(GCF99CVCV  DW DDJ  +G4G4GHD*}Dr   rW   r;   c                     | j                   j                  r|t        j                  j                  k(  S || j                   j
                  k(  S r)   )rm   
relativizer3   rW   emptyorigin)r   rW   s     r   
_is_originzWritableVersion._is_origin   s9     99388>>))499++++r   c                 <   t         |   |      \  }}t        t        |      }| j	                  |      r'|xj
                  t        j                  z  c_        ||fS | j                  j                  |      r#|xj
                  t        j                  z  c_        ||fS r)   )r   _maybe_cow_with_namer   r   r~   r   r	   r   rx   r$   r   )r   rW   r/   r   s      r   r   z$WritableVersion._maybe_cow_with_name   s     w3D9tD$??4 JJ)***J d| %%d+JJ)..(Jd|r   r$   Nc                 >   | j                   j                         }|j                  |d       g }	 |j                         }|nA|j	                         }|j                  |      snt        t        j                  j                  |j                               }|| j                  vrm| j                  j                         }| j                  |_        |j                  j!                  |j                         | j                  j#                  |       |}t%        |t              sJ |r$|xj&                  t(        j*                  z  c_        n$|xj&                  t(        j*                   z  c_        |j-                  ||f       U|D ]  \  }}|| j                   |<    y r[   )rw   r\   r]   nextr_   rg   r   r3   r/   r   valuechangedrm   node_factoryr   r2   extendaddrq   r   r	   r   append)	r   rW   r$   r\   updateseltenamer/   new_nodes	            r   update_glue_flagz WritableVersion.update_glue_flag   s>   ""$D% ++-C{GGIE%%d+syy{3DDLL(99113"gg""))$..9  'dD)))

inn,


y~~o-

 NNE4=)/ 0 # 	%KE4 $DJJu	%r   c                 ,   | j                  |      }| j                  j                  |      }|f|j                         r-| j                  j                  |       | j                  |d       | j                  |= | j                  j                  |       y y r[   )	_validate_namerw   getr"   rx   discardr   r   r   )r   rW   r/   s      r   delete_nodezWritableVersion.delete_node   s}    ""4(zz~~d#!!#  ((.%%dE2

4 LLT" r   r4   c                 x   | j                  |      \  }}|j                  t        j                  j                  k(  rn|j                         s^|xj                  t        j                  z  c_        || j                  vr-| j                  j                  |       | j                  |d       |j                  |       y rL   )r   r8   r3   rN   NSr(   r   r	   r   rx   r   r   rJ   )r   rW   r4   r/   s       r   put_rdatasetzWritableVersion.put_rdataset   s     006tOOs}}///8N8N8PJJ)...J4+++  $$T*%%dD1h'r   r8   r9   c                    | j                  |      \  }}|t        j                  j                  k(  r_|| j                  v rQ|xj
                  t        j                   z  c_        | j                  j                  |       | j                  |d       |j                  | j                  j                  ||       t        |      dk(  r| j                  |= y y )NFr   )r   r3   rN   r   rx   r   r	   r   r   r   rG   rm   r7   lenrw   )r   rW   r8   r9   r/   s        r   rG   zWritableVersion.delete_rdataset   s     006tS]]%%%$$2B2B*BJJ9////J$$T*!!$.TYY..?t9>

4  r   )F)r   r   r   r3   rm   rs   rS   r   rW   rj   r~   r   r/   r   r   r   r   r4   rT   r   rN   rR   rG   r+   r,   s   @r   rl   rl      s#   
-SXX]] 
- 
-,sxx}} , ,	HHMM		sxx}}chhmm+	,	%SXX]] %T %d %># #$ #(HHMM(-0\\-B-B(	(!hhmm! ''! ''	!
 
!r   rl   T)frozenc                       e Zd ZU ej                  j
                  ed<   ej                  j
                  ed<   ej                  j
                  dz  ed<   ej                  j
                  ed<   eed<   eed<   d Zy)	BoundsrW   leftNrightclosest_encloseris_equalr"   c           
          | 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   rW   r   r   )r   opzonecuts      r   __str__zBounds.__str__   se    ==BB GGyyk2$a		{#djj\'"$$%'	
r   )	r   r   r   r3   rW   rj   __annotations__rS   r   r   r   r   r   r      sO    
((--
((--88==4hhmm#N
r   r   c                        e Zd Zdej                  j
                  f fdZdej                  j                  e	z  de
fdZ xZS )ImmutableVersionry   c                 t   t        |t              st        d      t        |   |j
                  d       |j                  | _        |j                  | _        |j                  D ]8  }|j                  j                  |      }|s!t        |      |j                  |<   : t        t        t        j                  j                   t        j"                  j$                  f   |j                        | _	        | j                  j'                          |j(                  | _        | j(                  j'                          y )NzIa dns.btreezone.ImmutableVersion requires a dns.btreezone.WritableVersionT)rq   rl   
ValueErrorr   r   rm   r   r}   r   rw   r   r.   r   r   r3   rW   rj   r/   r   make_immutablerx   )r   ry   rW   r/   r   s       r   r   zImmutableVersion.__init__  s    '?30  	t,**nnOO 	:D==$$T*D&3D&9d#	:
 .)EFV


!!#"..'')r   rW   r;   c                    | j                   J | j                  j                  | j                         }| j                  j                  |      }| j                  j	                  |      \  }}||}d}n|}d}t        t        j                  j                  | j                        j                         }|j                  |d       |j                         }|J |j                          	 |j                         }	|	|	j                         j                         sn2|j!                         j#                  |      }
|	"|	j!                         }|j#                  |      }n(t        j$                  j&                  dt)        |      f}d}t        j$                  j+                  |t-        |
d   |d          d       }t/        ||j!                         |||
d   t        j$                  j0                  j2                  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.
        NTFro   r   r   )r}   rm   r   rx   rh   r   r3   ru   rv   rw   r\   r]   r^   r   r   r$   r_   r`   rW   NAMERELN_COMMONANCESTORr   rj   maxr   ra   rc   )r   rW   r}   rd   rf   targetr"   cr   r   left_comparison	right_keyright_comparisonr   s                 r   boundszImmutableVersion.bounds  s   2 {{&&&))$++6yy''-!!006Q?F MF!M$$djj188:	vuvvx	FFHE}EKKM$9$9$;  ((*006		I(44T: 00F 
 I88==#oa(*:1*=>>@A
 HHJA#(("7"7"="==
 	
r   )r   r   r   r3   rm   Versionr   rW   rj   strr   r   r+   r,   s   @r   r   r   
  s<    * 0 0 *&B
388==3. B
6 B
r   r   c                   n   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z  ed<   eZeej$                  j*                  gej$                  j*                  f   dz  ed<   y)rs   r   map_factoryNwritable_version_factoryimmutable_version_factory)r   r   r   r   r   r   r3   r/   r   r   r   rW   rj   ru   rv   r   rl   r   rm   rs   rS   r   r   r   r   r   r   rs   rs   d  s
   04L(2sxx}},-4NR^CHHMM388==$@AAB		CHHMM4/0OK"nSXX]]CHHMM-IJJK  	 #((--&(8(889D@ 	 x)9)9(:CHH<L<L(LMPTT r   rs   )$enumdataclassesr   typingr   r   r   r   	dns.btreer3   dns.immutabledns.namedns.nodedns.rdataclassdns.rdatasetdns.rdatatypedns.versioneddns.zoneIntFlagr	   r/   r   r>   r.   ru   BTreeSetrW   rj   rV   rm   rl   r   r   r   rr   rs   r   r   r   <module>r      s    ! 8 8          G388== G4 +D + +\#))$$SXX]]3 @c!chh.. c!L $
 
 
. V
sxx'' V
 V
r3== r   