3
[_ð]Ð  ã               @   s<   d Z ddlmZ ddlZddlZddlZG dd„ deƒZdS )z)DNS nodes.  A node is a set of rdatasets.é    )ÚStringIONc               @   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   ú-/tmp/pip-build-yz_zf6az/dnspython/dns/node.pyÚ__init__!   s    zNode.__init__c             K   sP   t ƒ }x8| jD ].}t|ƒdkr|j|j|f|Žƒ |jdƒ qW |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`` or ``text``, the owner name of the rdatasets.

        Returns a ``text``.
        r   Ú
Né   éÿÿÿÿ)r   r   Ú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Úid)r   r   r   r   Ú__repr__7   s    zNode.__repr__c             C   s@   x| j D ]}||j krdS qW x|j D ]}|| j kr&dS q&W dS )NFT)r   )r   ÚotherÚrdr   r   r   Ú__eq__:   s    

zNode.__eq__c             C   s   | j |ƒ S )N)r   )r   r   r   r   r   Ú__ne__F   s    zNode.__ne__c             C   s
   t | jƒS )N)r   r   )r   r   r   r   Ú__len__I   s    zNode.__len__c             C   s
   t | jƒS )N)Úiterr   )r   r   r   r   Ú__iter__L   s    zNode.__iter__Fc             C   sH   x | j D ]}|j|||ƒr|S qW |s*t‚tjj||ƒ}| 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``, 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_rdatasetO   s    zNode.find_rdatasetc             C   s2   y| j ||||ƒ}W n tk
r,   d}Y nX |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'   r(   r   r   r   r   Úget_rdatasetr   s
    
zNode.get_rdatasetc             C   s&   | j |||ƒ}|dk	r"| j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ƒ | 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   Úreplacementr   r   r   Úreplace_rdataset£   s
    zNode.replace_rdatasetN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r   r   r   r   r!   Z	rdatatypeÚNONEr)   r*   r,   r0   r   r   r   r   r      s   "r   )	r4   Úior   Zdns.rdatasetr!   Zdns.rdatatypeZdns.rendererÚobjectr   r   r   r   r   Ú<module>   s
   