o
    2cE                     @   s2  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	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 ejjZdd Zd ddZd dd	Z		
	
	
d!ddZ		
		d"ddZ		
	
	d#ddZd ddZdd Z	
	
d$ddZ			d%ddZ			d&ddZ ddddddej!dfddZ"dS )'zTalk to a DNS server.    N)_compute_times_matches_destinationBadResponsesslUDPModec                 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   D/var/www/html/gps/gps/lib/python3.10/site-packages/dns/asyncquery.py_source_tuple)   s   

r   c                 C   s"   | r|st   }t| | dS d S )Nr   )timemax)
expirationnowr   r   r   _timeout9   s
   r   c                    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.

    Returns an ``(int, float)`` tuple of bytes sent and the sent time.
    N)
isinstancednsmessageMessageto_wirer   sendtor   )sockwhatdestinationr   	sent_timenr   r   r   send_udpB   s   r!   F    c	                    s`   d}		 |  dt|I dH \}	}
t| j|
||rnqt }tjj|	|||||d}|||
fS )zRead 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, exceptions, and return type of this method.
    r"        N)keyringrequest_macone_rr_per_rrsetignore_trailingraise_on_truncation)recvfromr   r   familyr   r   r   	from_wire)r   r   r   ignore_unexpectedr'   r%   r&   r(   r)   wirefrom_addressreceived_timerr   r   r   receive_udpZ   s    

r2   5   c              
      s  |   }t|\}}d}zetj|}t||f|}|
r |
}n|s'tj }t|||}|	|t
jd|I dH }t||||I dH  t|||||| j| j||		I dH \}}}|| |_| |sct|W |
sq|rr| I dH  S S S |
s|r| I dH  w w w )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_lltupleasyncbackendget_default_backendr   make_socketr   
SOCK_DGRAMr!   r2   r%   macr   is_responser   close)qwheretimeoutr   sourcesource_portr-   r'   r(   r)   r   backendr.   
begin_timer   sr   r   stupler1   r0   _r   r   r   udps   s<   


rH   c                    sp   zt | ||||||||d|	|I dH }|dfW S  tjjy7   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)rH   r   r   	Truncatedtcp)r>   r?   r@   r   rA   rB   r-   r'   r(   udp_socktcp_sockrC   responser   r   r   udp_with_fallback   s   


rN   c                    s\   t |tjjr| }t|}t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.
    !HN)r   r   r   r   r   lenstructpackr   sendallr   )r   r   r   ltcpmsgr   r   r   r   send_tcp   s   	rV   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   EOFErrorrP   )r   countr   rE   r    r   r   r   _read_exactly   s   rZ   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.
       NrO   )r%   r&   r'   r(   )rZ   rQ   unpackr   r   r   r,   )r   r   r'   r%   r&   r(   ldatarT   r.   r0   r1   r   r   r   receive_tcp   s   
r^   c
                    s  |   }
t|\}}d}zf|r| I dH  |}n%tj|}t|||}||f}|	s1tj }	|		|t
jd|||I dH }t||
|I dH  t|||| j| j|I dH \}}|| |_| |sdt|W |sr|rs| I dH  S S S |s|r| I dH  w w w )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   r4   r5   r   r7   r8   r9   r   SOCK_STREAMrV   r^   r%   r;   r   r<   r   r=   )r>   r?   r@   r   rA   rB   r'   r(   r   rC   r.   rD   r   rE   r   rF   dtupler1   r0   r   r   r   rJ      s<   



rJ   U  c                    s  t |\}}|sE|
du rt }
|du rd|
_nd}
d}tj|}t|||}||f}|	s4tj	 }	|	
|tjd||||
|I dH }n|}z-t|}t| |||||||||	
I dH }t }|| |_|W |ss|rt| I dH  S S S |s|r| I dH  w w w )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.
    NFr   )r   r   create_default_contextcheck_hostnamer   r4   r5   r   r7   r8   r9   r   r`   r   rJ   r   r=   )r>   r?   r@   r   rA   rB   r'   r(   r   rC   ssl_contextserver_hostnamerD   r   r   rF   ra   rE   rM   end_timer   r   r   tls/  sB   


rh   c
           #         s  |du rt j|\}}
|jd j}|t jjk}| }| }t j	
| }t|||}| |f}t|\}}d}|rnd}|rK|tjkrKtj}d}ntj}d}|	sWt 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}|s3t|\}}|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&y-   |sJ |tj'kr$ d}d}tj}Y qw |"j(}|r|sD|j#rD|"j)sDt j*+d	W d   n	1 sOw   Y  W d  I dH  n1 I dH sew   Y  |s<d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   TFrO   r$   r[   )r%   r&   xfrorigintsig_ctxmultir'   zmissing TSIG),r   ri   
make_queryquestionrdtype	rdatatypeIXFRfrom_wire_originr   r4   r5   r   r   r   NEVERr   r:   r`   r7   r8   r9   r   r   rQ   rR   rP   rS   Inboundr6   r*   r   rZ   r\   r   r,   r%   r;   process_messageUseTCPONLYrk   had_tsig	exception	FormError)#r?   txn_managerqueryr   r@   lifetimerA   rB   udp_moderC   serialro   is_ixfrrj   r.   r   rF   ra   rG   r   retry	sock_typeis_udprE   rU   inbounddonerk   mexpirationr   rwirer/   r]   rT   r1   r   r   r   inbound_xfr`  s   


# *r   )N)NNFFNr"   FF)
Nr3   Nr   FFFFNN)
Nr3   Nr   FFFNNN)NFNr"   F)Nr3   Nr   FFNN)
Nrb   Nr   FFNNNN)#__doc__r   rQ   r   dns.asyncbackendr   dns.exceptiondns.inetdns.namedns.message	dns.rcodedns.rdataclassdns.rdatatype	dns.queryr   r   r   r   r   r4   low_level_address_tupler6   r   r   r!   r2   rH   rN   rV   rZ   r^   rJ   rh   rs   r   r   r   r   r   <module>   sd   

	

.

$

3
1