a
    sd_á  ã                   @   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   ú*/usr/lib/python3/dist-packages/dns/node.pyÚ__init__!   s    zNode.__init__c                 K   sR   t  ¡ }| jD ]2}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   ÚotherZ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   s
   t | jƒS r   )r   r   r   r   r   r	   Ú__len__K   s    zNode.__len__c                 C   s
   t | jƒS r   )Úiterr   r   r   r   r	   Ú__iter__N   s    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ÚcoversZcreater   r   r   r	   Úfind_rdatasetQ   s    

zNode.find_rdatasetc                 C   s0   z|   ||||¡}W n ty*   d}Y n0 |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'   r   r   r	   Úget_rdatasetu   s
    
zNode.get_rdatasetc                 C   s&   |   |||¡}|dur"| j |¡ 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   r(   r)   r*   r   r   r   r	   Údelete_rdataset•   s    zNode.delete_rdatasetc                 C   s:   t |tjjƒstdƒ‚|  |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%   Ú
ValueErrorr.   r(   r)   r*   r   r&   )r   Zreplacementr   r   r	   Úreplace_rdataset¦   s    ÿzNode.replace_rdatasetN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r
   r   r   r   r   r   r    r#   Z	rdatatypeZNONEr+   r,   r.   r1   r   r   r   r	   r      s"   ÿ
$ÿ
 r   )r5   r   Zdns.rdatasetr#   Zdns.rdatatypeZdns.rendererr   r   r   r   r	   Ú<module>   s
   