
    ,hw1                        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j0                               Z G d d      Zej6                  j6                   G d	 d
e             Zy)z)DNS nodes.  A node is a set of rdatasets.    N)AnyDictOptionalc                 T    || v xs# |t         j                  j                  k(  xr || v S N)dns	rdatatypeRRSIG)rdtypesrdtypecoverss      J/var/www/html/Resume-Scraper/venv/lib/python3.12/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y)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   s>     *,G>>!+NFFK######r   rdatasetc                 N    | j                  |j                  |j                        S r   )r   r   r   )r   r   s     r   classify_rdatasetzNodeKind.classify_rdatasetC   s    ||HOOX__==r   N)__name__
__module____qualname____doc__r   r   r   classmethodr   r	   	RdataTyper   r   Rdatasetr     r   r   r   r   0   s~    GGE$]],,$69mm6M6M$	$ $ >)>)> >: > >r   r   c                   l   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j2                  j4                  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j2                  j4                     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j2                  j4                  ddfdZde fdZ!defdZ"y)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 | _         y r   r+   selfs    r   __init__zNode.__init__Z   s	    r   namekwr   c                     t        j                         }| j                  D ]D  }t        |      dkD  s|j	                   |j
                  |fi |       |j	                  d       F |j                         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^   si     KKM>> 	C3x!|D/B/0	 zz|CR  r   c                 6    dt        t        |             z   dz   S )Nz
<DNS node >)stridr.   s    r   __repr__zNode.__repr__r   s    c"T(m+c11r   c                     | j                   D ]  }||j                   vs y |j                   D ]  }|| j                   vs y y)NFTr-   )r/   otherrds      r   __eq__zNode.__eq__u   sO     .. 	B(	 // 	B'	 r   c                 &    | j                  |       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    DNN##r   c                 
   t        | j                        dkD  rt        j                  |      }|t        j                  k(  rF| j                  D cg c]*  }t        j                  |      t        j
                  k7  r|, c}| _        nX|t        j
                  k(  rE| j                  D cg c]*  }t        j                  |      t        j                  k7  r|, c}| _        | j                  j                  |       yc c}w c c}w )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   N)r8   r+   r   r    r   r   append)r/   r   kindr=   s       r   _append_rdatasetzNode._append_rdataset   s     t~~"--h7Dx~~%  $~~"11#6(:J:JJ "
 )))  $~~"11#6(..H " 	h'""s   /C;(/D Frdclassr   r   createc                     | j                   D ]  }|j                  |||      s|c S  |st        t        j                  j                  |||      }| 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'   rQ   r/   rR   r   r   rS   r=   s         r   find_rdatasetzNode.find_rdataset   sb    @ >> 	Cyy&&1
	 Nll##GVV<c"
r   c                 T    	 | j                  ||||      }|S # t        $ r d}Y |S w xY w)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)rX   rV   rW   s         r   get_rdatasetzNode.get_rdataset   s?    >	$$WfffEC 
  	C
	s    ''Nc                 f    | j                  |||      }|| j                  j                  |       yy)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)rZ   r+   remove)r/   rR   r   r   r=   s        r   delete_rdatasetzNode.delete_rdataset   s4    $ 8?NN!!#& r   replacementc                 N   t        |t        j                  j                        st	        d      t        |t        j
                  j                        r|j                         }| j                  |j                  |j                  |j                         | j                  |       y)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_rdatasetr]   rR   r   r   rQ   r/   r^   s     r   replace_rdatasetzNode.replace_rdataset
  s}     +s||'<'<==>>k399??3 &113K!3!3[5G5G	
 	k*r   c                     | j                   D ]C  }t        j                  |j                  |j                        }|t        j
                  k7  sA|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   )r/   r   rP   s      r   r   zNode.classify$  sR      	H$$X__hooFDx'''	 r   c                      y)NFr(   r.   s    r   is_immutablezNode.is_immutable9  s    r   )#r!   r"   r#   r$   	__slots__r0   r   r1   Namer   r@   r   r:   rB   rF   rH   rJ   rM   rQ   r	   NONE
rdataclass
RdataClassr&   boolr   r'   rX   r   rZ   r]   rf   r   r   ri   r(   r   r   r*   r*   H   s    I!CHHMM !c3h !C !(2
&#$(@ +.--*<*<'**' ''' ''	'
 ' 
		'Z +.--*<*<#**# ''# ''	#
 # 
#,,''	(#R +.--*<*<	'**' ''' ''	'
 
',+CLL,A,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        |j                  D cg c]!  }t        j
                  j                  |      # c}      | _        y c c}w r   )superr0   tupler+   r   r   ImmutableRdataset)r/   noder=   	__class__s      r   r0   zImmutableNode.__init__?  s>    <@NNKSS\\++C0K
Ks   &AFrR   r   r   rS   r   c                 B    |rt        d      t        | 	  |||d      S N	immutableF)	TypeErrorrs   rX   r/   rR   r   r   rS   rw   s        r   rX   zImmutableNode.find_rdatasetE  s)     K((w$WffeDDr   c                 B    |rt        d      t        | 	  |||d      S ry   )r{   rs   rZ   r|   s        r   rZ   zImmutableNode.get_rdatasetP  s)     K((w#GVVUCCr   Nc                     t        d      Nrz   r{   )r/   rR   r   r   s       r   r]   zImmutableNode.delete_rdataset[  s     $$r   r^   c                     t        d      r   r   re   s     r   rf   zImmutableNode.replace_rdatasetc  s    $$r   c                      y)NTr(   r.   s    r   ri   zImmutableNode.is_immutablef  s    r   )r!   r"   r#   r0   r   r	   rl   rm   rn   r&   ro   r   r'   rX   r   rZ   r]   rf   ri   __classcell__)rw   s   @r   rq   rq   =  sx   
 +.--*<*<	E**	E ''	E ''		E
 	E 
			E +.--*<*<	D**	D ''	D ''		D
 	D 
#,,''	(	D +.--*<*<	%**% ''% ''	%
 
%%CLL,A,A %d %d r   rq   )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*   rz   rq   r(   r   r   <module>r      s   $ 0  	 & &        MM MMMMMMV >tyy > >.r rj )D ) )r   