o
    gh                  !   @   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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"rpddl$Z$ej%j&Z'dd Z(dNdd	Z)	dNd
ej*j+deej,j-e.f dede	e/ de
e0e/f f
ddZ1										dOd
ej*j+de	e de	e/ de2de2de	eej3j4ej5j6f  de	e. de2de2de2de	ej,j- defddZ7											dPdej,j-de8d e	e/ d!e0d"e	e8 d#e0de2de2de2de2d
e	ej*j+ d$e	ej*j9 de2dej,j-fd%d&Z:											dQdej,j-de8d e	e/ d!e0d"e	e8 d#e0de2de2de2d'e	ej*j+ d(e	ej*j; d$e	ej*j9 de2de
ej,j-e2f fd)d*Z<	dNd
ej*j;deej,j-e.f de	e/ de
e0e/f fd+d,Z=d-d. Z>					dRd
ej*j;de	e/ de2de	eej3j4ej5j6f  de	e. de2de
ej,j-e/f fd/d0Z?								dSdej,j-de8d e	e/ d!e0d"e	e8 d#e0de2de2d
e	ej*j; d$e	ej*j9 dej,j-fd1d2Z@		3									4dTdej,j-de8d e	e/ d!e0d"e	e8 d#e0de2de2d
e	ej*j; d$e	ej*j9 d5e	e#jA d6e	e8 d7ee2e8f dej,j-fd8d9ZBdd:dddddd;d4d4ddejCfdej,j-de8d e	e/ d!e0d"e	e8 d#e0de2de2d<e	d= d>e8d?e2d7ee2e8f d@e	e8 dAe	dB dCe	e0 dej,j-f dDdEZDddddddejEdfde8dFejFjGde	ej,j- d!e0d e	e/ dGe	e/ d"e	e8 d#e0dHed$e	ej*j9 ddfdIdJZH		3						4		dUdej,j-de8d e	e/ d!e0d"e	e8 d#e0de2de2dKe	ejIjJ d7ee2e8f d$e	ej*j9 d6e	e8 dej,j-fdLdMZIdS )Vz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   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   [/var/www/html/portale_awareness/portale-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   _timeoutJ   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_udpS   s   r-   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.
    r.   T  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_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_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   sD   



0rZ   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)rZ   r&   r'   r;   tcp)rE   rF   rG   r   rH   rI   r/   r0   r3   r[   r\   rJ   r5   responser   r   r   udp_with_fallback   sB   #


r_   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_tcp4  s   rg   c                    sP   d}|dkr&|  |t|I dH }|dkrt|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.
    r.   r   N)recvr    EOFErrorrc   )r!   countr   rX   r,   r   r   r   _read_exactlyM  s   rk   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.
    ra   N!Hr1   r2   r0   r3   )rk   structunpackr   r&   r'   r:   )r!   r   r0   r1   r2   r3   ldatalr>   r@   rA   r   r   r   receive_tcp[  s   rr   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&   rK   rL   r   rN   rO   rQ   r   SOCK_STREAMrg   rr   r1   rS   r   r<   r   )rE   rF   rG   r   rH   rI   r0   r3   r!   rJ   r>   rT   r   rU   r   rV   rW   rX   rA   r@   r   r   r   r]   y  s0   




0r]   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&   rK   rL   r   rN   rO   rQ   r   rt   r    r]   r   )rE   rF   rG   r   rH   rI   r0   r3   r!   rJ   rv   rw   rx   rT   r   rU   r   rV   rW   rX   r^   end_timer   r   r   tls  sN   






0rz   i  z
/dns-queryclientzhttpx.AsyncClientpathpostbootstrap_addressresolverzdns.asyncresolver.Resolverr9   c              
      s  t st|rt|tjstd|  }ztj	|}W n ty(   d}Y nw d}ddi}|durStj
|rS|tjkrFd|||	}n|tjkrRd|||	}n|}tj }|du rcd}d}n|}|}| |dd|||||d	}|r|t|}n	tjdd||d
}|4 I dH F}|
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 sw   Y  |jdk s|jdkrt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http2rx   
local_portr~   r   r9   )r   r   rx   	transport)zcontent-typezcontent-length)headerscontent   =r&   )r   params   i+  z4{} responded with status code {}
Response body: {!r}rm   )(r   r	   r%   httpxAsyncClient
ValueErrorr)   r&   rK   rL   
is_addressr   r   formatr   rN   rO   get_transport_classr   updatestrrc   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   r{   r|   r}   rx   r~   r   r9   r>   r   r   r   urlrJ   r   r   rU   
the_clientr^   twirerA   r   r   r   https  s   




(
r   txn_managerlifetimeudp_modec
           #         s  |du rt j|\}}
nt j|}
|jd j}|t jjk}| }|	 }t j
| }t|||}| |f}t|\}}d}|rud}|rR|tjkrRt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|||
|}d}d}|s:t|\}}|du s|dur||kr|}|rt| |f|}	 t|}|d|I dH \}}t|||drnqnt |d|I dH } t!d| \}!t ||!|I dH }|t jjk}t j"j#||j$|j%d||| |d}"z|&|"}W n t jj'y4   |s$J |tj(kr+ d}d}tj}Y qw |"j)}|r|sK|j$rK|"j*sKt j+,d	W d   n	1 sVw   Y  W d  I dH  n1 I dH slw   Y  |sCdS 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   TFrl   r7   ra   )r1   r2   xfrorigintsig_ctxmultir0   zmissing TSIG)-r&   r   
make_queryextract_serial_from_queryquestionrdtype	rdatatypeIXFRfrom_wire_originr)   rK   rL   r   r   r   NEVERr   rR   rt   rN   rO   rQ   r    r*   rn   packrc   re   InboundrM   r8   r   rk   ro   r'   r:   r1   rS   process_messageUseTCPONLYr   had_tsig	exception	FormError)#rF   r   r6   r   rG   r   rH   rI   r   rJ   serialr   is_ixfrr   r>   r   rV   rW   rY   r   retry	sock_typeis_udprX   rf   inbounddoner   mexpirationr#   rwirer?   rp   rq   rA   r   r   r   inbound_xfrl  s   



) *r   
connectionc                    s  t jjs	tdd| _|  }|rt jj}t jj}|}nt j|
\}}| 4 I dH }|||	|d4 I dH V}|sC|||||}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 s{w   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.r   N)verify_modeserver_nameTrm   g        )r&   quic	have_quicr
   idr)   null_factoryfactories_for_backendconnectr   make_streamsendreceiver   r   r'   r:   r1   r2   r   r<   r   )rE   rF   rG   r   rH   rI   r0   r3   r   rx   rJ   rw   r>   cfactorymfactorythe_connectioncontextthe_managerstartr   streamfinishrA   r   r   r   r     sJ   (
((
r   )N)
NNFFNr.   FFFN)NrD   Nr   FFFFNNF)NrD   Nr   FFFNNNF)NFNr.   F)NrD   Nr   FFNN)Nru   Nr   FFNNNNT)
Nru   Nr   FFNTNN)K__doc__r   
contextlibr   rn   r   typingr   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   rK   low_level_address_tuplerM   r   r    rN   DatagramSocketr'   r(   bytesfloatintr-   boolnameNametsigKeyrC   r   BackendrZ   StreamSocketr_   rg   rk   rr   r]   
SSLContextrz   	AF_UNSPECr   r   transactionTransactionManagerr   r   AsyncQuicConnectionr   r   r   r   <module>   s  0


 	


@	



E	

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

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



I	


x
	

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


