o
    ‰ÖhS1  ã                   @   s¾   d Z ddlZddlZddl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ejjhZejjejjejjhZdd„ ZejG dd„ dejƒƒZG dd	„ d	ƒZejjG d
d„ deƒƒZdS )z)DNS nodes.  A node is a set of rdatasets.é    N)ÚAnyÚDictc                 C   s   || v p|t jjko|| v S ©N)ÚdnsÚ	rdatatypeÚRRSIG)ÚrdtypesÚrdtypeÚcovers© r   úJ/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/dns/node.pyÚ_matches_type_or_its_signature+   s   r   c                   @   sX   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d	„ƒZed
ejjdd fdd„ƒZdS )ÚNodeKindzRdatasets in nodesr   é   é   r	   r
   Úreturnc                 C   s*   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
   r   r   r   Úclassify7   s
   zNodeKind.classifyÚrdatasetc                 C   s   |   |j|j¡S r   )r   r	   r
   )r   r   r   r   r   Úclassify_rdatasetB   s   zNodeKind.classify_rdatasetN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úclassmethodr   r   Ú	RdataTyper   r   ÚRdatasetr   r   r   r   r   r   /   s    ÿÿþ
r   c                   @   sD  e Zd ZdZdgZdd„ Zdejjde	e
ef de
fdd	„Zd
d„ Zdd„ Zdd„ Zdd„ Zdd„ Z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
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
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 defd'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                 C   s
   g | _ d S r   ©r#   ©Úselfr   r   r   Ú__init__Y   s   
zNode.__init__ÚnameÚkwr   c                 K   sR   t  ¡ }| jD ]}t|ƒdkr | |j|fi |¤Ž¡ | d¡ q| ¡ 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&   r(   r)   ÚsÚrdsr   r   r   r0   ]   s   

€zNode.to_textc                 C   s   dt t| ƒƒ d S )Nz
<DNS node ú>)ÚstrÚidr%   r   r   r   Ú__repr__q   s   zNode.__repr__c                 C   s<   | j D ]
}||j vr dS q|j D ]
}|| j vr dS qdS )NFTr$   )r&   ÚotherÚrdr   r   r   Ú__eq__t   s   

ÿ

ÿzNode.__eq__c                 C   s   |   |¡ S r   )r:   )r&   r8   r   r   r   Ú__ne__€   s   zNode.__ne__c                 C   ó
   t | jƒS r   )r.   r#   r%   r   r   r   Ú__len__ƒ   ó   
zNode.__len__c                 C   r<   r   )Úiterr#   r%   r   r   r   Ú__iter__†   r>   zNode.__iter__c                 C   sb   t | jƒdkr)t |¡}|tjkrdd„ | jD ƒ| _n|tjkr)d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                 S   ó    g | ]}t  |¡t jkr|‘qS r   )r   r   r   ©Ú.0r3   r   r   r   Ú
<listcomp>–   ó
    þz)Node._append_rdataset.<locals>.<listcomp>c                 S   rA   r   )r   r   r   rB   r   r   r   rD   œ   rE   N)r.   r#   r   r   r   r   Úappend©r&   r   Úkindr   r   r   Ú_append_rdataset‰   s   



þ
þzNode._append_rdatasetFÚrdclassr	   r
   Úcreatec                 C   sH   | j D ]}| |||¡r|  S q|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!   rI   ©r&   rJ   r	   r
   rK   r3   r   r   r   Úfind_rdataset¥   s   
 ÿ
zNode.find_rdatasetNc                 C   s0   z|   ||||¡}W |S  ty   d}Y |S 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)rO   rM   rN   r   r   r   Úget_rdatasetÎ   s   þþzNode.get_rdatasetc                 C   s*   |   |||¡}|dur| 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)rP   r#   Úremove)r&   rJ   r	   r
   r3   r   r   r   Údelete_rdatasetó   s   ÿzNode.delete_rdatasetÚreplacementc                 C   sN   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_rdatasetrR   rJ   r	   r
   rI   ©r&   rS   r   r   r   Úreplace_rdataset	  s   ÿzNode.replace_rdatasetc                 C   s4   | j D ]}t |j|j¡}|tjkr|  S q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   rG   r   r   r   r   #  s   

ÿzNode.classifyc                 C   ó   dS )NFr   r%   r   r   r   Úis_immutable8  ó   zNode.is_immutable)"r   r   r   r   Ú	__slots__r'   r   r(   ÚNamer   r5   r   r0   r7   r:   r;   r=   r@   rI   r   ÚNONEÚ
rdataclassÚ
RdataClassr    Úboolr   r!   rO   rP   rR   rZ   r   r   r\   r   r   r   r   r"   G   sd    " ûþýüû
ú-ûþýüû

ú)üþýü
ûr"   c                       sê   e Zd Z‡ 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 )ÚImmutableNodec                    s$   t ƒ  ¡  tdd„ |jD ƒƒ| _d S )Nc                 S   s   g | ]}t j |¡‘qS r   )r   r   ÚImmutableRdatasetrB   r   r   r   rD   A  s    z*ImmutableNode.__init__.<locals>.<listcomp>)Úsuperr'   Útupler#   )r&   Únode©Ú	__class__r   r   r'   >  s   

ÿzImmutableNode.__init__FrJ   r	   r
   rK   r   c                    ó   |rt dƒ‚tƒ  |||d¡S ©NÚ	immutableF)Ú	TypeErrorrf   rO   ©r&   rJ   r	   r
   rK   ri   r   r   rO   D  ó   zImmutableNode.find_rdatasetNc                    rk   rl   )rn   rf   rP   ro   ri   r   r   rP   O  rp   zImmutableNode.get_rdatasetc                 C   ó   t dƒ‚©Nrm   ©rn   )r&   rJ   r	   r
   r   r   r   rR   Z  s   zImmutableNode.delete_rdatasetrS   c                 C   rq   rr   rs   rY   r   r   r   rZ   b  s   zImmutableNode.replace_rdatasetc                 C   r[   )NTr   r%   r   r   r   r\   e  r]   zImmutableNode.is_immutable)r   r   r   r'   r   r   r`   ra   rb   r    rc   r   r!   rO   rP   rR   rZ   r\   Ú__classcell__r   r   ri   r   rd   <  sP    
ûþýüûúûþýüû
úüþýü
ûrd   )r   Úenumr,   Útypingr   r   Údns.immutabler   Údns.nameÚdns.rdataclassÚdns.rdatasetÚdns.rdatatypeÚ	dns.rrsetr   r   r   ÚNSECÚNSEC3ÚKEYr   r   ÚuniqueÚEnumr   r"   rm   rd   r   r   r   r   Ú<module>   s.   ÿý v