
                         B    d Z ddlmZ ddlZddlZddlZ G d de      Zy)z)DNS nodes.  A node is a set of rdatasets.    )StringIONc                       e Zd ZdZdgZd Zd Zd Zd Zd Z	d Z
d	 Zej                  j                  d
fdZej                  j                  d
fdZej                  j                  fdZd Zy)NodezA Node is a set of rdatasets.	rdatasetsc                     g | _         y Nr   selfs    lib/third_party/dns/node.py__init__zNode.__init__!   s	        c                     t               }| j                  D ]D  }t        |      dkD  s|j                   |j                  |fi |       |j                  d       F |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rdss        r   r   zNode.to_text%   s`     J>>C3x!|D/B/0 " zz|CR  r   c                 6    dt        t        |             z   dz   S )Nz
<DNS node >)stridr
   s    r   __repr__zNode.__repr__7   s    c"T(m+c11r   c                     | j                   D ]  }||j                   vs y |j                   D ]  }|| j                   vs y y)NFTr	   )r   otherrds      r   __eq__zNode.__eq__:   sE     ..B( ! //B' " r   c                 &    | j                  |       S r   )r"   )r   r    s     r   __ne__zNode.__ne__F   s    ;;u%%%r   c                 ,    t        | j                        S r   )r   r   r
   s    r   __len__zNode.__len__I   s    4>>""r   c                 ,    t        | j                        S r   )iterr   r
   s    r   __iter__zNode.__iter__L   s    DNN##r   Fc                     | j                   D ]  }|j                  |||      s|c S  |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   s         r   find_rdatasetzNode.find_rdatasetO   s^    4 >>Cyy&&1
 " Nll##GV4c"
r   c                 T    	 | j                  ||||      }|S # t        $ r d}Y |S w xY 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)r6   r,   r1   s         r   get_rdatasetzNode.get_rdatasetr   s?    4	$$WfffEC 
  	C
	s    ''c                 f    | j                  |||      }|| j                  j                  |       yy)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)r8   r   remove)r   r2   r3   r4   r   s        r   delete_rdatasetzNode.delete_rdataset   s4     8?NN!!#& r   c                     t        |t        j                  j                        st	        d      | j                  |j                  |j                  |j                         | j                  j                  |       y)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;   r2   r3   r4   r   r0   )r   replacements     r   replace_rdatasetzNode.replace_rdataset   s]     +s||'<'<==>>[00+2D2D(//	1k*r   N)__name__
__module____qualname____doc__	__slots__r   r   r   r"   r$   r&   r)   r-   	rdatatypeNONEr6   r8   r;   r@    r   r   r   r      sx    'I!$2
&#$ 58MM4F4F"!F 47==3E3E!@ 7:mm6H6H '"+r   r   )	rD   ior   dns.rdatasetr-   dns.rdatatypedns.rendererobjectr   rH   r   r   <module>rN      s$   $ 0    [+6 [+r   