
    Eqgw1                     f   d Z ddlZddlZddl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ej        j        hZej        j        ej        j        ej        j        hZd Zej         G d dej                              Z G d d          Zej        j         G d	 d
e                      ZdS )z)DNS nodes.  A node is a set of rdatasets.    N)AnyDictOptionalc                 <    || v p|t           j        j        k    o|| v S N)dns	rdatatypeRRSIG)rdtypesrdtypecoverss      :/var/www/html/env/lib/python3.11/site-packages/dns/node.py_matches_type_or_its_signaturer   ,   s&    WU3=+>!>!T6WCTU    c                       e Zd ZdZdZdZdZedej	        j
        dej	        j
        dd fd            Zed	ej        j        dd fd
            ZdS )NodeKindzRdatasets in nodesr         r   r   returnc                     t          t          ||          rt          j        S t          t          ||          rt          j        S t          j        S r   )r   _cname_typesr   CNAME_neutral_typesNEUTRALREGULAR)clsr   r   s      r   classifyzNodeKind.classify8   sF     *,GG 	$>!+NFFKK 	$####r   rdatasetc                 B    |                      |j        |j                  S r   )r   r   r   )r   r   s     r   classify_rdatasetzNodeKind.classify_rdatasetC   s    ||HOX_===r   N)__name__
__module____qualname____doc__r   r   r   classmethodr   r	   	RdataTyper   r   Rdatasetr     r   r   r   r   0   s        GGE$],$69m6M$	$ $ $ [$ >)> >: > > > [> > >r   r   c                   :   e Zd ZdZdgZd Zdej        j        de	e
ef         de
fdZd Zd	 Zd
 Zd Zd Z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
dZej        j        dfdej        j        dej        j        dej        j        dedeej        j                 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!defdZ"dS )Nodea  A Node is a set of rdatasets.

    A node is either a CNAME node or an "other data" node.  A CNAME
    node contains only CNAME, KEY, NSEC, and NSEC3 rdatasets along with their
    covering RRSIG rdatasets.  An "other data" node contains any
    rdataset other than a CNAME or RRSIG(CNAME) rdataset.  When
    changes are made to a node, the CNAME or "other data" state is
    always consistent with the update, i.e. the most recent change
    wins.  For example, if you have a node which contains a CNAME
    rdataset, and then add an MX rdataset to it, then the CNAME
    rdataset will be deleted.  Likewise if you have a node containing
    an MX rdataset and add a CNAME rdataset, the MX rdataset will be
    deleted.
    	rdatasetsc                     g | _         d S r   r+   selfs    r   __init__zNode.__init__Z   s    r   namekwr   c                    t          j                    }| j        D ]K}t          |          dk    r6|                     |j        |fi |           |                    d           L|                                dd         S )a"  Convert a node to text format.

        Each rdataset at the node is printed.  Any keyword arguments
        to this method are passed on to the rdataset's to_text() method.

        *name*, a ``dns.name.Name``, the owner name of the
        rdatasets.

        Returns a ``str``.

        r   
N)ioStringIOr+   lenwriteto_textgetvalue)r/   r1   r2   srdss        r   r:   zNode.to_text^   s|     KMM> 	 	C3xx!||D//B//000zz||CRC  r   c                 F    dt          t          |                     z   dz   S )Nz
<DNS node >)stridr.   s    r   __repr__zNode.__repr__r   s    c"T((mm+c11r   c                 ^    | j         D ]}||j         vr dS |j         D ]}|| j         vr dS dS )NFTr-   )r/   otherrds      r   __eq__zNode.__eq__u   s]     . 	 	B((uu )/ 	 	B''uu (tr   c                 .    |                      |           S r   )rF   )r/   rD   s     r   __ne__zNode.__ne__   s    ;;u%%%%r   c                 *    t          | j                  S r   )r8   r+   r.   s    r   __len__zNode.__len__   s    4>"""r   c                 *    t          | j                  S r   )iterr+   r.   s    r   __iter__zNode.__iter__   s    DN###r   c                 8   t          | j                  dk    rgt                              |          }|t          j        k    rd | j        D             | _        n&|t          j        k    rd | j        D             | _        | j                            |           dS )a  Append rdataset to the node with special handling for CNAME and
        other data conditions.

        Specifically, if the rdataset being appended has ``NodeKind.CNAME``,
        then all rdatasets other than KEY, NSEC, NSEC3, and their covering
        RRSIGs are deleted.  If the rdataset being appended has
        ``NodeKind.REGULAR`` then CNAME and RRSIG(CNAME) are deleted.
        r   c                 b    g | ],}t                               |          t           j        k    *|-S r(   )r   r    r   .0r=   s     r   
<listcomp>z)Node._append_rdataset.<locals>.<listcomp>   s>     " " "11#66(:JJJ JJJr   c                 b    g | ],}t                               |          t           j        k    *|-S r(   )r   r    r   rP   s     r   rR   z)Node._append_rdataset.<locals>.<listcomp>   s=     " " "11#66(.HH HHHr   N)r8   r+   r   r    r   r   appendr/   r   kinds      r   _append_rdatasetzNode._append_rdataset   s     t~""--h77Dx~%%" "#~" " "
 )))" "#~" " " 	h'''''r   Frdclassr   r   createc                     | j         D ]}|                    |||          r|c S |st          t          j                            |||          }|                     |           |S )a*  Find an rdataset matching the specified properties in the
        current node.

        *rdclass*, a ``dns.rdataclass.RdataClass``, the class of the rdataset.

        *rdtype*, a ``dns.rdatatype.RdataType``, the type of the rdataset.

        *covers*, a ``dns.rdatatype.RdataType``, the covered type.
        Usually this value is ``dns.rdatatype.NONE``, but if the
        rdtype is ``dns.rdatatype.SIG`` or ``dns.rdatatype.RRSIG``,
        then the covers value will be the rdata type the SIG/RRSIG
        covers.  The library treats the SIG and RRSIG types as if they
        were a family of types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA).
        This makes RRSIGs much easier to work with than if RRSIGs
        covering different rdata types were aggregated into a single
        RRSIG rdataset.

        *create*, a ``bool``.  If True, create the rdataset if it is not found.

        Raises ``KeyError`` if an rdataset of the desired type and class does
        not exist and *create* is not ``True``.

        Returns a ``dns.rdataset.Rdataset``.
        )r+   matchKeyErrorr   r   r'   rW   r/   rX   r   r   rY   r=   s         r   find_rdatasetzNode.find_rdataset   s{    @ > 	 	Cyy&&11 


 	Nl##GVV<<c"""
r   c                 ^    	 |                      ||||          }n# t          $ r d}Y nw xY w|S )a  Get an rdataset matching the specified properties in the
        current node.

        None is returned if an rdataset of the specified type and
        class does not exist and *create* is not ``True``.

        *rdclass*, an ``int``, the class of the rdataset.

        *rdtype*, an ``int``, the type of the rdataset.

        *covers*, an ``int``, the covered type.  Usually this value is
        dns.rdatatype.NONE, but if the rdtype is dns.rdatatype.SIG or
        dns.rdatatype.RRSIG, then the covers value will be the rdata
        type the SIG/RRSIG covers.  The library treats the SIG and RRSIG
        types as if they were a family of
        types, e.g. RRSIG(A), RRSIG(NS), RRSIG(SOA).  This makes RRSIGs much
        easier to work with than if RRSIGs covering different rdata
        types were aggregated into a single RRSIG rdataset.

        *create*, a ``bool``.  If True, create the rdataset if it is not found.

        Returns a ``dns.rdataset.Rdataset`` or ``None``.
        N)r^   r\   r]   s         r   get_rdatasetzNode.get_rdataset   sK    >	$$WfffEECC 	 	 	CCC	
s    **Nc                 p    |                      |||          }|| j                            |           dS dS )aD  Delete the rdataset matching the specified properties in the
        current node.

        If a matching rdataset does not exist, it is not an error.

        *rdclass*, an ``int``, the class of the rdataset.

        *rdtype*, an ``int``, the type of the rdataset.

        *covers*, an ``int``, the covered type.
        N)r`   r+   remove)r/   rX   r   r   r=   s        r   delete_rdatasetzNode.delete_rdataset   sC    $ 88?N!!#&&&&& ?r   replacementc                 >   t          |t          j        j                  st	          d          t          |t          j        j                  r|                                }|                     |j	        |j
        |j                   |                     |           dS )a  Replace an rdataset.

        It is not an error if there is no rdataset matching *replacement*.

        Ownership of the *replacement* object is transferred to the node;
        in other words, this method does not store a copy of *replacement*
        at the node, it stores *replacement* itself.

        *replacement*, a ``dns.rdataset.Rdataset``.

        Raises ``ValueError`` if *replacement* is not a
        ``dns.rdataset.Rdataset``.
        zreplacement is not an rdatasetN)
isinstancer   r   r'   
ValueErrorrrsetRRsetto_rdatasetrc   rX   r   r   rW   r/   rd   s     r   replace_rdatasetzNode.replace_rdataset
  s     +s|'<== 	?=>>>k39?33 	4 &1133K!3[5G	
 	
 	
 	k*****r   c                     | j         D ];}t                              |j        |j                  }|t          j        k    r|c S <t          j        S )aT  Classify a node.

        A node which contains a CNAME or RRSIG(CNAME) is a
        ``NodeKind.CNAME`` node.

        A node which contains only "neutral" types, i.e. types allowed to
        co-exist with a CNAME, is a ``NodeKind.NEUTRAL`` node.  The neutral
        types are NSEC, NSEC3, KEY, and their associated RRSIGS.  An empty node
        is also considered neutral.

        A node which contains some rdataset which is not a CNAME, RRSIG(CNAME),
        or a neutral type is a a ``NodeKind.REGULAR`` node.  Regular nodes are
        also commonly referred to as "other data".
        )r+   r   r   r   r   r   rU   s      r   r   zNode.classify$  sS      	 	H$$X_hoFFDx''' (r   c                     dS )NFr(   r.   s    r   is_immutablezNode.is_immutable9  s    ur   )#r!   r"   r#   r$   	__slots__r0   r   r1   Namer   r@   r   r:   rB   rF   rH   rJ   rM   rW   r	   NONE
rdataclass
RdataClassr&   boolr   r'   r^   r   r`   rc   rl   r   r   ro   r(   r   r   r*   r*   H   sV         I  !CHM !c3h !C ! ! ! !(2 2 2
 
 
& & &# # #$ $ $( ( (@ +.-*<' '*' '' '	'
 ' 
	' ' ' 'Z +.-*<# #*# '# '	#
 # 
#,'	(# # # #R +.-*<	' '*' '' '	'
 
' ' ' ',+CL,A +d + + + +4 (        *d      r   r*   c                       e Zd Z 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ej        j                 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 )ImmutableNodec                     t                                                       t          d |j        D                       | _        d S )Nc                 L    g | ]!}t           j                            |          "S r(   )r   r   ImmutableRdatasetrP   s     r   rR   z*ImmutableNode.__init__.<locals>.<listcomp>B  s(    KKKSS\++C00KKKr   )superr0   tupler+   )r/   node	__class__s     r   r0   zImmutableNode.__init__?  sA    KKDNKKK
 
r   FrX   r   r   rY   r   c                 n    |rt          d          t                                          |||d          S N	immutableF)	TypeErrorr{   r^   r/   rX   r   r   rY   r~   s        r   r^   zImmutableNode.find_rdatasetE  s9      	)K(((ww$$WffeDDDr   c                 n    |rt          d          t                                          |||d          S r   )r   r{   r`   r   s        r   r`   zImmutableNode.get_rdatasetP  s9      	)K(((ww##GVVUCCCr   Nc                      t          d          Nr   r   )r/   rX   r   r   s       r   rc   zImmutableNode.delete_rdataset[  s     $$$r   rd   c                      t          d          r   r   rk   s     r   rl   zImmutableNode.replace_rdatasetc  s    $$$r   c                     dS )NTr(   r.   s    r   ro   zImmutableNode.is_immutablef  s    tr   )r!   r"   r#   r0   r   r	   rr   rs   rt   r&   ru   r   r'   r^   r   r`   rc   rl   ro   __classcell__)r~   s   @r   rw   rw   =  s       
 
 
 
 
 +.-*<	E 	E*	E '	E '		E
 	E 
		E 	E 	E 	E 	E 	E +.-*<	D 	D*	D '	D '		D
 	D 
#,'	(	D 	D 	D 	D 	D 	D +.-*<	% %*% '% '	%
 
% % % %%CL,A %d % % % %d        r   rw   )r$   enumr6   typingr   r   r   dns.immutabler   dns.namedns.rdataclassdns.rdatasetdns.rdatatypedns.renderer	dns.rrsetr	   r   r   NSECNSEC3KEYr   r   uniqueEnumr   r*   r   rw   r(   r   r   <module>r      s  $ 0 /  				 & & & & & & & & & &                          M MMMV V V > > > > >ty > > >.r r r r r r r rj ) ) ) ) )D ) ) ) ) )r   