o
    'hA                     @   s  d Z ddlZddlZddlZddlmZmZmZmZm	Z	m
Z
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ZddlZddl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ejjG d
d deZ				dde
ej j!e"f de
ej#j$e"f de%dee" de	ej&j' de	ej&j( de)de	ej&j( defddZ*de
ej j!e"f de
ej#j$e"f de%dedef
ddZ+de%deej,j- defddZ.de%dedefddZ/dS ) zHDNS rdatasets (an rdataset is a set of rdatas of a given type and class)    N)Any
CollectionDictListOptionalUnioncastc                   @      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   H/var/www/html/olx_land/venv/lib/python3.10/site-packages/dns/rdataset.pyr
   '       r
   c                   @   r	   )IncompatibleTypesz?An attempt was made to add DNS RR data of an incompatible type.Nr   r   r   r   r   r   ,   r   r   c                       s  e Zd ZdZg dZejjdfdejj	dejj
dejj
def fdd	Z fd
dZdeddfddZ	d6dejjdee ddf fddZ fddZ fddZ fddZdd Zdd Zdd Z fdd Zd!d" Z			#		$d7d%eejj d&eejj d'ed(eejj	 d)ed*eee f defd+d,Z!				#d8d%ejjd-e d.eejj" d&eejj d(eejj	 d/edefd0d1Z#dejj	dejj
dejj
defd2d3Z$de%ejj fd4d5Z&  Z'S )9RdatasetzA DNS rdataset.)rdclassrdtypecoversttlr   r   r   r   r   c                    s&   t    || _|| _|| _|| _dS )a5  Create a new rdataset of the specified class and type.

        *rdclass*, a ``dns.rdataclass.RdataClass``, the rdataclass.

        *rdtype*, an ``dns.rdatatype.RdataType``, the rdatatype.

        *covers*, an ``dns.rdatatype.RdataType``, the covered rdatatype.

        *ttl*, an ``int``, the TTL.
        N)super__init__r   r   r   r   )selfr   r   r   r   	__class__r   r   r   5   s
   

zRdataset.__init__c                    s.   t   }| j|_| j|_| j|_| j|_|S N)r   _cloner   r   r   r   )r   objr   r   r   r   M   s   
zRdataset._clonereturnNc                 C   s:   t j|}t| dkr|| _dS || jk r|| _dS dS )a   Perform TTL minimization.

        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.

        *ttl*, an ``int`` or ``str``.
        r   N)dnsr   makelenr   r   r   r   r   
update_ttlU   s   	


zRdataset.update_ttlrdc                    s   | j |j ks| j|jkrt|dur| | | jtjjks%| jtjjkrA| }t	| dkr:| jtjj
kr:|| _n| j|krAttj|jrRt	| dkrR|   t | dS )a!  Add the specified rdata to the rdataset.

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

        *rd*, a ``dns.rdata.Rdata``, the rdata

        *ttl*, an ``int``, the TTL.

        Raises ``dns.rdataset.IncompatibleTypes`` if the type and class
        do not match the type and class of the rdataset.

        Raises ``dns.rdataset.DifferingCovers`` if the type is a signature
        type and the covered type does not match that of the rdataset.
        Nr   )r   r   r   r&   r"   	rdatatypeRRSIGSIGr   r$   NONEr
   is_singletonclearr   add)r   r'   r   r   r   r   r   r.   d   s   

zRdataset.addc                       |  |j t | d S r   )r&   r   r   union_updater   otherr   r   r   r0         zRdataset.union_updatec                    r/   r   )r&   r   r   intersection_updater1   r   r   r   r4      r3   zRdataset.intersection_updatec                    s   |  |j t | dS )zAdd all rdatas in other to self.

        *other*, a ``dns.rdataset.Rdataset``, the rdataset from which
        to update.
        N)r&   r   r   updater1   r   r   r   r5      s   zRdataset.updatec                    s(   dd  dd  fdd| D  d S )Nc                 S   s    t | dkr| d d d S | S )Nd   z...)r$   )sr   r   r   maybe_truncate   s   z,Rdataset._rdata_repr.<locals>.maybe_truncate[z, c                 3   s$    | ]}d  t | dV  qdS )<>N)str).0rrr8   r   r   	<genexpr>   s   " z'Rdataset._rdata_repr.<locals>.<genexpr>])joinr   r   r?   r   _rdata_repr   s    zRdataset._rdata_reprc                 C   s^   | j dkrd}ndtj| j  d }dtj| j d tj| j | d |   d S )	Nr    ()z<DNS  z rdataset: r;   )r   r"   r(   to_text
rdataclassr   r   rD   )r   ctextr   r   r   __repr__   s&   
zRdataset.__repr__c                 C   s   |   S r   )rI   rC   r   r   r   __str__      zRdataset.__str__c                    sB   t |tsdS | j|jks| j|jks| j|jkrdS t |S )NF)
isinstancer   r   r   r   r   __eq__r1   r   r   r   rP      s   
zRdataset.__eq__c                 C   s   |  | S r   )rP   r1   r   r   r   __ne__   s   zRdataset.__ne__TFnameorigin
relativizeoverride_rdclasswant_commentskwc                 K   s   |dur| ||}t|}d}nd}d}t }	|dur |}
n| j}
t| dkrB|	| | tj	|
 dtj
	| j d n3| D ]0}d}|rS|jrSd|j }|	d||| jtj	|
tj
	| j|j	d
||d||f  qD|	 dd	 S )au  Convert the rdataset into DNS zone 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.

        *name*, a ``dns.name.Name``.  If name is not ``None``, emit RRs with
        *name* as the owner name.

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

        *relativize*, a ``bool``.  If ``True``, names will be relativized
        to *origin*.

        *override_rdclass*, a ``dns.rdataclass.RdataClass`` or ``None``.
        If not ``None``, use this class instead of the Rdataset's class.

        *want_comments*, a ``bool``.  If ``True``, emit comments for rdata
        which have them.  The default is ``False``.
        NrH   rE   r   
z ;z%s%s%d %s %s %s%s
)rS   rT   r   )choose_relativityr<   ioStringIOr   r$   writer"   rJ   rI   r(   r   	rdcommentr   getvalue)r   rR   rS   rT   rU   rV   rW   ntextpadr7   r   r'   extrar   r   r   rI      sD   "
zRdataset.to_textfilecompresswant_shufflec           
   	   C   s   |dur	|}d}n| j }t| dkr(|||| |td| j|dd dS |r4t| }t	| n| }|D ]4}	|||| |td| j|| j
 tj|d |	||| W d   n1 sgw   Y  q8t| S )at  Convert the rdataset to wire format.

        *name*, a ``dns.name.Name`` is the owner name to use.

        *file* is the file where the name is emitted (typically a
        BytesIO file).

        *compress*, a ``dict``, is the compression table to use.  If
        ``None`` (the default), names will not be compressed.

        *origin* is a ``dns.name.Name`` or ``None``.  If the name is
        relative and origin is not ``None``, then *origin* will be appended
        to it.

        *override_rdclass*, an ``int``, is used as the class instead of the
        class of the rdataset.  This is useful when rendering rdatasets
        associated with dynamic updates.

        *want_shuffle*, a ``bool``.  If ``True``, then the order of the
        Rdatas within the Rdataset will be shuffled before rendering.

        Returns an ``int``, the number of records emitted.
        NFr   z!HHIH   z!HHI   )r   r$   to_wirer]   structpackr   listrandomshuffler   r"   rendererprefixed_length)
r   rR   rc   rd   rS   rU   re   r   lr'   r   r   r   rh     s(   !zRdataset.to_wirec                 C   s&   | j |kr| j|kr| j|krdS dS )zaReturns ``True`` if this rdataset matches the specified class,
        type, and covers.
        TF)r   r   r   )r   r   r   r   r   r   r   matchM  s   	zRdataset.matchc                 C   s"   t | dkrg S | d t| S )aT  Return rdatas in a valid processing order according to the type's
        specification.  For example, MX records are in preference order from
        lowest to highest preferences, with items of the same preference
        shuffled.

        For types that do not define a processing order, the rdatas are
        simply shuffled.
        r   )r$   _processing_orderiterrC   r   r   r   processing_orderZ  s   	zRdataset.processing_orderr   )NNTNF)NNNT)(r   r   r   r   	__slots__r"   r(   r+   rJ   
RdataClass	RdataTypeintr   r   r&   rdataRdatar   r.   r0   r4   r5   rD   rL   rM   rP   rQ   rR   Nameboolr   r<   r   rI   CompressTyperh   rq   r   rt   __classcell__r   r   r   r   r   0   s    '





S



8
r   c                       s   e Zd ZdZeZdef fddZdd Zd(dd	Zd
d Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Z fddZ fddZ fd d!Z fd"d#Z fd$d%Z fd&d'Z  ZS ))ImmutableRdatasetzAn immutable DNS rdataset.rdatasetc                    s.   t  |j|j|j|j tj|j	| _	dS )z9Create an immutable rdataset from the specified rdataset.N)
r   r   r   r   r   r   r"   	immutabler   items)r   r   r   r   r   r   o  s   zImmutableRdataset.__init__c                 C      t dNr   	TypeErrorr%   r   r   r   r&   w  rN   zImmutableRdataset.update_ttlNc                 C   r   r   r   )r   r'   r   r   r   r   r.   z  rN   zImmutableRdataset.addc                 C   r   r   r   r1   r   r   r   r0   }  rN   zImmutableRdataset.union_updatec                 C   r   r   r   r1   r   r   r   r4     rN   z%ImmutableRdataset.intersection_updatec                 C   r   r   r   r1   r   r   r   r5     rN   zImmutableRdataset.updatec                 C   r   r   r   )r   ir   r   r   __delitem__  rN   zImmutableRdataset.__delitem__c                 C   r   r   r   r1   r   r   r   __ior__  rN   zImmutableRdataset.__ior__c                 C   r   r   r   r1   r   r   r   __iand__  rN   zImmutableRdataset.__iand__c                 C   r   r   r   r1   r   r   r   __iadd__  rN   zImmutableRdataset.__iadd__c                 C   r   r   r   r1   r   r   r   __isub__  rN   zImmutableRdataset.__isub__c                 C   r   r   r   rC   r   r   r   r-     rN   zImmutableRdataset.clearc                       t t  S r   r   r   copyrC   r   r   r   __copy__     zImmutableRdataset.__copy__c                    r   r   r   rC   r   r   r   r     r   zImmutableRdataset.copyc                       t t |S r   )r   r   unionr1   r   r   r   r        zImmutableRdataset.unionc                    r   r   )r   r   intersectionr1   r   r   r   r     r   zImmutableRdataset.intersectionc                    r   r   )r   r   
differencer1   r   r   r   r     r   zImmutableRdataset.differencec                    r   r   )r   r   symmetric_differencer1   r   r   r   r     r   z&ImmutableRdataset.symmetric_differencer   )r   r   r   r   r   _clone_classr   r&   r.   r0   r4   r5   r   r   r   r   r   r-   r   r   r   r   r   r   r~   r   r   r   r   r   i  s*    
r   Tr   r   r   text_rdatas
idna_codecrS   rT   relativize_tor!   c              
   C   sd   t jj| } t jj|}t| |}|| |D ]}	t j	|j
|j|	||||}
||
 q|S )a|  Create an rdataset with the specified class, type, and TTL, 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.

    *origin*, a ``dns.name.Name`` (or ``None``), the
    origin to use for relative names.

    *relativize*, a ``bool``.  If true, name will be relativized.

    *relativize_to*, a ``dns.name.Name`` (or ``None``), the origin to use
    when relativizing names.  If not set, the *origin* value will be used.

    Returns a ``dns.rdataset.Rdataset`` object.
    )r"   rJ   rv   r#   r(   rw   r   r&   ry   	from_textr   r   r.   )r   r   r   r   r   rS   rT   r   rtr'   r   r   r   from_text_list  s   

r   c                 G   s   t | ||ttt |S )zCreate an rdataset with the specified class, type, and TTL, and with
    the specified rdatas in text format.

    Returns a ``dns.rdataset.Rdataset`` object.
    )r   r   r   r<   )r   r   r   r   r   r   r   r     s   r   rdatasc                 C   s\   t |dkr
tdd}|D ]}|du r t|j|j}||  || q|dus,J |S )zCreate an rdataset with the specified TTL, and with
    the specified list of rdata objects.

    Returns a ``dns.rdataset.Rdataset`` object.
    r   zrdata list must not be emptyN)r$   
ValueErrorr   r   r   r&   r.   )r   r   r   r'   r   r   r   from_rdata_list  s   
r   c                 G   s   t | tttjj |S )zCreate an rdataset with the specified TTL, and with
    the specified rdata objects.

    Returns a ``dns.rdataset.Rdataset`` object.
    )r   r   r   r"   ry   rz   )r   r   r   r   r   
from_rdata  s   r   )NNTN)0r   r[   rl   ri   typingr   r   r   r   r   r   r   dns.exceptionr"   dns.immutabledns.name	dns.rdatadns.rdataclassdns.rdatatypedns.rendererdns.setdns.ttlsetSet	SimpleSet	exceptionDNSExceptionr
   r   r   r   r   rJ   rv   r<   r(   rw   rx   rR   	IDNACodecr{   r|   r   r   ry   rz   r   r   r   r   r   r   <module>   st   $  ;J


	
(
