???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................3
¢báW¨  ã               @   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 DNS node.

    A node is a set of rdatasets

    @ivar rdatasets: the node's rdatasets
    @type rdatasets: list of dns.rdataset.Rdataset objectsÚ	rdatasetsc             C   s
   g | _ dS )zInitialize a DNS node.
        N)r   )Úself© r   ú/usr/lib/python3.6/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.
        @param name: the owner name of the rdatasets
        @type name: dns.name.Name object
        @rtype: string
        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__;   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 )zSTwo nodes are equal if they have the same rdatasets.

        @rtype: bool
        FT)r   )r   ÚotherZrdr   r   r   Ú__eq__>   s    

zNode.__eq__c             C   s   | j |ƒ S )N)r   )r   r   r   r   r   Ú__ne__N   s    zNode.__ne__c             C   s
   t | jƒS )N)r   r   )r   r   r   r   Ú__len__Q   s    zNode.__len__c             C   s
   t | jƒS )N)Úiterr   )r   r   r   r   Ú__iter__T   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.

        @param rdclass: The class of the rdataset
        @type rdclass: int
        @param rdtype: The type of the rdataset
        @type rdtype: int
        @param covers: 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.
        @type covers: int
        @param create: If True, create the rdataset if it is not found.
        @type create: bool
        @raises KeyError: An rdataset of the desired type and class does
        not exist and I{create} is not True.
        @rtype: dns.rdataset.Rdataset object
        )r   ÚmatchÚKeyErrorÚdnsÚrdatasetÚRdatasetÚappend)r   ÚrdclassÚrdtypeÚcoversÚcreater   r   r   r   Úfind_rdatasetW   s    zNode.find_rdatasetc             C   s2   y| j ||||ƒ}W n tk
r,   d}Y nX |S )aE  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 I{create} is not True.

        @param rdclass: The class of the rdataset
        @type rdclass: int
        @param rdtype: The type of the rdataset
        @type rdtype: int
        @param covers: The covered type.
        @type covers: int
        @param create: If True, create the rdataset if it is not found.
        @type create: bool
        @rtype: dns.rdataset.Rdataset object or None
        N)r(   r   )r   r$   r%   r&   r'   r   r   r   r   Úget_rdatasety   s
    
zNode.get_rdatasetc             C   s&   | j |||ƒ}|dk	r"| jj|ƒ dS )az  Delete the rdataset matching the specified properties in the
        current node.

        If a matching rdataset does not exist, it is not an error.

        @param rdclass: The class of the rdataset
        @type rdclass: int
        @param rdtype: The type of the rdataset
        @type rdtype: int
        @param covers: The covered type.
        @type covers: int
        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 )a8  Replace an rdataset.

        It is not an error if there is no rdataset matching I{replacement}.

        Ownership of the I{replacement} object is transferred to the node;
        in other words, this method does not store a copy of I{replacement}
        at the node, it stores I{replacement} itself.
        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+   r.   r   r   r   r   r      s   !r   )	r2   Úior   Zdns.rdatasetr    Zdns.rdatatypeZdns.rendererÚobjectr   r   r   r   r   Ú<module>   s
   