3
[_ð]  ã               @   sl   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„ dejj	ƒZ
ddd„Zd	d
„ Zddd„Zdd„ ZdS )z)DNS RRsets (an RRset is a named rdataset)é    Né   )Ústring_typesc                   sŒ   e Zd ZdZddgZejjdf‡ fdd„	Z‡ fdd„Z	d	d
„ Z
dd„ Z‡ fdd„Zd‡ fdd„	Zd‡ fdd„	Zd‡ fdd„	Zdd„ Z‡  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                s$   t t| ƒj|||ƒ || _|| _dS )zCreate a new RRset.N)Úsuperr   Ú__init__r   r   )Úselfr   ÚrdclassÚrdtypeÚcoversr   )Ú	__class__© ú./tmp/pip-build-yz_zf6az/dnspython/dns/rrset.pyr   )   s    zRRset.__init__c                s"   t t| ƒjƒ }| j|_| j|_|S )N)r   r   Ú_cloner   r   )r	   Úobj)r   r   r   r   1   s    zRRset._clonec             C   s†   | j dkrd}ndtjj| j ƒ d }| jd k	rDdtjj| jƒ }nd}dt| jƒ d tjj| jƒ d tjj| j	ƒ | | d S )	Nr   Ú ú(ú)z delete=z<DNS ú z RRset>)
r   ÚdnsÚ	rdatatypeÚto_textr   Ú
rdataclassÚstrr   r
   r   )r	   ZctextZdtextr   r   r   Ú__repr__7   s    

zRRset.__repr__c             C   s   | j ƒ S )N)r   )r	   r   r   r   Ú__str__D   s    zRRset.__str__c                s.   t |tƒsdS | j|jkrdS tt| ƒj|ƒS )NF)Ú
isinstancer   r   r   Ú__eq__)r	   Úother)r   r   r   r   G   s
    
zRRset.__eq__c                s4   t t| ƒj|||ƒsdS | j|ks,| j|kr0dS dS )znReturns ``True`` if this rrset matches the specified class, type,
        covers, and deletion state.
        FT)r   r   Úmatchr   r   )r	   r   r
   r   r   r   )r   r   r   r    N   s
    zRRset.matchTc                s   t t| ƒj| j||| jf|Ž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	   ÚoriginZ
relativizeÚkw)r   r   r   r   Y   s    zRRset.to_textc                s    t t| ƒj| j|||| jf|ŽS )zÖConvert 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!   r"   )r   r   r   r#   m   s    	zRRset.to_wirec             C   s   t jj| jt| ƒƒS )zYConvert an RRset into an Rdataset.

        Returns a ``dns.rdataset.Rdataset``.
        )r   ÚrdatasetÚfrom_rdata_listÚttlÚlist)r	   r   r   r   Úto_rdatasety   s    zRRset.to_rdataset)N)NT)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   ÚNONEr   r   r   r   r   r    r   r#   r*   Ú__classcell__r   r   )r   r   r      s   	r   c       	      C   sŽ   t | tƒrtjj| d|d�} t |tƒr2tjj|ƒ}t |tƒrHtjj|ƒ}t| ||ƒ}|j|ƒ x*|D ]"}tj	j|j
|j|ƒ}|j|ƒ qdW |S )z¨Create 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_ttlZrdatar
   r   Úadd)	r   r(   r
   r   Útext_rdatasr2   ÚrÚtÚrdr   r   r   Úfrom_text_list�   s    




r:   c             G   s   t | ||||ƒS )zŸCreate an RRset with the specified name, TTL, class, and type and with
    the specified rdatas in text format.

    Returns a ``dns.rrset.RRset`` object.
    )r:   )r   r(   r
   r   r6   r   r   r   r3   —   s    r3   c             C   sr   t | tƒrtjj| d|d�} t|ƒdkr0tdƒ‚d}x8|D ]0}|dkr`t| |j|j	ƒ}|j
|ƒ |j|ƒ q:W |S )z’Create an RRset with the specified name and TTL, and with
    the specified list of rdata objects.

    Returns a ``dns.rrset.RRset`` object.
    N)r2   r   zrdata list must not be empty)r   r   r   r   r3   ÚlenÚ
ValueErrorr   r
   r   r4   r5   )r   r(   Úrdatasr2   r7   r9   r   r   r   r'   ¡   s    


r'   c             G   s   t | ||ƒS )zŠCreate an RRset with the specified name and TTL, and with
    the specified rdata objects.

    Returns a ``dns.rrset.RRset`` object.
    )r'   )r   r(   r=   r   r   r   Ú
from_rdata¶   s    r>   )N)N)r.   Zdns.namer   Zdns.rdatasetZdns.rdataclassZdns.rendererÚ_compatr   r&   ZRdatasetr   r:   r3   r'   r>   r   r   r   r   Ú<module>   s   f


