U
    Â@Ûfâh  ã                   @   sf  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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# e"ràddl$Z$ej%j&Z'dd„ Z(d6dd	„Z)d7ej*j+eej,j-e.f ee	e/ e
e0e/f d
œdd„Z1d8ej*j+e	e e	e/ e2e2e	eej3j4ej5j6f  e	e. e2e2e2e	ej,j- edœdd„Z7d9ej,j-e8e	e/ e0e	e8 e0e2e2e2e2e	ej*j+ e	ej*j9 e2ej,j-dœdd„Z:d:ej,j-e8e	e/ e0e	e8 e0e2e2e2e	ej*j+ e	ej*j; e	ej*j9 e2e
ej,j-e2f dœdd„Z<d;ej*j;eej,j-e.f e	e/ e
e0e/f dœdd„Z=dd„ Z>d<ej*j;e	e/ e2e	eej3j4ej5j6f  e	e. e2e
ej,j-e/f dœdd „Z?d=ej,j-e8e	e/ e0e	e8 e0e2e2e	ej*j; e	ej*j9 ej,j-d!œd"d#„Z@d>ej,j-e8e	e/ e0e	e8 e0e2e2e	ej*j; e	ej*j9 e	e#jA e	e8 ee2e8f ej,j-d&œd'd(„ZBdd)dddddd*d%d%ddejCfej,j-e8e	e/ e0e	e8 e0e2e2e	d+ e8e2ee2e8f e	e8 e	d, e	e0 ej,j-d-œd.d/„ZDddddddejEdfe8ejFjGe	ej,j- e0e	e/ e	e/ e	e8 e0ee	ej*j9 dd0œd1d2„ZHd?ej,j-e8e	e/ e0e	e8 e0e2e2e	ejIjJ ee2e8f e	ej*j9 e	e8 ej,j-d3œd4d5„ZIdS )@zTalk to a DNS server.é    N)ÚAnyÚDictÚOptionalÚTupleÚUnion)ÚNullContext)
ÚBadResponseÚNoDOHÚNoDOQÚUDPModeÚ_compute_timesÚ_make_dot_ssl_contextÚ_matches_destinationÚ
_remainingÚhave_dohÚsslc                 C   sN   |s|rF|d kr>| t jkr d}n| t jkr0d}ntd| › �ƒ‚||fS d S d S )Nz0.0.0.0z::zunknown address family )ÚsocketÚAF_INETÚAF_INET6ÚNotImplementedError)ÚafÚaddressÚport© r   úH/var/www/html/chatgpt/venv/lib/python3.8/site-packages/dns/asyncquery.pyÚ_source_tuple:   s    

r   c                 C   s*   | d k	r"|st   ¡ }t| | dƒS d S d S )Nr   )ÚtimeÚmax)Ú
expirationÚnowr   r   r   Ú_timeoutJ   s
    r    )ÚsockÚwhatÚdestinationr   Úreturnc                 Ã   s@   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_udpS   s
    r-   Fó    )r!   r#   r   Úignore_unexpectedÚone_rr_per_rrsetÚkeyringÚrequest_macÚignore_trailingÚraise_on_truncationÚignore_errorsÚqueryr$   c              
   Ã   sâ   d}|   dt|ƒ¡I dH \}}t| j|||ƒs0qt ¡ }ztjj||||||d�}W nj tjjk
r  } z*|	rŽ|
dk	rŽ|
 	| ¡ ¡sŽW Y ¢
qn‚ W 5 d}~X Y n  t
k
r¾   |	r¸Y qn‚ Y nX |	rØ|
dk	rØ|
 	|¡sØq|||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.
    r.   éÿÿ  N)r1   r2   r0   r3   r4   )Úrecvfromr    r   Úfamilyr   r&   r'   Ú	from_wireÚ	TruncatedÚis_responseÚ	Exception)r!   r#   r   r/   r0   r1   r2   r3   r4   r5   r6   ÚwireÚfrom_addressÚreceived_timeÚrÚer   r   r   Úreceive_udpq   sF       ÿú
ÿþý
rC   é5   )ÚqÚwhereÚtimeoutr   ÚsourceÚsource_portr/   r0   r3   r4   r!   Úbackendr5   r$   c                 Ã   s  |   ¡ }t|ƒ\}}tj |¡}t||f|ƒ}|
r<t|
ƒ}nJ|sJtj ¡ }t	|||ƒ}| 
¡ rh||f}nd}| |tjd||¡I dH }|4 I dH št}t||||ƒI dH  t|||||| j| j||	|| ƒI dH \}}}|| |_|sð|  |¡sðt‚|W  5 Q I dH R £ S Q I dH R X 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   Zdatagram_connection_requiredÚmake_socketr   Ú
SOCK_DGRAMr-   rC   r1   Úmacr   r<   r   )rE   rF   rG   r   rH   rI   r/   r0   r3   r4   r!   rJ   r5   r>   Ú
begin_timer   r   r#   ÚcmÚstupleÚdtupleÚsrA   r@   Ú_r   r   r   Úudp®   s@    


õ
rY   )rE   rF   rG   r   rH   rI   r/   r0   r3   Úudp_sockÚtcp_sockrJ   r5   r$   c                 Ã   sv   z0t | ||||||||d|	||ƒI dH }|dfW S  tjjk
rp   t| ||||||||
|ƒ
I dH }|df Y S X dS )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)rY   r&   r'   r;   Útcp)rE   rF   rG   r   rH   rI   r/   r0   r3   rZ   r[   rJ   r5   Úresponser   r   r   Úudp_with_fallbackð   s>    #ó

ö
r^   )r!   r"   r   r$   c                 Ã   s\   t |tjjƒr|jdd�}nt|ƒ dd¡| }t ¡ }|  |t	||ƒ¡I dH  t|ƒ|fS )zîSend 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)Zprepend_lengthé   ÚbigN)
r%   r&   r'   r(   r)   ÚlenÚto_bytesr   Úsendallr    )r!   r"   r   Útcpmsgr+   r   r   r   Úsend_tcp4  s    re   c                 Ã   sH   d}|dkrD|   |t|ƒ¡I dH }|dkr.t‚|t|ƒ }|| }q|S )z|Read the specified number of bytes from stream.  Keep trying until we
    either get the desired amount, or we hit EOF.
    r.   r   N)Úrecvr    ÚEOFErrorra   )r!   Úcountr   rW   r,   r   r   r   Ú_read_exactlyM  s    
ri   )r!   r   r0   r1   r2   r3   r$   c                 Ã   sX   t | d|ƒI dH }t d|¡\}t | ||ƒI dH }t ¡ }	tjj|||||d�}
|
|	fS )zçRead 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.
    r_   Nú!H©r1   r2   r0   r3   )ri   ÚstructÚunpackr   r&   r'   r:   )r!   r   r0   r1   r2   r3   ÚldataÚlr>   r@   rA   r   r   r   Úreceive_tcp[  s    ûrp   )rE   rF   rG   r   rH   rI   r0   r3   r!   rJ   r$   c
                 Ã   sø   |   ¡ }
t|ƒ\}}|r0| ¡ I dH  t|ƒ}nJtj |¡}t|||ƒ}||f}|	s^tj 	¡ }	|	 
|tjd|||¡I dH }|4 I dH šb}t||
|ƒI dH  t|||| j| j|ƒI dH \}}|| |_|  |¡sÒt‚|W  5 Q I dH R £ S Q I dH R X 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&   rK   rL   r   rN   rO   rP   r   ÚSOCK_STREAMre   rp   r1   rR   r   r<   r   )rE   rF   rG   r   rH   rI   r0   r3   r!   rJ   r>   rS   r   rT   r   rU   rV   rW   rA   r@   r   r   r   r\   y  s@    

     ÿ
     ÿ

r\   éU  T)rE   rF   rG   r   rH   rI   r0   r3   r!   rJ   Ússl_contextÚserver_hostnameÚverifyr$   c                 Ã   sè   t |ƒ\}}|rt|ƒ}n`|
dkr,t||ƒ}
tj |¡}t|||ƒ}||f}|	sZtj ¡ }	|	 	|t
jd||||
|¡I dH }|4 I dH šR}t|ƒ}t| |||||||||	ƒ
I dH }t ¡ }|| |_|W  5 Q I dH R £ S Q I dH R X 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&   rK   rL   r   rN   rO   rP   r   rr   r    r\   r   )rE   rF   rG   r   rH   rI   r0   r3   r!   rJ   rt   ru   rv   rS   r   rT   r   rU   rV   rW   r]   Úend_timer   r   r   Útls±  sJ    


ø

ö

rx   i»  z
/dns-queryzhttpx.AsyncClientzdns.asyncresolver.Resolver)rE   rF   rG   r   rH   rI   r0   r3   ÚclientÚpathÚpostrv   Úbootstrap_addressÚresolverr9   r$   c              
   Ã   s
  t st‚|r t|tjƒs tdƒ‚|  ¡ }ztj 	|¡}W n tk
rP   d}Y nX d}ddi}|dk	r¦tj 
|¡r¦|tjkrŒd |||	¡}qª|tjkrªd |||	¡}n|}tj ¡ }|dkrÆd}d}n|}|}| ¡ |dd|||||d	�}|røt|ƒ}ntjdd||d
�}|4 I dH š~}|
�rV| dtt|ƒƒdœ¡ | |j|||d�|¡I dH }n:t |¡ d¡}| ¡ }| |j||d|id�|¡I dH }W 5 Q I dH R X |jdk �s¸|jdk�rÎtd ||j|j¡ƒ‚tjj |j| j!| j"||d�}|j# $¡ |_%|  &|¡�st'‚|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.
    z.session parameter must be an httpx.AsyncClientNÚacceptzapplication/dns-messagezhttps://{}:{}{}zhttps://[{}]:{}{}r   T)Úlocal_addressÚhttp1Úhttp2rv   Ú
local_portr|   r}   r9   )r€   r�   rv   Ú	transport)zcontent-typezcontent-length)ÚheadersÚcontentó   =r&   )r„   ÚparamséÈ   i+  z4{} responded with status code {}
Response body: {!r}rk   )(r   r	   r%   ÚhttpxZAsyncClientÚ
ValueErrorr)   r&   rK   rL   Z
is_addressr   r   Úformatr   rN   rO   Zget_transport_classr   ÚupdateÚstrra   Úwait_forr{   Úbase64Úurlsafe_b64encodeÚrstripÚdecodeÚgetÚstatus_coder…   r'   r:   r1   r2   ÚelapsedÚtotal_secondsr   r<   r   )rE   rF   rG   r   rH   rI   r0   r3   ry   rz   r{   rv   r|   r}   r9   r>   r   rƒ   r„   ÚurlrJ   r   r‚   rT   Z
the_clientr]   ZtwirerA   r   r   r   Úhttps÷  sš    



ø
   ÿ
þÿ ÿ ÿ  þÿûr˜   )rF   Útxn_managerr6   r   rG   ÚlifetimerH   rI   Úudp_moderJ   r$   c
           #      Ã   sÎ  |dkrt j |¡\}}
nt j |¡}
|jd j}|t jjk}| ¡ }| 	¡ }t j
 | ¡}t|||ƒ}| |f}t|ƒ\}}d}|�rÊd}|r¢|tjkr¢tj}d}n
tj}d}|	sºt j ¡ }	|	 ||d||t|ƒ¡I dH }|4 I dH �šÖ |�r| ||t|ƒ¡I dH  n&t dt|ƒ¡| }| ||¡I dH  t j |||
|¡��p}d}d}|�sŒt|ƒ\}}|dk�s||dk	�r€||k�r€|}|�rÌt| |f|ƒ}t|ƒ}| d|¡I dH \}}t|||dƒ�r”�qþ�q”n2t |d|ƒI dH } t !d| ¡\}!t ||!|ƒI dH }|t jjk}t j"j#||j$|j%d||| |d�}"z| &|"¡}W nF t jj'k
�r€   |�sZt(‚|tj)k�rh‚ d}d}tj}Y �qLY nX |"j*}�qL|�s®|j$�r®|"j+�s®t j, -d	¡‚W 5 Q R X W 5 Q I dH R X q~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   TFrj   r7   r_   )r1   r2   ÚxfrÚoriginÚtsig_ctxÚmultir0   zmissing TSIG).r&   rœ   Z
make_queryZextract_serial_from_queryÚquestionÚrdtypeZ	rdatatypeZIXFRZfrom_wire_originr)   rK   rL   r   r   r   ÚNEVERr   rQ   rr   rN   rO   rP   r    r*   rl   Úpackra   rc   ZInboundrM   r8   r   ri   rm   r'   r:   r1   rR   Zprocess_messageZUseTCPÚAssertionErrorZONLYrž   Zhad_tsigÚ	exceptionZ	FormError)#rF   r™   r6   r   rG   rš   rH   rI   r›   rJ   Úserialr¡   Zis_ixfrr�   r>   r   rU   rV   rX   r   ÚretryZ	sock_typeZis_udprW   rd   ZinboundÚdonerž   Zmexpirationr#   Zrwirer?   rn   ro   rA   r   r   r   Úinbound_xfrl  s¦    
     ÿ

ÿÿ   ÿ
ø


r©   )rE   rF   rG   r   rH   rI   r0   r3   Ú
connectionrv   rJ   ru   r$   c                 Ã   sJ  t jjstdƒ‚d| _|  ¡ }|r8t jj}t jj}|}nt j |
¡\}}|ƒ 4 I dH šÄ}|||	|d�4 I dH š‚}|s„| ||||¡}t	|ƒ\}}| 
|¡I dH }|4 I dH š, | |d¡I dH  | t|ƒ¡I dH }W 5 Q I dH R X t ¡ }W 5 Q I dH R X t jj|| j| j||d�}W 5 Q I dH R X t|| dƒ|_|  |¡�sFt‚|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.r   N)Úverify_modeZserver_nameTrk   g        )r&   ÚquicZ	have_quicr
   Úidr)   Znull_factoryZfactories_for_backendÚconnectr   Zmake_streamÚsendZreceiver   r   r'   r:   r1   r2   r   r<   r   )rE   rF   rG   r   rH   rI   r0   r3   rª   rv   rJ   ru   r>   ZcfactoryZmfactoryZthe_connectionÚcontextZthe_managerÚstartr   ÚstreamÚfinishrA   r   r   r   r¬   Ñ  sF      ÿ$ûr¬   )N)N)
NNFFNr.   FFFN)NrD   Nr   FFFFNNF)NrD   Nr   FFFNNNF)N)NFNr.   F)NrD   Nr   FFNN)Nrs   Nr   FFNNNNT)
Nrs   Nr   FFNTNN)KÚ__doc__r�   Ú
contextlibr   rl   r   Útypingr   r   r   r   r   Zdns.asyncbackendr&   Zdns.exceptionZdns.inetZdns.messageZdns.nameZdns.quicZ	dns.rcodeZdns.rdataclassZdns.rdatatypeZdns.transactionZdns._asyncbackendr   Z	dns.queryr   r	   r
   r   r   r   r   r   r   r   r‰   rK   Zlow_level_address_tuplerM   r   r    rN   ZDatagramSocketr'   r(   ÚbytesÚfloatÚintr-   ÚboolÚnameÚNameZtsigÚKeyrC   r�   ÚBackendrY   ZStreamSocketr^   re   ri   rp   r\   Ú
SSLContextrx   Ú	AF_UNSPECr˜   r¢   ZtransactionZTransactionManagerr©   r¬   ZAsyncQuicConnectionr   r   r   r   Ú<module>   s   0
 ü
û           õ
ô@           ó

òE           ó


òG ý
ü     úù!        ö

õ;           ó


òIñ
ðxö

õh          ô


ó