
                             d Z ddlZddlZddlZddlZddlmZ  G d dej                  j                        Z
	 ddZd Zdd	Zd
 Zy)z)DNS RRsets (an RRset is a named rdataset)    N   )string_typesc                        e Zd ZdZddgZej                  j                  df fd	Z fdZ	d Z
d Z fd	Zd fd
	Zd fd	Zd fd	Zd Z xZS )RRseta6  A DNS RRset (named rdataset).

    RRset inherits from Rdataset, and RRsets can be treated as
    Rdatasets in most cases.  There are, however, a few notable
    exceptions.  RRsets have different to_wire() and to_text() method
    arguments, reflecting the fact that RRsets always have an owner
    name.
    namedeletingNc                 L    t         t        |   |||       || _        || _        y)zCreate a new RRset.N)superr   __init__r   r   selfr   rdclassrdtypecoversr   	__class__s         lib/third_party/dns/rrset.pyr   zRRset.__init__)   s&     	eT#GVV<	     c                 p    t         t        |          }| j                  |_        | j                  |_        |S N)r
   r   _cloner   r   )r   objr   s     r   r   zRRset._clone1   s-    E4')99}}
r   c                    | j                   dk(  rd}n/dt        j                  j                  | j                         z   dz   }| j                  -dt        j
                  j                  | j                        z   }nd}dt        | j                        z   dz   t        j
                  j                  | j                        z   dz   t        j                  j                  | j                        z   |z   |z   dz   S )	Nr    ()z delete=z<DNS  z RRset>)
r   dns	rdatatypeto_textr   
rdataclassstrr   r   r   )r   ctextdtexts      r   __repr__zRRset.__repr__7   s    ;;!E#--//<<sBE==$!7!7!FFEETYY'#-~~%%dll3469:}}$$T[[1249:<ABDMN 	Nr   c                 "    | j                         S r   )r   r   s    r   __str__zRRset.__str__D   s    ||~r   c                     t        |t              sy| j                  |j                  k7  ryt        t        |   |      S )NF)
isinstancer   r   r
   __eq__)r   otherr   s     r   r*   zRRset.__eq__G   s5    %'99

"UD(//r   c                 p    t         t        |   |||      sy| j                  |k7  s| j                  |k7  ryy)znReturns ``True`` if this rrset matches the specified class, type,
        covers, and deletion state.
        FT)r
   r   matchr   r   r   s         r   r-   zRRset.matchN   s8    
 UD'@99 9r   c                 Z    t        t        | 
  | j                  ||| j                  fi |S )a  Convert the RRset into DNS master file format.

        See ``dns.name.Name.choose_relativity`` for more information
        on how *origin* and *relativize* determine the way names
        are emitted.

        Any additional keyword arguments are passed on to the rdata
        ``to_text()`` method.

        *origin*, a ``dns.name.Name`` or ``None``, the origin for relative
        names.

        *relativize*, a ``bool``.  If ``True``, names will be relativized
        to *origin*.
        )r
   r   r   r   r   )r   origin
relativizekwr   s       r   r   zRRset.to_textY   s2    " UD)$))VZ*.--?;=? 	?r   c                 \    t        t        | 
  | j                  |||| j                  fi |S )zConvert the RRset to wire format.

        All keyword arguments are passed to ``dns.rdataset.to_wire()``; see
        that function for details.

        Returns an ``int``, the number of records emitted.
        )r
   r   to_wirer   r   )r   filecompressr/   r1   r   s        r   r3   zRRset.to_wirem   s4     UD)$))T8V*.--?;=? 	?r   c                 h    t         j                  j                  | j                  t	        |             S )zYConvert an RRset into an Rdataset.

        Returns a ``dns.rdataset.Rdataset``.
        )r   rdatasetfrom_rdata_listttllistr&   s    r   to_rdatasetzRRset.to_rdatasety   s#    
 ||++DHHd4jAAr   r   )NT)NN)__name__
__module____qualname____doc__	__slots__r   r   NONEr   r   r$   r'   r*   r-   r   r3   r;   __classcell__)r   s   @r   r   r      sS     $I58]]5G5G!N0	?(
?Br   r   c                    t        | t              r"t        j                  j	                  | d|      } t        |t              rt        j
                  j	                  |      }t        |t              rt        j                  j	                  |      }t        | ||      }|j                  |       |D ]H  }t        j                  j	                  |j                  |j                  |      }|j                  |       J |S )zCreate an RRset with the specified name, TTL, class, and type, and with
    the specified list of rdatas in text format.

    Returns a ``dns.rrset.RRset`` object.
    N
idna_codec)r)   r   r   r   	from_textr    r   r   
update_ttlrdatar   r   add)	r   r9   r   r   text_rdatasrE   rtrds	            r   from_text_listrN      s     $%xx!!$!D'<(..**73&,'((0dGV$ALLYY  AHHa8	b	  Hr   c                      t        | ||||      S )zCreate an RRset with the specified name, TTL, class, and type and with
    the specified rdatas in text format.

    Returns a ``dns.rrset.RRset`` object.
    )rN   )r   r9   r   r   rJ   s        r   rF   rF      s     $WfkBBr   c                 8   t        | t              r"t        j                  j	                  | d|      } t        |      dk(  rt        d      d}|D ]G  }|2t        | |j                  |j                        }|j                  |       |j                  |       I |S )zCreate an RRset with the specified name and TTL, and with
    the specified list of rdata objects.

    Returns a ``dns.rrset.RRset`` object.
    NrD   r   zrdata list must not be empty)r)   r   r   r   rF   len
ValueErrorr   r   r   rG   rI   )r   r9   rdatasrE   rK   rM   s         r   r8   r8      s     $%xx!!$!D
6{a788A9dBJJ		2ALL	b		 
 Hr   c                     t        | ||      S )zCreate an RRset with the specified name and TTL, and with
    the specified rdata objects.

    Returns a ``dns.rrset.RRset`` object.
    )r8   )r   r9   rS   s      r   
from_rdatarU      s     4f--r   r   )r?   dns.namer   dns.rdatasetdns.rdataclassdns.renderer_compatr   r7   Rdatasetr   rN   rF   r8   rU    r   r   <module>r]      sP   $ 0     !bBCLL!! bBL #,C*.r   