o
    2³c°  ã                   @   s6   d Z ddlZddlZddlZddlZG dd„ dƒZdS )z)DNS nodes.  A node is a set of rdatasets.é    Nc                   @   sŠ   e Zd ZdZdgZ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d„Zejjdfdd„Zejjfdd„Zdd„ ZdS )ÚNodezA Node is a set of rdatasets.Ú	rdatasetsc                 C   s
   g | _ d S ©N©r   ©Úself© r   ú>/var/www/html/gps/gps/lib/python3.10/site-packages/dns/node.pyÚ__init__!   s   
zNode.__init__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`` or ``str``, the owner name of the
        rdatasets.

        Returns a ``str``.

        r   Ú
Néÿÿÿÿ)ÚioÚStringIOr   ÚlenÚwriteÚto_textÚgetvalue)r   ÚnameÚkwÚsÚrdsr   r   r	   r   %   s   

€zNode.to_textc                 C   s   dt t| ƒƒ d S )Nz
<DNS node ú>)ÚstrÚidr   r   r   r	   Ú__repr__9   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__<   s   

ÿ

ÿzNode.__eq__c                 C   s   |   |¡ S r   )r   )r   r   r   r   r	   Ú__ne__H   s   zNode.__ne__c                 C   ó
   t | jƒS r   )r   r   r   r   r   r	   Ú__len__K   ó   
zNode.__len__c                 C   r   r   )Úiterr   r   r   r   r	   Ú__iter__N   r!   zNode.__iter__Fc                 C   sH   | j D ]}| |||¡r|  S q|st‚tj ||¡}| j  |¡ |S )aû  Find an rdataset matching the specified properties in the
        current node.

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

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

        *covers*, an ``int`` or ``None``, 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ÚKeyErrorÚdnsÚrdatasetÚRdatasetÚappend©r   ÚrdclassÚrdtypeÚcoversÚcreater   r   r   r	   Úfind_rdatasetQ   s   
ÿzNode.find_rdatasetc                 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)r/   r%   r*   r   r   r	   Úget_rdatasetu   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)r0   r   Úremove)r   r+   r,   r-   r   r   r   r	   Údelete_rdataset•   s   ÿzNode.delete_rdatasetc                 C   sP   t |tjjƒstdƒ‚t |tjjƒr| ¡ }|  |j	|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_rdatasetr2   r+   r,   r-   r   r)   )r   Úreplacementr   r   r	   Úreplace_rdataset¦   s   ÿzNode.replace_rdatasetN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r
   r   r   r   r   r    r#   r&   Ú	rdatatypeÚNONEr/   r0   r2   r9   r   r   r   r	   r      s$    
ÿ$
ÿ r   )r=   r   Údns.rdatasetr&   Údns.rdatatypeÚdns.rendererr   r   r   r   r	   Ú<module>   s   