???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................3
¢báW$-  ã               @   s¼   d Z ddlZddlmZ ddlZddlZddlZddlZddl	Zddl
ZddlmZ ejjZG dd„ dejjƒZG dd	„ d	ejjƒZG d
d„ dejjƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )zHDNS rdatasets (an rdataset is a set of rdatas of a given type and class)é    N)ÚStringIOé   )Ústring_typesc               @   s   e Zd ZdZdS )ÚDifferingCoversz~An attempt was made to add a DNS SIG/RRSIG whose covered type
    is not the same as that of the other rdatas in the rdataset.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r
   r
   ú/usr/lib/python3.6/rdataset.pyr   !   s   r   c               @   s   e Zd ZdZdS )ÚIncompatibleTypesz?An attempt was made to add DNS RR data of an incompatible type.N)r   r   r   r	   r
   r
   r
   r   r   '   s   r   c                   sº   e Zd ZdZddddgZejjf‡ fdd„	Z‡ fdd	„Z	d
d„ Z
d$‡ fdd„	Z‡ fdd„Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Z‡ fdd„Zdd„ Zd%dd„Zd&d d!„Zd"d#„ Z‡  ZS )'ÚRdatasetaÝ  A DNS rdataset.

    @ivar rdclass: The class of the rdataset
    @type rdclass: int
    @ivar rdtype: The type of the rdataset
    @type rdtype: int
    @ivar 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
    @ivar ttl: The DNS TTL (Time To Live) value
    @type ttl: int
    ÚrdclassÚrdtypeÚcoversÚttlc                s*   t t| ƒjƒ  || _|| _|| _d| _dS )z©Create a new rdataset of the specified class and type.

        @see: the description of the class instance variables for the
        meaning of I{rdclass} and I{rdtype}r   N)Úsuperr   Ú__init__r   r   r   r   )Úselfr   r   r   )Ú	__class__r
   r   r   C   s
    zRdataset.__init__c                s2   t t| ƒjƒ }| j|_| j|_| j|_| j|_|S )N)r   r   Ú_cloner   r   r   r   )r   Úobj)r   r
   r   r   O   s    zRdataset._clonec             C   s(   t | ƒdkr|| _n|| jk r$|| _dS )zàSet the TTL of the rdataset to be the lesser of the set's current
        TTL or the specified TTL.  If the set contains no rdatas, set the TTL
        to the specified TTL.
        @param ttl: The TTL
        @type ttl: intr   N)Úlenr   )r   r   r
   r
   r   Ú
update_ttlW   s    
zRdataset.update_ttlNc                s¸   | j |j ks| j|jkrt‚|dk	r.| j|ƒ | jtjjksJ| jtjjkr‚|jƒ }t	| ƒdkrt| jtjj
krt|| _n| j|kr‚t‚tjj|jƒr¤t	| ƒdkr¤| jƒ  tt| ƒj|ƒ dS )a%  Add the specified rdata to the rdataset.

        If the optional I{ttl} parameter is supplied, then
        self.update_ttl(ttl) will be called prior to adding the rdata.

        @param rd: The rdata
        @type rd: dns.rdata.Rdata object
        @param ttl: The TTL
        @type ttl: intNr   )r   r   r   r   ÚdnsÚ	rdatatypeZRRSIGZSIGr   r   ÚNONEr   Zis_singletonÚclearr   r   Úadd)r   Úrdr   r   )r   r
   r   r   c   s    

zRdataset.addc                s    | j |jƒ tt| ƒj|ƒ d S )N)r   r   r   r   Úunion_update)r   Úother)r   r
   r   r    ƒ   s    zRdataset.union_updatec                s    | j |jƒ tt| ƒj|ƒ d S )N)r   r   r   r   Úintersection_update)r   r!   )r   r
   r   r"   ‡   s    zRdataset.intersection_updatec                s    | j |jƒ tt| ƒj|ƒ dS )z‹Add all rdatas in other to self.

        @param other: The rdataset from which to update
        @type other: dns.rdataset.Rdataset objectN)r   r   r   r   Úupdate)r   r!   )r   r
   r   r#   ‹   s    zRdataset.updatec             C   sR   | j dkrd}ndtjj| j ƒ d }dtjj| jƒ d tjj| jƒ | d S )Nr   Ú ú(ú)z<DNS ú z
 rdataset>)r   r   r   Úto_textÚ
rdataclassr   r   )r   Zctextr
   r
   r   Ú__repr__”   s    
zRdataset.__repr__c             C   s   | j ƒ S )N)r(   )r   r
   r
   r   Ú__str__œ   s    zRdataset.__str__c                sF   t |tƒsdS | j|jks2| j|jks2| j|jkr6dS tt| ƒj|ƒS )zTwo rdatasets are equal if they have the same class, type, and
        covers, and contain the same rdata.
        @rtype: boolF)Ú
isinstancer   r   r   r   r   Ú__eq__)r   r!   )r   r
   r   r-   Ÿ   s    
zRdataset.__eq__c             C   s   | j |ƒ S )N)r-   )r   r!   r
   r
   r   Ú__ne__¬   s    zRdataset.__ne__Tc             K   sØ   |dk	r"|j ||ƒ}t|ƒ}d}nd}d}tƒ }|dk	r>|}	n| j}	t| ƒdkrz|jd||tjj|	ƒtj	j| j
ƒf ƒ nNxL| D ]D}
|jd||| jtjj|	ƒtj	j| j
ƒ|
jf ||dœ|—Žf ƒ q€W |jƒ dd	… S )
a„  Convert the rdataset into DNS master file format.

        @see: L{dns.name.Name.choose_relativity} for more information
        on how I{origin} and I{relativize} determine the way names
        are emitted.

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

        @param name: If name is not None, emit a RRs with I{name} as
        the owner name.
        @type name: dns.name.Name object
        @param origin: The origin for relative names, or None.
        @type origin: dns.name.Name object
        @param relativize: True if names should names be relativized
        @type relativize: boolNr'   r$   r   z
%s%s%s %s
z%s%s%d %s %s %s
)ÚoriginÚ
relativizer   éÿÿÿÿ)Zchoose_relativityÚstrr   r   r   Úwriter   r)   r(   r   r   r   Úgetvalue)r   Únamer/   r0   Úoverride_rdclassÚkwZntextZpadÚsr   r   r
   r
   r   r(   ¯   s*    


zRdataset.to_textc             C   s&  |dk	r|}d}n| j }|jddƒ t| ƒdkr`|j|||ƒ tjd| j|ddƒ}|j|ƒ dS |rxt| ƒ}	t	j
|	ƒ n| }	xœ|	D ]”}
|j|||ƒ tjd| j|| jdƒ}|j|ƒ |jƒ }|
j|||ƒ |jƒ }|| dk sât‚|j|d ƒ tjd|| ƒ}|j|ƒ |jddƒ q‚W t| ƒS dS )	a,  Convert the rdataset to wire format.

        @param name: The owner name of the RRset that will be emitted
        @type name: dns.name.Name object
        @param file: The file to which the wire format data will be appended
        @type file: file
        @param compress: The compression table to use; the default is None.
        @type compress: dict
        @param origin: The origin to be appended to any relative names when
        they are emitted.  The default is None.
        @returns: the number of records emitted
        @rtype: int
        NFr   é   z!HHIHr   i   z!H)r   Úseekr   Úto_wireÚstructÚpackr   r3   ÚlistÚrandomZshuffler   ÚtellÚAssertionError)r   r5   ÚfileÚcompressr/   r6   Zwant_shuffler   ZstuffÚlr   ÚstartÚendr
   r
   r   r;   â   s8    




zRdataset.to_wirec             C   s&   | j |kr"| j|kr"| j|kr"dS dS )zSReturns True if this rdataset matches the specified class, type,
        and coversTF)r   r   r   )r   r   r   r   r
   r
   r   Úmatch  s
    


zRdataset.match)N)NNTN)NNNT)r   r   r   r	   Ú	__slots__r   r   r   r   r   r   r   r    r"   r#   r*   r+   r-   r.   r(   r;   rG   Ú__classcell__r
   r
   )r   r   r   ,   s$    	 
2 
/r   c             C   sp   t | tƒrtjj| ƒ} t |tƒr,tjj|ƒ}t| |ƒ}|j|ƒ x*|D ]"}tjj|j	|j
|ƒ}|j|ƒ qFW |S )z¤Create an rdataset with the specified class, type, and TTL, and with
    the specified list of rdatas in text format.

    @rtype: dns.rdataset.Rdataset object
    )r,   r   r   r)   Ú	from_textr   r   r   Zrdatar   r   r   )r   r   r   Útext_rdatasÚrÚtr   r
   r
   r   Úfrom_text_list  s    




rN   c             G   s   t | |||ƒS )zœCreate an rdataset with the specified class, type, and TTL, and with
    the specified rdatas in text format.

    @rtype: dns.rdataset.Rdataset object
    )rN   )r   r   r   rK   r
   r
   r   rJ   /  s    rJ   c             C   sT   t |ƒdkrtdƒ‚d}x6|D ].}|dkrBt|j|jƒ}|j| ƒ |j|ƒ qW |S )z‹Create an rdataset with the specified TTL, and with
    the specified list of rdata objects.

    @rtype: dns.rdataset.Rdataset object
    r   zrdata list must not be emptyN)r   Ú
ValueErrorr   r   r   r   r   )r   ÚrdatasrL   r   r
   r
   r   Úfrom_rdata_list9  s    

rQ   c             G   s
   t | |ƒS )zƒCreate an rdataset with the specified TTL, and with
    the specified rdata objects.

    @rtype: dns.rdataset.Rdataset object
    )rQ   )r   rP   r
   r
   r   Ú
from_rdataK  s    rR   )r	   r?   Úior   r<   Zdns.exceptionr   Zdns.rdatatypeZdns.rdataclassZ	dns.rdataZdns.setZ_compatr   ÚsetÚSetZ	SimpleSetZ	exceptionZDNSExceptionr   r   r   rN   rJ   rQ   rR   r
   r
   r
   r   Ú<module>   s$    q
