a
    sd_                     @   s`   d Z ddlZddlZddlZddl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)    Nc                       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  ||| || _|| _dS )zCreate a new RRset.N)super__init__r   r   selfr   rdclassrdtypecoversr   	__class__ +/usr/lib/python3/dist-packages/dns/rrset.pyr   (   s    zRRset.__init__c                    s   t   }| j|_| j|_|S N)r   _cloner   r   )r   objr   r   r   r   0   s    
zRRset._clonec                 C   s   | j dkrd}ndtj| j  d }| jd urDdtj| j }nd}dt| j d tj| j d tj| j	 | | d | 
  d	 S )
Nr    ()z delete=z<DNS  z RRset: >)r   dns	rdatatypeto_textr   
rdataclassstrr   r	   r
   Z_rdata_repr)r   ZctextZdtextr   r   r   __repr__6   s.    

zRRset.__repr__c                 C   s   |   S r   )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 |S )NF)
isinstancer   r   r   __eq__)r   otherr   r   r   r!   G   s
    
zRRset.__eq__c                    s0   t  |||sdS | j|ks(| j|kr,dS dS )znReturns ``True`` if this rrset matches the specified class, type,
        covers, and deletion state.
        FT)r   matchr   r   r   r   r   r   r#   N   s
    zRRset.matchTc                    s   t  j| 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   originZ
relativizekwr   r   r   r   Y   s
    zRRset.to_textc                    s    t  j| 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   to_wirer   r   )r   filecompressr$   r%   r   r   r   r&   m   s
    	zRRset.to_wirec                 C   s   t j| jt| S )zYConvert an RRset into an Rdataset.

        Returns a ``dns.rdataset.Rdataset``.
        )r   rdatasetfrom_rdata_listttllistr   r   r   r   to_rdatasety   s    zRRset.to_rdataset)N)NT)NN)__name__
__module____qualname____doc__	__slots__r   r   Z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jj|}tjj	|}t
| ||}|| |D ]&}tjj|j|j||d}|| qR|S )aD  Create an RRset with the specified name, TTL, class, and type, and with
    the specified list of rdatas in text format.

    *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA
    encoder/decoder to use; if ``None``, the default IDNA 2003
    encoder/decoder is used.

    Returns a ``dns.rrset.RRset`` object.
    N
idna_codec)r    r   r   r   	from_textr   Z
RdataClassZmaker   Z	RdataTyper   
update_ttlZrdatar	   r
   add)	r   r+   r	   r
   text_rdatasr5   rtrdr   r   r   from_text_list   s    

r=   c                 G   s   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.
    )r=   )r   r+   r	   r
   r9   r   r   r   r6      s    r6   c                 C   sn   t | trtjj| d|d} t|dkr0tdd}|D ]0}|du r^t| |j|j	}|
| || q8|S )a/  Create an RRset with the specified name and TTL, and with
    the specified list of rdata objects.

    *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA
    encoder/decoder to use; if ``None``, the default IDNA 2003
    encoder/decoder is used.

    Returns a ``dns.rrset.RRset`` object.

    Nr4   r   zrdata list must not be empty)r    r   r   r   r6   len
ValueErrorr   r	   r
   r7   r8   )r   r+   rdatasr5   r:   r<   r   r   r   r*      s    

r*   c                 G   s   t | ||S )zCreate 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    rA   )N)N)r1   Zdns.namer   Zdns.rdatasetZdns.rdataclassZdns.rendererr)   ZRdatasetr   r=   r6   r*   rA   r   r   r   r   <module>   s   g 


