o
    'hex                  #   @   s  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Zddl	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ddlZddlmZ ddlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) e(r~ddl*Z*ej+j,Z-dd Z.dYdd	Z/	dYd
ej0j1deej2j3e4f de
dee5 dee6e5f f
ddZ7										dZd
ej0j1dee
 dee5 de8de8deeej9j:ej;j<f  dee4 de8de8de8deej2j3 de
fddZ=											d[dej2j3de>d ee5 d!e6d"ee> d#e6de8de8de8de8d
eej0j1 d$eej0j? de8dej2j3fd%d&Z@											d\dej2j3de>d ee5 d!e6d"ee> d#e6de8de8de8d'eej0j1 d(eej0jA d$eej0j? de8deej2j3e8f fd)d*ZB	dYd
ej0jAdeej2j3e4f dee5 dee6e5f fd+d,ZCd-d. ZD					d]d
ej0jAdee5 de8deeej9j:ej;j<f  dee4 de8deej2j3e5f fd/d0ZE								d^dej2j3de>d ee5 d!e6d"ee> d#e6de8de8d
eej0jA d$eej0j? dej2j3fd1d2ZF		3									4d_dej2j3de>d ee5 d!e6d"ee> d#e6de8de8d
eej0jA d$eej0j? d5ee)jG d6ee> d7ee8e>f dej2j3fd8d9ZHd:ed; dd;fd<d=ZIdd>dddddd?d4d4ddejJejKfdej2j3de>d ee5 d!e6d"ee> d#e6de8de8d@edA dBe>dCe8d7ee8e>f dDee> d:ed; dEe6dFedej2j3f"dGdHZL		3					4			4d`dej2j3de>dIe>d ee5 d!e6d"ee> d#e6de8de8d7ee8e>f d$eej0j? dJee> dCe8dej2j3fdKdLZM		3						4			dadej2j3de>d ee5 d!e6d"ee> d#e6de8de8dMeejNjO d7ee8e>f d$eej0j? dJee> d6ee> dej2j3fdNdOZNdPejPjQdQej0jRdej2j3dRee6 d ee5 de5de
fdSdTZSdddddde"jTdfde>dPejPjQdeej2j3 d!e6d ee5 dUee5 d"ee> d#e6dVe"d$eej0j? ddfdWdXZUdS )bzTalk to a DNS server.    N)AnyDictOptionalTupleUnioncast)NullContext)BadResponseHTTPVersionNoDOHNoDOQUDPMode_check_status_compute_times_make_dot_ssl_context_matches_destination
_remaininghave_dohsslc                 C   sV   |s|r)|d u r%| t jkrd}||fS | t jkrd}||fS td|  ||fS d S )Nz0.0.0.0z::zunknown address family )socketAF_INETAF_INET6NotImplementedError)afaddressport r   J/var/www/html/olx_land/venv/lib/python3.10/site-packages/dns/asyncquery.py_source_tuple>   s   

r   c                 C   s&   | d ur|s
t   }t| | dS d S Nr   )timemax)
expirationnowr   r   r   _timeoutN   s
   r$   sockwhatdestinationr"   returnc                    sB   t |tjjr| }t }| ||t||I dH }||fS )a  Send a DNS message to the specified UDP socket.

    *sock*, a ``dns.asyncbackend.DatagramSocket``.

    *what*, a ``bytes`` or ``dns.message.Message``, the message to send.

    *destination*, a destination tuple appropriate for the address family
    of the socket, specifying where to send the query.

    *expiration*, a ``float`` or ``None``, the absolute time at which
    a timeout exception should be raised.  If ``None``, no timeout will
    occur.  The expiration value is meaningless for the asyncio backend, as
    asyncio's transport sendto() never blocks.

    Returns an ``(int, float)`` tuple of bytes sent and the sent time.
    N)
isinstancednsmessageMessageto_wirer    sendtor$   )r%   r&   r'   r"   	sent_timenr   r   r   send_udpW   s   r1   F    ignore_unexpectedone_rr_per_rrsetkeyringrequest_macignore_trailingraise_on_truncationignore_errorsqueryc              
      s   d}	 |  dt|I dH \}}t| j|||sqt }ztjj||||||d}W n- tjjyN } z|	rI|
durI|
	| sIW Y d}~q d}~w t
yY   |	rXY q w |	rf|
durf|
	|sfq|||fS )aj  Read a DNS message from a UDP socket.

    *sock*, a ``dns.asyncbackend.DatagramSocket``.

    See :py:func:`dns.query.receive_udp()` for the documentation of the other
    parameters, and exceptions.

    Returns a ``(dns.message.Message, float, tuple)`` tuple of the received message, the
    received time, and the address where the message arrived from.
    r2   T  N)r5   r6   r4   r7   r8   )recvfromr$   r   familyr    r*   r+   	from_wire	Truncatedis_response	Exception)r%   r'   r"   r3   r4   r5   r6   r7   r8   r9   r:   wirefrom_addressreceived_timerer   r   r   receive_udpu   sF   


rG   5   qwheretimeoutr   sourcesource_portbackendc                    s$  |   }t|\}}tj|}t||f|}|
rt|
}n%|s&tj }t	|||}|
 r5||f}nd}||tjd||I dH }|4 I dH ;}t||||I dH  t|||||| j| j||	|| I dH \}}}|| |_|sy| |syt|W  d  I dH  S 1 I dH sw   Y  dS )aF  Return the response obtained after sending a query via UDP.

    *sock*, a ``dns.asyncbackend.DatagramSocket``, or ``None``,
    the socket to use for the query.  If ``None``, the default, a
    socket is created.  Note that if a socket is provided, the
    *source*, *source_port*, and *backend* are ignored.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.udp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    Nr   )r-   r   r*   inetaf_for_address_lltupler   asyncbackendget_default_backendr   datagram_connection_requiredmake_socketr   
SOCK_DGRAMr1   rG   r5   macr    r@   r	   )rI   rJ   rK   r   rL   rM   r3   r4   r7   r8   r%   rN   r9   rB   
begin_timer"   r   r'   cmstupledtuplesrE   rD   _r   r   r   udp   sD   



0r^   udp_socktcp_sockc                    sr   zt | ||||||||d|	||I dH }|dfW S  tjjy8   t| ||||||||
|
I dH }|df Y S w )a  Return the response to the query, trying UDP first and falling back
    to TCP if UDP results in a truncated response.

    *udp_sock*, a ``dns.asyncbackend.DatagramSocket``, or ``None``,
    the socket to use for the UDP query.  If ``None``, the default, a
    socket is created.  Note that if a socket is provided the *source*,
    *source_port*, and *backend* are ignored for the UDP query.

    *tcp_sock*, a ``dns.asyncbackend.StreamSocket``, or ``None``, the
    socket to use for the TCP query.  If ``None``, the default, a
    socket is created.  Note that if a socket is provided *where*,
    *source*, *source_port*, and *backend*  are ignored for the TCP query.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.udp_with_fallback()` for the documentation
    of the other parameters, exceptions, and return type of this
    method.
    TNF)r^   r*   r+   r?   tcp)rI   rJ   rK   r   rL   rM   r3   r4   r7   r_   r`   rN   r9   responser   r   r   udp_with_fallback   sB   #


rc   c                    s^   t |tjjr|jdd}n
t|dd| }t }| |t	||I dH  t||fS )zSend a DNS message to the specified TCP socket.

    *sock*, a ``dns.asyncbackend.StreamSocket``.

    See :py:func:`dns.query.send_tcp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    T)prepend_length   bigN)
r)   r*   r+   r,   r-   lento_bytesr    sendallr$   )r%   r&   r"   tcpmsgr/   r   r   r   send_tcp8  s   rk   c                    sT   d}|dkr(|  |t|I dH }|dkrtd|t| }|| }|dks|S )z|Read the specified number of bytes from stream.  Keep trying until we
    either get the desired amount, or we hit EOF.
    r2   r   NEOF)recvr$   EOFErrorrg   )r%   countr"   r\   r0   r   r   r   _read_exactlyQ  s   rp   c                    sZ   t | d|I dH }td|\}t | ||I dH }t }	tjj|||||d}
|
|	fS )zRead a DNS message from a TCP socket.

    *sock*, a ``dns.asyncbackend.StreamSocket``.

    See :py:func:`dns.query.receive_tcp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    re   N!Hr5   r6   r4   r7   )rp   structunpackr    r*   r+   r>   )r%   r"   r4   r5   r6   r7   ldatalrB   rD   rE   r   r   r   receive_tcp_  s   rw   c
              	      s  |   }
t|\}}|r| I dH  t|}n%tj|}t|||}||f}|	s0tj	 }	|	
|tjd|||I dH }|4 I dH 2}t||
|I dH  t|||| j| j|I dH \}}|| |_| |sjt|W  d  I dH  S 1 I dH s|w   Y  dS )aO  Return the response obtained after sending a query via TCP.

    *sock*, a ``dns.asyncbacket.StreamSocket``, or ``None``, the
    socket to use for the query.  If ``None``, the default, a socket
    is created.  Note that if a socket is provided
    *where*, *port*, *source*, *source_port*, and *backend* are ignored.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.tcp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    Nr   )r-   r   getpeernamer   r*   rO   rP   r   rR   rS   rU   r   SOCK_STREAMrk   rw   r5   rW   r    r@   r	   )rI   rJ   rK   r   rL   rM   r4   r7   r%   rN   rB   rX   r"   rY   r   rZ   r[   r\   rE   rD   r   r   r   ra   }  s0   




0ra   U  Tssl_contextserver_hostnameverifyc                    s   t |\}}|rt|}n0|
du rt||}
tj|}t|||}||f}|	s.tj }	|		|t
jd||||
|I dH }|4 I dH *}t|}t| |||||||||	
I dH }t }|| |_|W  d  I dH  S 1 I dH stw   Y  dS )a  Return the response obtained after sending a query via TLS.

    *sock*, an ``asyncbackend.StreamSocket``, or ``None``, the socket
    to use for the query.  If ``None``, the default, a socket is
    created.  Note that if a socket is provided, it must be a
    connected SSL stream socket, and *where*, *port*,
    *source*, *source_port*, *backend*, *ssl_context*, and *server_hostname*
    are ignored.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.tls()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    Nr   )r   r   r   r*   rO   rP   r   rR   rS   rU   r   ry   r$   ra   r    )rI   rJ   rK   r   rL   rM   r4   r7   r%   rN   r{   r|   r}   rX   r"   rY   r   rZ   r[   r\   rb   end_timer   r   r   tls  sN   






0r   resolverzdns.asyncresolver.Resolverc                 C   s   | d u rdd l }|j } | S r   )dns.asyncresolverasyncresolverResolver)r   r*   r   r   r   _maybe_get_resolver  s   
r   i  z
/dns-queryclientzhttpx.AsyncClientpathpostbootstrap_addressr=   http_versionc           "         s0  zt j|}W n ty   d}Y nw |dur?t j|r?|tjkr/d| d| |	 }n|tjkr>d| d| |	 }n|}i }|du rmtj	
|}|jdu rVtdt j|jre|j}|j|d< |jdurm|j}|tjksy|tjkrts|du rt|}|jdusJ ||j|I dH }tt| }t| ||||||||||
dI dH S tst|rt|tjstd	|  }d
di}|tjtjfv }|tjtjfv }t j  }|du rd}d}n|}|}|rt!|}n|" ||||||||d}tj||||d}|4 I dH I}|
r,|#dt$t%|d |&|j'||||d|I dH }nt()|*d}|+ } |&|j,||d| i|d|I dH }W d  I dH  n1 I dH s[w   Y  |j-dk sl|j-dkrzt| d|j- d|j.t j/j0|j.| j1| j2||d}!|j34 |!_5| 6|!st7|!S )a  Return the response obtained after sending a query via DNS-over-HTTPS.

    *client*, a ``httpx.AsyncClient``.  If provided, the client to use for
    the query.

    Unlike the other dnspython async functions, a backend cannot be provided
    in this function because httpx always auto-detects the async backend.

    See :py:func:`dns.query.https()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    Nzhttps://:z	https://[z]:zno hostname in URLsni_hostname)r}   r   z.session parameter must be an httpx.AsyncClientacceptzapplication/dns-messager   )local_addresshttp1http2r}   
local_portr   r   r=   )r   r   r}   	transport)zcontent-typezcontent-length)headerscontent
extensions   =r*   )r   paramsr      i+  z responded with status code z
Response body: rr   )8r*   rO   rP   
ValueError
is_addressr   r   r   urllibparseurlparsehostnamer   r
   H3DEFAULTr   r   resolve_namerandomchoicelist	addresses_http3r   r)   httpxAsyncClientr-   H1H2rR   rS   r   get_transport_classupdatestrrg   wait_forr   base64urlsafe_b64encoderstripdecodegetstatus_coder   r+   r>   r5   r6   elapsedtotal_secondsr    r@   r	   )"rI   rJ   rK   r   rL   rM   r4   r7   r   r   r   r}   r   r   r=   r   r   urlr   parsedanswersrB   r   h1h2rN   r   r   rY   r   
the_clientrb   twirerE   r   r   r   https	  s   









*"r   r   r   c                    s  t jjs	tdtj|}|j}|jd ur|j}d| _	| 
 }t j|
\}}| 4 I d H }|||	|dd4 I d H Z}|||||}t|\}}||I d H }|4 I d H $ |||| |t|I d H }t| || W d   I d H  n1 I d H sw   Y  t }W d   I d H  n1 I d H sw   Y  t jj|| j| j||d}W d   I d H  n1 I d H sw   Y  t|| d|_| |st|S )Nz DNS-over-HTTP3 is not available.r   T)verify_modeserver_nameh3rr           )r*   quic	have_quicr   r   r   r   r   r   idr-   factories_for_backendconnectr   make_streamsend_h3receiver   r   r   r    r+   r>   r5   r6   r!   r@   r	   )rI   rJ   r   rK   r   rL   rM   r4   r7   r}   rN   r   r   	url_partsrB   cfactorymfactorycontextthe_managerthe_connectionstartr"   streamfinishrE   r   r   r   r     sJ   
(
((
r   
connectionc                    s  t jjs	td|dur|du r|}d| _|  }|r't jj}t jj}|}nt j|
\}}| 4 I dH }|||	|d4 I dH V}|sM|||||}t	|\}}|
|I dH }|4 I dH  ||dI dH  |t|I dH }W d  I dH  n1 I dH sw   Y  t }W d  I dH  n1 I dH sw   Y  t jj|| j| j||d}W d  I dH  n1 I dH sw   Y  t|| d|_| |st|S )ai  Return the response obtained after sending an asynchronous query via
    DNS-over-QUIC.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.quic()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    zDNS-over-QUIC is not available.Nr   )r   r   Trr   r   )r*   r   r   r   r   r-   null_factoryr   r   r   r   sendr   r   r    r+   r>   r5   r6   r!   r@   r	   )rI   rJ   rK   r   rL   rM   r4   r7   r   r}   rN   r   r|   rB   r   r   r   r   r   r   r"   r   r   rE   r   r   r   r     sR   (
((
r   txn_managerr\   serialc                 C  s  |j d j}|tjjk}|  }| }	|jtj	k}
|
r1t
tjj|}||	dt|I dH  nt
tjj|}tdt|	|	 }|||I dH  tj| |||
}d}d}|st|\}}|du sm|duro||kro|}|
rt|}|d|I dH \}}nt|d|I dH }td|\}t|||I dH }tjj||j|jd|||
 |d}||}|V  |j}|r[|jr|j stj!"d	W d   dS W d   dS 1 sw   Y  dS )
z'Given a socket, does the zone transfer.r   Nrq   Fr;   re   T)r5   r6   xfrorigintsig_ctxmultir4   zmissing TSIG)#questionrdtyper*   	rdatatypeIXFRfrom_wire_originr-   typer   rV   r   rR   DatagramSocketr.   r$   StreamSocketrs   packrg   ri   r   Inboundr   r<   rp   rt   r+   r>   r5   rW   process_messager   had_tsig	exception	FormError)r   r\   r:   r   rK   r"   r   is_ixfrr   rB   is_udpr_   r`   rj   inbounddoner   r]   mexpirationrwireru   rv   rE   r   r   r   _inbound_xfr(  s\   	

"r   lifetimeudp_modec
              	      s  |du rt j|\}}
nt j|}
t j| }t|||}| |f}|	s+t j }	t	|\}}|j
d jt jjkr|tjkr|	|tjd||t|I dH }|4 I dH : zt||||
||2 z3 dH W }qa6 W W d  I dH  dS  t jjy   |tjkr Y nw W d  I dH  n1 I dH sw   Y  |	|tjd||t|I dH }|4 I dH  t||||
||2 z3 dH W }q6 W d  I dH  dS 1 I dH sw   Y  dS )am  Conduct an inbound transfer and apply it via a transaction from the
    txn_manager.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.inbound_xfr()` for the documentation of
    the other parameters, exceptions, and return type of this method.
    Nr   )r*   r   
make_queryextract_serial_from_queryrO   rP   r   rR   rS   r   r   r   r   r   r   NEVERrU   r   rV   r$   r   UseTCPONLYry   )rJ   r   r:   r   rK   r   rL   rM   r   rN   r   r   rZ   r[   r]   r"   r\   r   r   r   inbound_xfr^  sL   


(
.r   )N)
NNFFNr2   FFFN)NrH   Nr   FFFFNNF)NrH   Nr   FFFNNNF)NFNr2   F)NrH   Nr   FFNN)Nrz   Nr   FFNNNNT)
Nrz   Nr   FFTNNT)Nrz   Nr   FFNTNNN)V__doc__r   
contextlibr   r   rs   r    urllib.parser   typingr   r   r   r   r   r   dns.asyncbackendr*   dns.exceptiondns.inetdns.messagedns.namedns.quic	dns.rcodedns.rdataclassdns.rdatatypedns.transactiondns._asyncbackendr   	dns.queryr	   r
   r   r   r   r   r   r   r   r   r   r   r   rO   low_level_address_tuplerQ   r   r$   rR   r   r+   r,   bytesfloatintr1   boolnameNametsigKeyrG   r   Backendr^   r   rc   rk   rp   rw   ra   
SSLContextr   r   	AF_UNSPECr   r   r   r   AsyncQuicConnectiontransactionTransactionManagerSocketr   r   r   r   r   r   r   <module>   sf   8


 	


@	



E	




G


!
	


;
	



F
	


 +	



8
	



D
9
	

