o
    'h.y                     @   s  U d 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 ddl	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ddlZdZdZG dd dejjZed	fd
dZed	fddZ ed	fddZ!dZ"dd Z#dd Z$ej%j&Z'ej%j%G dd dZ(ej%j%G dd de(Z)i Z*eeej+j,ej-j.f e
f e/d< dZ0da1d9ddZ2d9ddZ3				d:deej+j,e4f d eej-j.e4f d!eej5j6e4f d"eej7j8 d#e9d$eej7j8 d%eej7j: d&e(fd'd(Z;	d;deej+j,e4f d eej-j.e4f d)ej<j=d"eej7j8 d&e(f
d*d+Z>	d;deej+j,e4f d eej-j.e4f d,e?d-e@d.e@d"eej7j8 d&e(fd/d0ZAG d1d2 d2ejjZBd3ej+jCfd4e
d e@d5e4d6e9dej+j,d&dfd7d8ZDdS )<z
DNS rdata.    N)import_module)AnyDictOptionalTupleUnion    Tc                   @   s   e Zd ZdZdS )NoRelativeRdataOrderingzAn attempt was made to do an ordered comparison of one or more
    rdata with relative names.  The only reliable way of sorting rdata
    is to use non-relativized rdata.

    N)__name__
__module____qualname____doc__ r   r   E/var/www/html/olx_land/venv/lib/python3.10/site-packages/dns/rdata.pyr	   3   s    r	       c                    s6    s  S | fddtdt D   S )zXBreak a binary string into chunks of chunksize characters separated by
    a space.
    c                    s   g | ]
}||   qS r   r   ).0i	chunksizedatar   r   
<listcomp>C   s    z_wordbreak.<locals>.<listcomp>r   )decodejoinrangelen)r   r   	separatorr   r   r   
_wordbreak;   s   r   c                 K      t t| ||S )zConvert a binary string into its hex encoding, broken up into chunks
    of chunksize characters separated by a separator.
    )r   binasciihexlifyr   r   r   kwr   r   r   _hexifyJ      r"   c                 K   r   )zConvert a binary string into its base64 encoding, broken up into chunks
    of chunksize characters separated by a separator.
    )r   base64	b64encoder    r   r   r   
_base64ifyR   r#   r&   s   "\c                 C   sz   t | tr	|  } t | tst| } d}| D ]$}|tv r%|dt| 7 }q|dkr4|dk r4|t|7 }q|d| 7 }q|S )z7Escape the characters in a quoted string which need it. \r      z\%03d)
isinstancestrencode	bytearray	__escapedchr)qstringtextcr   r   r   	_escapify_   s   

r3   c                 C   sF   t t| d ddD ]}| | dkr| d|d    S q
| dd S )zDetermine the index of greatest byte that isn't all zeros, and
    return the bitmap that contains all the bytes less than that index.
       r   )r   r   )whatr   r   r   r   _truncate_bitmapr   s
   r7   c                   @   s  e Zd ZdZg dZdd Zdd Zdd Zd	d
 Zde	j
jfddZdefddZ		dfdee	jj dedeeef defddZ			dgdee dee	jj dee	jj deddf
ddZ				dhdee dee	jj dee	jj dedee f
ddZ	didee	jj ddfd d!Zdidee	jj defd"d#Zd$d% Zd&d' Zd(d) Zd*d+ Z d,d- Z!d.d/ Z"d0d1 Z#d2d3 Z$d4d5 Z%d6d7 Z&e'			djd8e	j(j)d9e	j
jd:e	j*j+dee	jj ded;ee	jj dd fd<d=Z,e'	did8e	j(j)d9e	j
jd>e	j-j.dee	jj dd f
d?d@Z/dAedd fdBdCZ0e'dDdE Z1e'dFdG Z2e'			dkdHedIedJee dKedef
dLdMZ3e'dNdO Z4e'dPdQ Z5e'dRdS Z6e'dTdU Z7e'dVdW Z8e'dldXdYZ9e'dZd[ Z:e'd\d] Z;e'd^d_ Z<e'd`da Z=e'dbdc Z>e'ddde Z?dS )mRdataz#Base class for all DNS rdata types.)rdclassrdtype	rdcommentc                 C   s"   |  || _| || _d| _dS )zInitialize an rdata.

        *rdclass*, an ``int`` is the rdataclass of the Rdata.

        *rdtype*, an ``int`` is the rdatatype of the Rdata.
        N)_as_rdataclassr9   _as_rdatatyper:   r;   )selfr9   r:   r   r   r   __init__   s   
zRdata.__init__c                 C   s   t jdd | jjD S )Nc                 s   s    | ]	}t |d g V  qdS )	__slots__N)getattr)r   clsr   r   r   	<genexpr>   s    
z'Rdata._get_all_slots.<locals>.<genexpr>)	itertoolschainfrom_iterable	__class____mro__r>   r   r   r   _get_all_slots   s   zRdata._get_all_slotsc                 C   s$   i }|   D ]	}t| |||< q|S N)rJ   rA   )r>   stateslotr   r   r   __getstate__   s   	zRdata.__getstate__c                 C   s@   |  D ]\}}t| || qt| dst| dd  d S d S )Nr;   )itemsobject__setattr__hasattr)r>   rL   rM   valr   r   r   __setstate__   s
   
zRdata.__setstate__returnc                 C   s   t jjS )a  Return the type a Rdata covers.

        DNS SIG/RRSIG rdatas apply to a specific type; this type is
        returned by the covers() function.  If the rdata type is not
        SIG or RRSIG, dns.rdatatype.NONE is returned.  This is useful when
        creating rdatasets, allowing the rdataset to contain only RRSIGs
        of a particular type, e.g. RRSIG(NS).

        Returns a ``dns.rdatatype.RdataType``.
        )dns	rdatatypeNONErI   r   r   r   covers   s   zRdata.coversc                 C   s   |   d> | jB S )zReturn a 32-bit type value, the least significant 16 bits of
        which are the ordinary DNS type, and the upper 16 bits of which are
        the "covered" type, if any.

        Returns an ``int``.
           )rY   r:   rI   r   r   r   extended_rdatatype   s   zRdata.extended_rdatatypeNTorigin
relativizer!   c                 K      t )zEConvert an rdata to text format.

        Returns a ``str``.
        NotImplementedErrorr>   r\   r]   r!   r   r   r   to_text   s   zRdata.to_textFfilecompresscanonicalizec                 C   r^   rK   r_   r>   rc   rd   r\   re   r   r   r   _to_wire   s   zRdata._to_wirec                 C   s8   |r|  |||| dS t }|  |||| | S )z~Convert an rdata to wire format.

        Returns a ``bytes`` if no output file was specified, or ``None`` otherwise.
        N)rg   ioBytesIOgetvalue)r>   rc   rd   r\   re   fr   r   r   to_wire   s   zRdata.to_wirezdns.rdata.GenericRdatac                 C   s   t j| j| j| j|dS )zrCreates a dns.rdata.GenericRdata equivalent of this rdata.

        Returns a ``dns.rdata.GenericRdata``.
        )r\   )rV   rdataGenericRdatar9   r:   rl   )r>   r\   r   r   r   
to_generic   s   zRdata.to_genericc                 C   s   | j |dd}|dusJ |S )zConvert rdata to a format suitable for digesting in hashes.  This
        is also the DNSSEC canonical form.

        Returns a ``bytes``.
        T)r\   re   N)rl   )r>   r\   wirer   r   r   to_digestable   s   zRdata.to_digestablec                 C   sf   |   }|tjjkrd}n
dtj| d }dtj| j d tj| j | d t|  d S )Nr'   ()z<DNS  z rdata: >)	rY   rV   rW   rX   rb   
rdataclassr9   r:   r+   )r>   rY   ctextr   r   r   __repr__	  s(   zRdata.__repr__c                 C   s   |   S rK   )rb   rI   r   r   r   __str__  s   zRdata.__str__c                 C   s   z|   }d}W n tjjy   tr|  tjj}d}Y nw z|  }d}W n tjjy=   tr9| tjj}d}Y nw trK||krJ|rHdS dS n|sO|rQt||krWdS ||kr]dS dS )a  Compare an rdata with another rdata of the same rdtype and
        rdclass.

        For rdata with only absolute names:
            Return < 0 if self < other in the DNSSEC ordering, 0 if self
            == other, and > 0 if self > other.
        For rdata with at least one relative names:
            The rdata sorts before any rdata with only absolute names.
            When compared with another relative rdata, all names are
            made absolute as if they were relative to the root, as the
            proper origin is not available.  While this creates a stable
            ordering, it is NOT guaranteed to be the DNSSEC ordering.
            In the future, all ordering comparisons for rdata with
            relative names will be disallowed.
        FTr5   r4   r   )rq   rV   nameNeedAbsoluteNameOrOrigin_allow_relative_comparisonsrootr	   )r>   otherourour_relativetheirtheir_relativer   r   r   _cmp  s:   z
Rdata._cmpc                 C   s   t |tsdS | j|jks| j|jkrdS d}d}z|  }W n tjjy3   | tjj}d}Y nw z| }W n tjjyN   |tjj}d}Y nw ||krUdS ||kS )NFT)	r*   r8   r9   r:   rq   rV   rz   r{   r}   )r>   r~   r   r   r   r   r   r   r   __eq__L  s*   
zRdata.__eq__c                 C   s6   t |tsdS | j|jks| j|jkrdS | | S NT)r*   r8   r9   r:   r   r>   r~   r   r   r   __ne__a  s
   
zRdata.__ne__c                 C   s4   t |tr| j|jks| j|jkrtS | |dk S Nr   r*   r8   r9   r:   NotImplementedr   r   r   r   r   __lt__h     zRdata.__lt__c                 C   s4   t |tr| j|jks| j|jkrtS | |dkS r   r   r   r   r   r   __le__q  r   zRdata.__le__c                 C   s4   t |tr| j|jks| j|jkrtS | |dkS r   r   r   r   r   r   __ge__z  r   zRdata.__ge__c                 C   s4   t |tr| j|jks| j|jkrtS | |dkS r   r   r   r   r   r   __gt__  r   zRdata.__gt__c                 C   s   t | tjjS rK   )hashrq   rV   rz   r}   rI   r   r   r   __hash__  s   zRdata.__hash__r9   r:   tokrelativize_toc                 C   r^   rK   r_   )rB   r9   r:   r   r\   r]   r   r   r   r   	from_text  s   
zRdata.from_textparserc                 C   r^   rK   r_   rB   r9   r:   r   r\   r   r   r   from_wire_parser  s   zRdata.from_wire_parserkwargsc                    s   t jj} D ])}|dkrq	||vr!tdjj d| d|dv r2tdjj d| dq	 fdd|D }j| } dj}|d	urTt	
|d| |S )
a  
        Create a new Rdata instance based on the instance replace was
        invoked on. It is possible to pass different parameters to
        override the corresponding properties of the base Rdata.

        Any field specific to the Rdata type can be replaced, but the
        *rdtype* and *rdclass* fields cannot.

        Returns an instance of the same Rdata subclass as *self*.
        r;   'z' object has no attribute 'r9   r:   zCannot overwrite 'z' attribute 'c                 3   s"    | ]}  |t|V  qd S rK   )getrA   )r   keyr   r>   r   r   rC     s     z Rdata.replace.<locals>.<genexpr>N)inspect	signaturer?   
parametersAttributeErrorrG   r
   r   r;   rP   rQ   )r>   r   r   r   argsrdr;   r   r   r   replace  s&   
zRdata.replacec                 C      t jj|S rK   )rV   rv   
RdataClassmakerB   valuer   r   r   r<        zRdata._as_rdataclassc                 C   r   rK   )rV   rW   	RdataTyper   r   r   r   r   r=     r   zRdata._as_rdatatyper   r,   
max_lengthempty_okc                 C   s|   |rt |tr| }nt |trt|}nt |tr|}ntd|d ur0t||kr0td|s<t|dkr<td|S )Nz	not bytesztoo longr   zempty bytes not allowed)r*   r+   r,   r-   bytes
ValueErrorr   )rB   r   r,   r   r   bvaluer   r   r   	_as_bytes  s   



zRdata._as_bytesc                 C   s0   t |trtj|S t |tjjstd|S )Nz
not a name)r*   r+   rV   rz   r   Namer   r   r   r   r   _as_name  s
   
zRdata._as_namec                 C   .   t |ts	td|dk s|dkrtd|S )Nnot an integerr      znot a uint8r*   intr   r   r   r   r   	_as_uint8  
   
zRdata._as_uint8c                 C   r   )Nr   r   i  znot a uint16r   r   r   r   r   
_as_uint16  r   zRdata._as_uint16c                 C   r   )Nr   r   l    znot a uint32r   r   r   r   r   
_as_uint32  r   zRdata._as_uint32c                 C   r   )Nr   r   l    znot a uint48r   r   r   r   r   
_as_uint48  r   zRdata._as_uint48c                 C   sF   t |ts	td|d ur||k rtd|d ur!||kr!td|S )Nr   zvalue too smallzvalue too larger   )rB   r   lowhighr   r   r   _as_int  s   
zRdata._as_intc                 C   4   t |trtj|S t |trtj|S td)Nznot an IPv4 address)r*   r+   rV   ipv4re   r   	inet_ntoar   r   r   r   r   _as_ipv4_address%  
   

zRdata._as_ipv4_addressc                 C   r   )Nznot an IPv6 address)r*   r+   rV   ipv6re   r   r   r   r   r   r   r   _as_ipv6_address.  r   zRdata._as_ipv6_addressc                 C   s   t |tr|S td)Nznot a boolean)r*   boolr   r   r   r   r   _as_bool7  s   
zRdata._as_boolc                 C   s:   t |tr| |dtjjS t |trtj|S td)Nr   z	not a TTL)	r*   r   r   rV   ttlMAX_TTLr+   r   r   r   r   r   r   _as_ttl>  s
   

zRdata._as_ttlc                    s6   z |fW S  t y   t fdd|D  Y S w )Nc                 3   s    | ]} |V  qd S rK   r   )r   vas_valuer   r   rC   P  s    z"Rdata._as_tuple.<locals>.<genexpr>)	Exceptiontuple)rB   r   r   r   r   r   	_as_tupleG  s
   zRdata._as_tuplec                 C   s   t |}t| |S rK   )listrandomshuffle)rB   iterablerO   r   r   r   _processing_orderT  s   
zRdata._processing_orderr   NNF)NNNFrK   NTN)FNT)NN)@r
   r   r   r   r@   r?   rJ   rN   rT   rV   rW   r   rY   r   r[   r   rz   r   r   r   r+   r   rb   CompressTyperg   r   rl   ro   rq   rx   ry   r   r   r   r   r   r   r   r   classmethodrv   r   	tokenizer	Tokenizerr   rp   Parserr   r   r<   r=   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8      s   











/				


	-







	




r8   c                	       s~   e Zd ZdZdgZ fddZ		ddeejj	 de
d	eeef d
efddZe	dddZdddZedddZ  ZS )rn   zGeneric Rdata Class

    This class is used for rdata types for which we have no better
    implementation.  It implements the DNS "unknown RRs" scheme.
    r   c                    s   t  || || _d S rK   )superr?   r   )r>   r9   r:   r   rG   r   r   r?   e  s   
zGenericRdata.__init__NTr\   r]   r!   rU   c                 K   s    dt | j t| jfi | S )Nz\# %d )r   r   r"   ra   r   r   r   rb   i  s    zGenericRdata.to_textc                 C   sj   |  }| r|jdkrtjd| }|d }	t	
|	}
t|
|kr/tjd| |||
S )N\#z$generic rdata does not start with \#Tz'generic rdata hex data has wrong length)r   is_identifierr   rV   	exceptionSyntaxErrorget_int!concatenate_remaining_identifiersr,   r   	unhexlifyr   )rB   r9   r:   r   r\   r]   r   tokenlengthhexr   r   r   r   r   q  s   
zGenericRdata.from_textFc                 C   s   | | j d S rK   )writer   rf   r   r   r   rg     s   zGenericRdata._to_wirec                 C   s   | |||  S rK   )get_remainingr   r   r   r   r     s   zGenericRdata.from_wire_parserr   r   r   rK   )r
   r   r   r   r@   r?   r   rV   rz   r   r   r   r+   r   rb   r   r   rg   r   __classcell__r   r   r   r   rn   [  s*    



rn   _rdata_classeszdns.rdtypesc                 C   s   t | |f}|srt tjj|f}|srtrrtj| }tj|}|dd}zt	d
t||g}t||}|t | |f< W n2 tyq   zt	d
td|g}t||}|t tjj|f< |t | |f< W n	 tyn   Y nw Y nw |s~|r~t}|t | |f< |S )N-_.ANY)r   r   rV   rW   r   _dynamic_load_allowedrv   rb   r   r   r   _module_prefixrA   ImportErrorrn   )r9   r:   use_genericrB   rdclass_textrdtype_textmodr   r   r   get_rdata_class  s8   

r   c                 C   sB   t jjD ]
}tt jj|d qtt jjt jjd | rdadS dS )a  Load all rdata types for which dnspython has a non-generic implementation.

    Normally dnspython loads DNS rdatatype implementations on demand, but in some
    specialized cases loading all types at an application-controlled time is preferred.

    If *disable_dynamic_load*, a ``bool``, is ``True`` then dnspython will not attempt
    to use its dynamic loading mechanism if an unknown type is subsequently encountered,
    and will simply use the ``GenericRdata`` class.
    FN)	rV   rW   r   r   rv   INCHAr   )disable_dynamic_loadr:   r   r   r   load_all_types  s   r   r9   r:   r   r\   r]   r   
idna_codecrU   c              	   C   s2  t |trtjj||d}tjj| } tjj	|}t
| |}tjtjjg d}|tkrg| }	||	 |	 rg|	jdkrgt| |||||}
t| ||
jdt|
j|}| }||
jkrgtjd|du ru|| |||||}| }	|	jdurt|d|	j |W  d   S 1 sw   Y  dS )a3  Build an rdata object from text format.

    This function attempts to dynamically load a class which
    implements the specified rdata class and type.  If there is no
    class-and-type-specific implementation, the GenericRdata class
    is used.

    Once a class is chosen, its from_text() class method is called
    with the parameters to this function.

    If *tok* is a ``str``, then a tokenizer is created and the string
    is used as its input.

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

    *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdatatype.

    *tok*, a ``dns.tokenizer.Tokenizer`` or a ``str``.

    *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.

    *idna_codec*, a ``dns.name.IDNACodec``, specifies the IDNA
    encoder/decoder to use if a tokenizer needs to be created.  If
    ``None``, the default IDNA 2003 encoder/decoder is used.  If a
    tokenizer is not created, then the codec associated with the tokenizer
    is the one that is used.

    Returns an instance of the chosen Rdata subclass.

    )r   Nr   r   z9compressed data in generic syntax form of known rdatatyper;   )r*   r+   rV   r   r   rv   r   r   rW   r   r   r   ExceptionWrapperr   rn   r   ungetr   r   r   	from_wirer   r   rl   get_eol_as_tokencommentrP   rQ   )r9   r:   r   r\   r]   r   r   rB   rm   r   grdatarwirer   r   r   r     s>   
-



$r   r   c                 C   sj   t jj| } t jj|}t| |}t jt jj	 |
| |||W  d   S 1 s.w   Y  dS )a  Build an rdata object from wire format

    This function attempts to dynamically load a class which
    implements the specified rdata class and type.  If there is no
    class-and-type-specific implementation, the GenericRdata class
    is used.

    Once a class is chosen, its from_wire() class method is called
    with the parameters to this function.

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

    *rdtype*, a ``dns.rdatatype.RdataType`` or ``str``, the rdatatype.

    *parser*, a ``dns.wire.Parser``, the parser, which should be
    restricted to the rdata length.

    *origin*, a ``dns.name.Name`` (or ``None``).  If not ``None``,
    then names will be relativized to this origin.

    Returns an instance of the chosen Rdata subclass.
    N)rV   rv   r   r   rW   r   r   r   r  	FormErrorr   )r9   r:   r   r\   rB   r   r   r   r     s   
$r   rp   currentrdlenc                 C   sJ   t j||}|| t| |||W  d   S 1 sw   Y  dS )a1  Build an rdata object from wire format

    This function attempts to dynamically load a class which
    implements the specified rdata class and type.  If there is no
    class-and-type-specific implementation, the GenericRdata class
    is used.

    Once a class is chosen, its from_wire() class method is called
    with the parameters to this function.

    *rdclass*, an ``int``, the rdataclass.

    *rdtype*, an ``int``, the rdatatype.

    *wire*, a ``bytes``, the wire-format message.

    *current*, an ``int``, the offset in wire of the beginning of
    the rdata.

    *rdlen*, an ``int``, the length of the wire-format rdata

    *origin*, a ``dns.name.Name`` (or ``None``).  If not ``None``,
    then names will be relativized to this origin.

    Returns an instance of the chosen Rdata subclass.
    N)rV   rp   r   restrict_tor   )r9   r:   rp   r	  r
  r\   r   r   r   r   r  @  s   "$r  c                   @   s   e Zd ZdZddhZdZdS )RdatatypeExistszDNS rdatatype already exists.r9   r:   zKThe rdata type with class {rdclass:d} and rdtype {rdtype:d} already exists.N)r
   r   r   r   supp_kwargsfmtr   r   r   r   r  g  s
    r  Fimplementationr   is_singletonc                 C   sf   t jj|}t||}|tkst j|rt||dt| |	ddt
||f< t j||| dS )a  Dynamically register a module to handle an rdatatype.

    *implementation*, a module implementing the type in the usual dnspython
    way.

    *rdtype*, an ``int``, the rdatatype to register.

    *rdtype_text*, a ``str``, the textual form of the rdatatype.

    *is_singleton*, a ``bool``, indicating if the type is a singleton (i.e.
    RRsets of the type can have only one member.)

    *rdclass*, the rdataclass of the type, or ``dns.rdataclass.ANY`` if
    it applies to all classes.
    r   r   r   N)rV   rW   r   r   r   rn   is_metatyper  rA   r   r   register_type)r  r:   r   r  r9   existing_clsr   r   r   r  q  s   
r  )T)NTNNrK   )Er   r$   r   r   rh   rD   r   	importlibr   typingr   r   r   r   r   dns.exceptionrV   dns.immutabledns.ipv4dns.ipv6dns.namedns.rdataclassdns.rdatatypedns.tokenizerdns.ttldns.wire
_chunksizer|   r   DNSExceptionr	   r   r"   r&   r.   r3   r7   	immutableconstify	_constifyr8   rn   r   rv   r   rW   r   __annotations__r   r   r   r   r+   r   r   rz   r   r   	IDNACodecr   rp   r   r   r   r   r  r  r   r  r   r   r   r   <module>   s   
   \,"





^

*

'