
    L}bg0              !          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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ZddlZddlZd Zd Z ej!        "                    d          Z#e#rBddl$Z%ddl&Z&e%j'        Z(e%j)        j*        j+        Z, G d de(          Z- G d	 d
e&j.                  Z/n G d d
          Z/e#Z0	 ddl1Z1n# e2$ r  G d d          Z1Y nw xY wej        Z3 G d dej4        j5                  Z6 G d dej4        j7                  Z8 G d dej4        j5                  Z9 G d dej4        j5                  Z:ej;        j<        Z<d Z=d Z>d Z? e@ed          rejA        aBnejC        aBd ZDd ZEd ZFd ZG	 dgdZHdhd ZIdd!ddd"d"dd#ddddejJ        fd$ejK        jL        d%eMd&eeN         d'eOd(eeM         d)eOd*ePd+ePd,ee         d-eMd.ePd/eeM         d0eePeMf         d1ed2         d3eeO         d4ejK        jL        f d5ZQd6 ZRd7 ZS	 did8ed9eejK        jL        eTf         d:ed;eeN         d4eeOeNf         f
d<ZU	 	 	 	 	 	 	 	 	 	 djd8ed:ee         d;eeN         d>ePd*ePd?eeejV        jW        ejX        jY        f                  d@eeT         d+ePdAePdBePdCeejK        jL                 d4efdDZZ	 	 	 	 	 	 	 	 	 	 dkd$ejK        jL        d%eMd&eeN         d'eOd(eeM         d)eOd>ePd*ePd+ePdAePd8ee         dBePd4ejK        jL        fdFZ[	 	 	 	 	 	 	 	 	 	 dld$ejK        jL        d%eMd&eeN         d'eOd(eeM         d)eOd>ePd*ePd+ePdGee         dHee         dBePd4eejK        jL        ePf         fdIZ\dJ Z]dK Z^	 did8ed9eejK        jL        eTf         d;eeN         d4eeOeNf         fdLZ_	 	 	 	 	 dmd8ed;eeN         d*ePd?eeejV        jW        ejX        jY        f                  d@eeT         d+ePd4eejK        jL        eNf         fdMZ`dN Za	 	 	 	 	 	 	 dnd$ejK        jL        d%eMd&eeN         d'eOd(eeM         d)eOd*ePd+ePd8ee         d4ejK        jL        fdOZbdP ZcdQeeM         d0eePeMf         d4e1jd        fdRZe	 	 	 	 	 	 	 	 	 	 dod$ejK        jL        d%eMd&eeN         d'eOd(eeM         d)eOd*ePd+ePd8ee1jf                 dTee1jd                 dQeeM         d0eePeMf         d4ejK        jL        fdUZg	 	 	 	 	 	 	 	 	 dpd$ejK        jL        d%eMd&eeN         d'eOd(eeM         d)eOd*ePd+ePdVeejh        ji                 d0eePeMf         dQeeM         d4ejK        jL        fdWZhejj        jk        ejl        jm        ddEdddddddd"ejX        jn        fd%eMdXeejV        jW        eMf         dYeejj        jo        eMf         dZeejl        jp        eMf         d&eeN         d'eOd?eeejV        jW        ejX        jY        f                  d[eeejV        jW        eMf                  d\ePd]eeN         d(eeM         d)eOd^eOd_ePd`eejV        jW        eMf         d4ef daZ; G db dcejq                  ZrddEdddderjs        fd%eMddejt        ju        dCeejK        jL                 d'eOd&eeN         d]eeN         d(eeM         d)eOdeerd4dfdfZvdS )qzTalk to a DNS server.    N)AnyDictOptionalTupleUnionc                 h    | d S | t          j                     z
  }|dk    rt          j        j        |S )N        )timedns	exceptionTimeout)
expirationtimeouts     \/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/dns/query.py
_remainingr   /   s6    t49;;&G#~~m##N    c                 R    |d S t          t          j                    | z   |          S N)minr
   )r   r   s     r   _expiration_for_this_attemptr   8   s(    tty{{W$j111r   dohc                   2     e Zd Z fdZ	 ddZ	 ddZ xZS )_NetworkBackendc                     t                                                       || _        || _        || _        || _        d S r   )super__init___local_port	_resolver_bootstrap_address_family)selfresolver
local_portbootstrap_addressfamily	__class__s        r   r   z_NetworkBackend.__init__G   s;    GG)D%DN&7D#!DLLLr   Nc                 p   g }t          |          \  }}t          j                            |          r|                    |           n| j        |                    | j                   nht          |          }| j        }	|rt          j                            |          }	| j	        
                    ||	|          }
|
                                }|D ]}t          j                            |          }|| j        dk    r(t          j                            || j        f|          }nd }t          |t          j        |          }t#          d|          }	 t%          |t          j                            ||f|          |           t'          |          c S # t(          $ r Y w xY wt*          j        )N)r%   lifetimer   g       @)_compute_timesr   inet
is_addressappendr   r   r    af_for_addressr   resolve_name	addressesr   low_level_address_tuple_make_socketsocketSOCK_STREAMr   _connect_CoreSyncStream	ExceptionhttpcoreConnectError)r!   hostportr   local_addresssocket_optionsr/   _r   r%   answersaddressafsourcesockattempt_expirations                   r   connect_tcpz_NetworkBackend.connect_tcpN   s    I*733MAzx""4(( 0  &&&&(4  !89999$Z00  D X44]CCF.55' 6   $--//	$  X,,W55 ,0@A0E0E X==&(892 FF "F#B(:FCC%A#z%R%R"88'4"MM*  
 +400000    D''s   ?F
F)(F)c                     t           r   NotImplementedError)r!   pathr   r<   s       r   connect_unix_socketz#_NetworkBackend.connect_unix_socketu   s
     &%r   r   )__name__
__module____qualname__r   rD   rI   __classcell__r&   s   @r   r   r   F   sm        	" 	" 	" 	" 	" FJ%	( %	( %	( %	(P 15	& 	& 	& 	& 	& 	& 	& 	&r   r   c                   4     e Zd Zdddej        d fd
Z xZS )_HTTPTransportr   N)r#   r$   r"   r%   c                    |dd l }|j                                        } t                      j        |i | t          ||||          | j        _        d S Nr   )dns.resolverr"   Resolverr   r   r   _pool_network_backend)	r!   r#   r$   r"   r%   argskwargsr   r&   s	           r   r   z_HTTPTransport.__init__{   sj     ####<0022EGGd-f---*9*&7+ +DJ'''r   )rJ   rK   rL   r2   	AF_UNSPECr   rM   rN   s   @r   rP   rP   z   sS         "#	 	 	 	 	 	 	 	 	 	 	r   rP   c                       e Zd Zd ZdS )rP   c                     t           r   rF   )r!   r9   r:   r   r;   s        r   rD   z_HTTPTransport.connect_tcp   s    %%r   N)rJ   rK   rL   rD    r   r   rP   rP      s#        	& 	& 	& 	& 	&r   c                       e Zd ZdZ G d de          Z G d de          Z G d d          Z G d d	          Ze	d
             Z
dS )sslr   c                       e Zd ZdS )ssl.WantReadExceptionNrJ   rK   rL   r\   r   r   WantReadExceptionr`              Dr   rb   c                       e Zd ZdS )ssl.WantWriteExceptionNra   r\   r   r   WantWriteExceptionre      rc   r   rf   c                       e Zd ZdS )ssl.SSLContextNra   r\   r   r   
SSLContextrh      rc   r   ri   c                       e Zd ZdS )ssl.SSLSocketNra   r\   r   r   	SSLSocketrk      rc   r   rl   c                      t          d          )Nzno ssl support)r6   )clsrW   rX   s      r   create_default_contextzssl.create_default_context   s    ,---r   N)rJ   rK   rL   	CERT_NONEr6   rb   rf   ri   rl   classmethodro   r\   r   r   r^   r^      s        		 	 	 	 		 	 	 		 	 	 	 	 	 	 		 	 	 	 	 	 	 		 	 	 	 	 	 	 	 
	. 	. 
	. 	. 	.r   r^   c                       e Zd ZdZdS )UnexpectedSourcez=A DNS query response came from an unexpected address or port.NrJ   rK   rL   __doc__r\   r   r   rs   rs      s        GGGGr   rs   c                       e Zd ZdZdS )BadResponsez<A DNS query response does not respond to the question asked.Nrt   r\   r   r   rw   rw      s        FFFFr   rw   c                       e Zd ZdZdS )NoDOHzMDNS over HTTPS (DOH) was requested but the httpx module is not
    available.Nrt   r\   r   r   ry   ry                 r   ry   c                       e Zd ZdZdS )NoDOQzNDNS over QUIC (DOQ) was requested but the aioquic module is not
    available.Nrt   r\   r   r   r|   r|      rz   r   r|   c                 B    t          j                     }| |d fS ||| z   fS r   )r
   )r   nows     r   r)   r)      s+    
)++CT{S7]##r   c                    |r4t          | t          j                  r|                                 dk    rdS t	                      }d}|r|t
          j        z  }|r|t
          j        z  }|r|                    | |           |d }n-|t          j	                    z
  }|dk    rt          j        j        |                    |          st          j        j        d S )Nr   Tr	   )
isinstancer^   rl   pending_selector_class	selectors
EVENT_READEVENT_WRITEregisterr
   r   r   r   select)fdreadablewritabler=   r   seleventsr   s           r   	_wait_forr      s      Jr3=11 bjjllQ6F6Ft


CF ')&& ()'' !R   ty{{*c>>-''::g $m##$ $r   c                 
    | a d S r   )r   )selector_classs    r   _set_selector_classr      s    
 %OOOr   PollSelectorc                 ,    t          | ddd|           d S )NTFr   sr   s     r   _wait_for_readabler     s    audJ/////r   c                 ,    t          | ddd|           d S )NFTr   r   s     r   _wait_for_writabler     s    adJ/////r   c                    	 t           j                            | |d                   }t           j                            | |d                   }n# t           j        j        $ r Y dS w xY w||k    o|dd          |dd          k    S )Nr   F   )r   r*   	inet_ptonr   SyntaxError)r@   a1a2n1n2s        r   _addresses_equalr   
  s    XBqE**XBqE**=$   uu8(122"QRR&((s   AA A'&A'c                     |sdS t          | ||          s;t          j                            |d                   r|dd          |dd          k    rdS |rdS t	          d| d|           )NTr   r   Fzgot a response from z instead of )r   r   r*   is_multicastrs   )r@   from_addressdestinationignore_unexpecteds       r   _matches_destinationr     s      tL+66 k!n--2>qrr2BkRSRTRTo2U2Ut	 u
J|JJ[JJ  r   Tc                 
   d }d }	 t           j                            |           }| }n# t          $ r |r Y nw xY w|r9t           j                            |          }|r||k    rt	          d          n|}|r@|s>	 t           j                            |          }n# t          $ r t	          d          w xY w|r"t           j                            ||f|          }|r"t           j                            ||f|          }|||fS )Nz5different address families for source and destinationz3source_port specified but address family is unknown)r   r*   r-   r6   
ValueError
any_for_afr0   )wherer:   rA   source_portwhere_must_be_addressr@   r   safs           r   _destination_and_sourcer   &  se   
 
BKX$$U++     		 	  h%%f-- 		byy K    B T6 T	TX((,,FF 	T 	T 	TRSSS	T
  Ph66T7JBOO M116;2GLLV$$s   !( 88;B B5c                     t          | |          }	 |                    d           ||                    |           |r|                    |d|          S |S # t          $ r |                                  w xY w)NF)do_handshake_on_connectserver_hostname)socket_factorysetblockingbindwrap_socketr6   close)r@   typerA   ssl_contextr   r   s         r   r1   r1   R  s    r4  A	eFF6NNN 	**(- / +    H   				s   AA A  A:i  Fz
/dns-queryqr   r   r:   rA   r   one_rr_per_rrsetignore_trailingsessionrH   postr$   verifyr"   zdns.resolver.Resolverr%   returnc           
      X   t           st          |r)t          |t          j                  st          d          |                                 }t          ||||d          \  }}}d}ddi}|ot          j	        
                    |          rP|t          j        k    rd                    |||	          }n*|t          j        k    rd                    |||	          }n|}|d}d}n|d         }|d	         }t          |d
d
|||||          }|rt!          j        |          }nt          j        d
d
||          }|5 }|
rL|                    dt'          t)          |                    d           |                    ||||          }nVt-          j        |                              d          }|                                }|                    |||d|i          }ddd           n# 1 swxY w Y   |j        dk     s|j        dk    r.t          d                    ||j        |j                            t          j                            |j        | j        | j         ||          }|j!        "                                |_#        | $                    |          stJ          |S )a  Return the response obtained after sending a query via DNS-over-HTTPS.

    *q*, a ``dns.message.Message``, the query to send.

    *where*, a ``str``, the nameserver IP address or the full URL. If an IP address is
    given, the URL will be constructed using the following schema:
    https://<IP-address>:<port>/<path>.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the query
    times out. If ``None``, the default, wait forever.

    *port*, a ``int``, the port to send the query to. The default is 443.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying the source
    address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message. The default is
    0.

    *one_rr_per_rrset*, a ``bool``. If ``True``, put each RR into its own RRset.

    *ignore_trailing*, a ``bool``. If ``True``, ignore trailing junk at end of the
    received message.

    *session*, an ``httpx.Client``.  If provided, the client session to use to send the
    queries.

    *path*, a ``str``. If *where* is an IP address, then *path* will be used to
    construct the URL to send the DNS query to.

    *post*, a ``bool``. If ``True``, the default, POST method will be used.

    *bootstrap_address*, a ``str``, the IP address to use to bypass resolution.

    *verify*, a ``bool`` or ``str``.  If a ``True``, then TLS certificate verification
    of the server is done using the default CA bundle; if ``False``, then no
    verification is done; if a `str` then it specifies the path to a certificate file or
    directory which will be used for verification.

    *resolver*, a ``dns.resolver.Resolver`` or ``None``, the resolver to use for
    resolution of hostnames in URLs.  If not specified, a new resolver with a default
    configuration will be used; note this is *not* the default resolver as that resolver
    might have been configured to use DoH causing a chicken-and-egg problem.  This
    parameter only has an effect if the HTTP library is httpx.

    *family*, an ``int``, the address family.  If socket.AF_UNSPEC (the default), both A
    and AAAA records will be retrieved.

    Returns a ``dns.message.Message``.
    z)session parameter must be an httpx.ClientFNacceptzapplication/dns-messagezhttps://{}:{}{}zhttps://[{}]:{}{}r   r   T)r;   http1http2r   r#   r$   r"   r%   )r   r   r   	transport)zcontent-typezcontent-length)headerscontentr      =r   )r   r   params   i+  z2{} responded with status code {}
Response body: {}keyringrequest_macr   r   )&have_dohry   r   httpxClientr   to_wirer   r   r*   r+   r2   AF_INETformatAF_INET6rP   
contextlibnullcontextupdatestrlenr   base64urlsafe_b64encoderstripdecodegetstatus_coder   message	from_wirer   r   elapsedtotal_secondsr
   is_responserw   )r   r   r   r:   rA   r   r   r   r   rH   r   r$   r   r"   r%   wirer@   r=   
the_sourcer   r   urlr;   r#   cmresponsetwirers                               r   httpsr   f  s&   H   Fz'5<88 FDEEE99;;D1tV[% RJ I23G	~#(--e44~#**5$==CC6?""%,,UD$??C 

"1]
#+	 	 	I  V0:0Fw0O0O\D9UUU	 w  	NN$=&)#d))nn    ||C$PW|XXHH+D1188>>DKKMME{{Wguen #  H              ( c!!X%9C%?%?""(&0DhFV"W"W
 
 	
 		M)' 	 	 	A ++--AF== Hs   =B%G..G25G2c                 r    	 	 |                      |          S # t          $ r t          | |           Y nw xY w7)zReads a datagram from the socket.
    A Timeout exception will be raised if the operation is not completed
    by the expiration time.
    )recvfromBlockingIOErrorr   )rB   max_sizer   s      r   	_udp_recvr     sT    
1	1==*** 	1 	1 	1tZ00000	11s    55c                     	 	 |r|                      ||          S |                     |          S # t          $ r t          | |           Y nw xY wO)zSends the specified datagram to destination over the socket.
    A Timeout exception will be raised if the operation is not completed
    by the expiration time.
    )sendtosendr   r   )rB   datar   r   s       r   	_udp_sendr     sn    
1	1 '{{4555yy& 	1 	1 	1tZ00000	11s   0 0 AArB   whatr   r   c                     t          |t          j        j                  r|                                }t          j                    }t          | |||          }||fS )a  Send a DNS message to the specified UDP socket.

    *sock*, a ``socket``.

    *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.
    )r   r   r   Messager   r
   r   )rB   r   r   r   	sent_timens         r   send_udpr     sP    , $+,, ||~~	I$k:66Ay>r   r   r   r   r   raise_on_truncationignore_errorsqueryc                    d}	 t          | d|          \  }}t          | j        |||          s-t          j                    }	 t          j                            ||||||          }n[# t          j        j        $ r6}|	r.|
,|
                    |                                          sY d}~ d}~wt          $ r |	rY  w xY w|	r|
|
                    |          s|r||fS |||fS )a  Read a DNS message from a UDP socket.

    *sock*, a ``socket``.

    *destination*, a destination tuple appropriate for the address family
    of the socket, specifying where the message is expected to arrive from.
    When receiving a response, this would be where the associated query was
    sent.

    *expiration*, a ``float`` or ``None``, the absolute time at which
    a timeout exception should be raised.  If ``None``, no timeout will
    occur.

    *ignore_unexpected*, a ``bool``.  If ``True``, ignore responses from
    unexpected sources.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own
    RRset.

    *keyring*, a ``dict``, the keyring to use for TSIG.

    *request_mac*, a ``bytes`` or ``None``, the MAC of the request (for TSIG).

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing
    junk at end of the received message.

    *raise_on_truncation*, a ``bool``.  If ``True``, raise an exception if
    the TC bit is set.

    Raises if the message is malformed, if network errors occur, of if
    there is a timeout.

    If *destination* is not ``None``, returns a ``(dns.message.Message, float)``
    tuple of the received message and the received time.

    If *destination* is ``None``, returns a
    ``(dns.message.Message, float, tuple)``
    tuple of the received message, the received time, and the address where
    the message arrived from.

    *ignore_errors*, a ``bool``.  If various format errors or response
    mismatches occur, ignore them and keep listening for a valid response.
    The default is ``False``.

    *query*, a ``dns.message.Message`` or ``None``.  If not ``None`` and
    *ignore_errors* is ``True``, check that the received message is a response
    to this query, and if not keep listening for a valid response.
    r   T  )r   r   r   r   r   N)
r   r   r%   r
   r   r   r   	Truncatedr   r6   )rB   r   r   r   r   r   r   r   r   r   r   r   r   received_timer   es                   r   receive_udpr  2  sS   | D(4(ujAA|#K{4E
 
 	 		%%'!1 /$7 &  AA {$ 	 	 	 %))!))++66 &  	 	 	 		
  	U.u7H7H7K7K. 	4}%%}l33s$   %A* *C>+B/.B//C C5   c                    |                                  }t          ||||          \  }}}t          |          \  }}|
rt          j        |
          }nt          |t          j        |          }|5 }t          ||||           t          |||||| j
        | j        ||	||           \  }}||z
  |_        |s|                     |          st          |cddd           S # 1 swxY w Y   	 J )a  Return the response obtained after sending a query via UDP.

    *q*, a ``dns.message.Message``, the query to send

    *where*, a ``str`` containing an IPv4 or IPv6 address,  where
    to send the message.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the
    query times out.  If ``None``, the default, wait forever.

    *port*, an ``int``, the port send the message to.  The default is 53.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
    the source address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message.
    The default is 0.

    *ignore_unexpected*, a ``bool``.  If ``True``, ignore responses from
    unexpected sources.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own
    RRset.

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing
    junk at end of the received message.

    *raise_on_truncation*, a ``bool``.  If ``True``, raise an exception if
    the TC bit is set.

    *sock*, a ``socket.socket``, 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 nonblocking datagram socket,
    and the *source* and *source_port* are ignored.

    *ignore_errors*, a ``bool``.  If various format errors or response
    mismatches occur, ignore them and keep listening for a valid response.
    The default is ``False``.

    Returns a ``dns.message.Message``.
    N)r   r   r)   r   r   r1   r2   
SOCK_DGRAMr   r  r   macr
   r   rw   )r   r   r   r:   rA   r   r   r   r   r   rB   r   r   r@   r   
begin_timer   r   r   r   r  s                        r   udpr    s^   p 99;;D 7tV[! !Rf  .g66Z 90:0Ft0L0L"f/88	 qD+z222(IE
 
M +  	q!1!1 	)               , 	s   1A"C  C$'C$udp_socktcp_sockc                     	 t          | ||||||||d|	|          }|dfS # t          j        j        $ r t	          | ||||||||
	  	        }|dfcY S w xY w)a|  Return the response to the query, trying UDP first and falling back
    to TCP if UDP results in a truncated response.

    *q*, a ``dns.message.Message``, the query to send

    *where*, a ``str`` containing an IPv4 or IPv6 address,  where to send the message.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the query
    times out.  If ``None``, the default, wait forever.

    *port*, an ``int``, the port send the message to.  The default is 53.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying the source
    address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message. The default is
    0.

    *ignore_unexpected*, a ``bool``.  If ``True``, ignore responses from unexpected
    sources.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own RRset.

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing junk at end of the
    received message.

    *udp_sock*, a ``socket.socket``, 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,
    it must be a nonblocking datagram socket, and the *source* and *source_port* are
    ignored for the UDP query.

    *tcp_sock*, a ``socket.socket``, or ``None``, the connected socket to use for the
    TCP query.  If ``None``, the default, a socket is created.  Note that if a socket is
    provided, it must be a nonblocking connected stream socket, and *where*, *source*
    and *source_port* are ignored for the TCP query.

    *ignore_errors*, a ``bool``.  If various format errors or response mismatches occur
    while listening for UDP, ignore them and keep listening for a valid response. The
    default is ``False``.

    Returns a (``dns.message.Message``, tcp) tuple where tcp is ``True`` if and only if
    TCP was used.
    TF)r  r   r   r  tcp)r   r   r   r:   rA   r   r   r   r   r  r  r   r   s                r   udp_with_fallbackr    s    r 
 
 %  ;       

 

 $ s     /AAc                 0   d}|dk    r	 |                      |          }|dk    rt          |t          |          z  }||z  }nL# t          t          j        f$ r t          | |           Y n$t          j        $ r t          | |           Y nw xY w|dk    |S )zRead the specified number of bytes from sock.  Keep trying until we
    either get the desired amount, or we hit EOF.
    A Timeout exception will be raised if the operation is not completed
    by the expiration time.
    r   r   )	recvEOFErrorr   r   r^   SSLWantReadErrorr   SSLWantWriteErrorr   )rB   countr   r   r   s        r   	_net_readr  O  s     	A
!))		1		%  ACxxSVVOEFAA!56 	1 	1 	1tZ00000$ 	1 	1 	1tZ00000	1 !)) Hs   9A &B,BBc                     d}t          |          }||k     rv	 ||                     ||d                   z  }nL# t          t          j        f$ r t          | |           Y n$t          j        $ r t          | |           Y nw xY w||k     tdS dS )zWrite the specified data to the socket.
    A Timeout exception will be raised if the operation is not completed
    by the expiration time.
    r   N)r   r   r   r^   r  r   r  r   )rB   r   r   currentls        r   
_net_writer  d  s    
 GD		A
A++	1tyyghh000GG!67 	1 	1 	1tZ00000# 	1 	1 	1tZ00000	1 A++++++s    : &B"BBc                 $   t          |t          j        j                  r|                    d          }n&t          |                              dd          |z   }t          j                    }t          | ||           t          |          |fS )a{  Send a DNS message to the specified TCP socket.

    *sock*, a ``socket``.

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

    *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.
    T)prepend_length   big)	r   r   r   r   r   r   to_bytesr
   r  )rB   r   r   tcpmsgr   s        r   send_tcpr"  t  s    $ $+,, 5T22
 T##Au--4	ItVZ(((KK##r   c                     t          | d|          }t          j        d|          \  }t          | ||          }t          j                    }	t          j                            |||||          }
|
|	fS )a  Read a DNS message from a TCP socket.

    *sock*, a ``socket``.

    *expiration*, a ``float`` or ``None``, the absolute time at which
    a timeout exception should be raised.  If ``None``, no timeout will
    occur.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own
    RRset.

    *keyring*, a ``dict``, the keyring to use for TSIG.

    *request_mac*, a ``bytes`` or ``None``, the MAC of the request (for TSIG).

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing
    junk at end of the received message.

    Raises if the message is malformed, if network errors occur, of if
    there is a timeout.

    Returns a ``(dns.message.Message, float)`` tuple of the received message
    and the received time.
    r  !Hr   )r  structunpackr
   r   r   r   )rB   r   r   r   r   r   ldatar  r   r  r   s              r   receive_tcpr(    s}    B dAz**E=u%%DQT1j))DIKKM)' 	 	 	A }r   c                 N   |                      |          }|dk    rd S |t          j        t          j        t          j        fv r:t          | |           |                     t          j        t          j	                  }|dk    r"t          |t          j        |                    d S rR   )
connect_exerrnoEINPROGRESSEWOULDBLOCKEALREADYr   
getsockoptr2   
SOL_SOCKETSO_ERROROSErrorosstrerror)r   r?   r   errs       r   r4   r4     s    
,,w

C
axx
u %"3U^DDD1j)))ll6,fo>>
axxc2;s++,,, xr   c	           	         |                                  }	t          |          \  }
}|rt          j        |          }n1t	          ||||          \  }}}t          |t          j        |          }|5 }|st          |||           t          ||	|           t          |||| j        | j        |          \  }}||
z
  |_        |                     |          st          |cddd           S # 1 swxY w Y   	 J )a  Return the response obtained after sending a query via TCP.

    *q*, a ``dns.message.Message``, the query to send

    *where*, a ``str`` containing an IPv4 or IPv6 address, where
    to send the message.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the
    query times out.  If ``None``, the default, wait forever.

    *port*, an ``int``, the port send the message to.  The default is 53.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
    the source address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message.
    The default is 0.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own
    RRset.

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing
    junk at end of the received message.

    *sock*, a ``socket.socket``, or ``None``, the connected 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 nonblocking connected stream
    socket, and *where*, *port*, *source* and *source_port* are ignored.

    Returns a ``dns.message.Message``.
    N)r   r)   r   r   r   r1   r2   r3   r4   r"  r(  r   r	  r
   r   rw   )r   r   r   r:   rA   r   r   r   rB   r   r
  r   r   r@   r   r   r   r  s                     r   r  r    sZ   V 99;;D-g66Z :0:0Ft0L0L$;4%
 %
![& "f0&99	 
q 	1QZ000D*%%%(z+QY
 
M +}}Q 	
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 	s   1A-C++C/2C/c                     	 	 |                                   d S # t          j        $ r t          | |           Y n$t          j        $ r t          | |           Y nw xY w]r   )do_handshaker^   r  r   r  r   r   s     r   _tls_handshaker9    s    .	.NNF# 	. 	. 	.q*-----$ 	. 	. 	.q*-----	..s    AAAr   c                    d }d }t          |t                    rSt          j                            |          r|}n1t          j                            |          r|}nt          d          t          j        ||          }t          j	        j
        |_        | d|_        |                    dg           |du rt          j        |_        |S )Nzinvalid verify string)cafilecapathFdot)r   r   r3  rH   isfileisdirr   r^   ro   
TLSVersionTLSv1_2minimum_versioncheck_hostnameset_alpn_protocolsrp   verify_mode)r   r   r;  r<  r   s        r   _make_dot_ssl_contextrF    s     !F F&# 67>>&!! 	6FFW]]6"" 	6FF4555,F6JJJK"%."8K%*"""E7+++"%-r   U  r   c                 <   |rt          | ||||||||	  	        S |                                 }t          |          \  }}t          ||||          \  }}}|	|st	          |
|          }	t          |t          j        ||	|
          5 }t          |||           t          ||           t          |||           t          |||| j        | j        |          \  }}||z
  |_        |                     |          st           |cddd           S # 1 swxY w Y   	 J )ak  Return the response obtained after sending a query via TLS.

    *q*, a ``dns.message.Message``, the query to send

    *where*, a ``str`` containing an IPv4 or IPv6 address,  where
    to send the message.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the
    query times out.  If ``None``, the default, wait forever.

    *port*, an ``int``, the port send the message to.  The default is 853.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
    the source address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message.
    The default is 0.

    *one_rr_per_rrset*, a ``bool``.  If ``True``, put each RR into its own
    RRset.

    *ignore_trailing*, a ``bool``.  If ``True``, ignore trailing
    junk at end of the received message.

    *sock*, an ``ssl.SSLSocket``, 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 nonblocking connected
    SSL stream socket, and *where*, *port*, *source*, *source_port*,
    and *ssl_context* are ignored.

    *ssl_context*, an ``ssl.SSLContext``, the context to use when establishing
    a TLS connection. If ``None``, the default, creates one with the default
    configuration.

    *server_hostname*, a ``str`` containing the server's hostname.  The
    default is ``None``, which means that no hostname is known, and if an
    SSL context is created, hostname checking will be disabled.

    *verify*, a ``bool`` or ``str``.  If a ``True``, then TLS certificate verification
    of the server is done using the default CA bundle; if ``False``, then no
    verification is done; if a `str` then it specifies the path to a certificate file or
    directory which will be used for verification.

    Returns a ``dns.message.Message``.

    N)r   r   )r  r   r)   r   rF  r1   r2   r3   r4   r9  r"  r(  r   r	  r
   r   rw   )r   r   r   r:   rA   r   r   r   rB   r   r   r   r   r
  r   r@   r   r   r   r  s                       r   tlsrI  1  s   z  
 

 

 
	
 99;;D-g66Z 7tV[! !Rf 4+OVDD	
'
 
 
  
K,,,q*%%%D*%%%(z+QY
 
M +}}Q 	!               $ 	s   A;DDD
connectionc                 4   t           j        j        st          d          d| _        |                                 }|rt          j        d          }|}n#t           j                            |	|
          }|}|5  |s|	                    ||||          }t          |          \  }}|                    |          5 }|                    |d           |                    t          |                    }ddd           n# 1 swxY w Y   t          j                    }ddd           n# 1 swxY w Y   t           j                            || j        | j        ||          }t)          ||z
  d          |_        |                     |          st,          |S )a  Return the response obtained after sending a query via DNS-over-QUIC.

    *q*, a ``dns.message.Message``, the query to send.

    *where*, a ``str``, the nameserver IP address.

    *timeout*, a ``float`` or ``None``, the number of seconds to wait before the query
    times out. If ``None``, the default, wait forever.

    *port*, a ``int``, the port to send the query to. The default is 853.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying the source
    address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message. The default is
    0.

    *one_rr_per_rrset*, a ``bool``. If ``True``, put each RR into its own RRset.

    *ignore_trailing*, a ``bool``. If ``True``, ignore trailing junk at end of the
    received message.

    *connection*, a ``dns.quic.SyncQuicConnection``.  If provided, the
    connection to use to send the query.

    *verify*, a ``bool`` or ``str``.  If a ``True``, then TLS certificate verification
    of the server is done using the default CA bundle; if ``False``, then no
    verification is done; if a `str` then it specifies the path to a certificate file or
    directory which will be used for verification.

    *server_hostname*, a ``str`` containing the server's hostname.  The
    default is ``None``, which means that no hostname is known, and if an
    SSL context is created, hostname checking will be disabled.

    Returns a ``dns.message.Message``.
    zDNS-over-QUIC is not available.r   N)rE  server_nameTr   r	   )r   quic	have_quicr|   idr   r   r   SyncQuicManagerconnectr)   make_streamr   receiver   r
   r   r   r   r   maxr   rw   )r   r   r   r:   rA   r   r   r   rJ  r   r   r   managerthe_connectionthe_managerstartr   streamfinishr   s                       r   rM  rM    s   d 8 75666AD99;;D  5?5KD5Q5Q#(**O + 
 
 	   	S(00fkRRN,W55
''00 	:FKKd###>>*Z"8"899D	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:                		M)' 	 	 	A %%%AF== Hs7   :AD+<9D5D+D	D+D		D++D/2D/zonerdtyperdclasskeyname
relativizer(   serialuse_udpkeyalgorithmc              #   (
  K   t          |t                    rt          j                            |          }t          j        j                            |          }t          j        	                    |||          }|t          j        j
        k    r@t          j                            |dddd|z            }|j                            |           ||                    |||           |                                }t!          | ||
|          \  }}}
|r$|t          j        j
        k    rt#          d          |rt$          j        nt$          j        }t+          |||
          5 }t-          |	          \  }}t/          |||           t1          |          }|rt3          ||d|           n)t5          j        d|          |z   }t9          |||           d	}d
}d	}d}|r|}t          j        j        }nd}|}d} |st-          |          \  }}!|!||!|k    r|}!|rt=          |d|!          \  }}n9t?          |d|!          }"t5          j         d|"          \  }t?          |||!          }|t          j        j
        k    }#t          j        !                    ||j"        |j#        d
|| d
|#          }$|$$                                }%|%t          j$        j%        k    rtM          |%          |$j'        } d}&||$j(        r|$j(        d         j        |k    rt          j)        *                    d          |$j(        d         }|j+        t          j        j,        k    rt          j)        *                    d          d}&|-                                }|t          j        j
        k    r3t          j.        /                    |d         j.                  |k    rd
}nd
}|$j(        |&d         D ]}|rt          j)        *                    d          |j+        t          j        j,        k    r|j        |k    r|r3|d         j.        |k    rt          j)        *                    d          d	}n|t          j        j
        k    r| }||k    r.|t          j        j0        k    s|t          j        j
        k    r|rd
}|rt          j        j0        }d	}|r-|j"        r&|$j1        st          j)        *                    d          |$V  |ddd           dS # 1 swxY w Y   dS )a  Return a generator for the responses to a zone transfer.

    *where*, a ``str`` containing an IPv4 or IPv6 address,  where
    to send the message.

    *zone*, a ``dns.name.Name`` or ``str``, the name of the zone to transfer.

    *rdtype*, an ``int`` or ``str``, the type of zone transfer.  The
    default is ``dns.rdatatype.AXFR``.  ``dns.rdatatype.IXFR`` can be
    used to do an incremental transfer instead.

    *rdclass*, an ``int`` or ``str``, the class of the zone transfer.
    The default is ``dns.rdataclass.IN``.

    *timeout*, a ``float``, the number of seconds to wait for each
    response message.  If None, the default, wait forever.

    *port*, an ``int``, the port send the message to.  The default is 53.

    *keyring*, a ``dict``, the keyring to use for TSIG.

    *keyname*, a ``dns.name.Name`` or ``str``, the name of the TSIG
    key to use.

    *relativize*, a ``bool``.  If ``True``, all names in the zone will be
    relativized to the zone origin.  It is essential that the
    relativize setting matches the one specified to
    ``dns.zone.from_xfr()`` if using this generator to make a zone.

    *lifetime*, a ``float``, the total number of seconds to spend
    doing the transfer.  If ``None``, the default, then there is no
    limit on the time the transfer may take.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
    the source address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message.
    The default is 0.

    *serial*, an ``int``, the SOA serial number to use as the base for
    an IXFR diff sequence (only meaningful if *rdtype* is
    ``dns.rdatatype.IXFR``).

    *use_udp*, a ``bool``.  If ``True``, use UDP (only meaningful for IXFR).

    *keyalgorithm*, a ``dns.name.Name`` or ``str``, the TSIG algorithm to use.

    Raises on errors, and so does the generator.

    Returns a generator of ``dns.message.Message`` objects.
    r   INSOAz. . %u 0 0 0 0N)	algorithmzcannot do a UDP AXFRr$  FTr  r  r   r   xfrorigintsig_ctxmultir   z No answer or RRset not for qnamezfirst RRset is not an SOAr   zanswers after final SOAzIXFR base serial mismatchmissing TSIG)2r   r   r   name	from_text	rdatatype	RdataTypemaker   
make_queryIXFRrrset	authorityr,   use_tsigr   r   r   r2   r  r3   r1   r)   r4   r   r   r%  packr  emptyr   r  r&  r   r   r	  rcodeNOERRORTransferErrorrj  answerr   	FormErrorr\  re  copyr`  SerialAXFRhad_tsig)'r   r[  r\  r]  r   r:   r   r^  r_  r(   rA   r   r`  ra  rb  r   rt  r   r@   r   	sock_typer   r=   r   r  r!  donedelete_modeexpecting_SOA	soa_rrsetri  onamerj  mexpirationr'  is_ixfrr   ry  answer_indexs'                                          r   rh  rh    sq     J $ (x!!$'']$))&11FtVW55A###	##D!T5:JV:STT	5!!!	

7G|
<<<99;;D 7tV[! !Rf  16S]////000%,D!!&2DI	b)V	,	, b(22JK,,,II 	.atZ0000[q))D0Fq&*---	 	FHNEEFE N	-g66Q"&;+C+C( 4%a<<	qq!!Q44}T511 A{33 22G%%	E!!( & 	 	A GGIIE	)))#E***zHL x V18A;#3u#<#<-112TUUU<3=#444-112MNNN !JJLL	S]///z((1)<==GG  $(,
 ,--0 * * M-112KLLL<3=#444u9L9L$ 6 8?f44"%-"9"9:U"V"VV(-3=#555*5o 	))#-"444"cm&888[8#" * !]/F$)M >	 >!* >m--n===GGG]  N	)b b b b b b b b b b b b b b b b b bs   &NTTTc                       e Zd ZdZdZdZdZdS )UDPModea  How should UDP be used in an IXFR from :py:func:`inbound_xfr()`?

    NEVER means "never use UDP; always use TCP"
    TRY_FIRST means "try to use UDP but fall back to TCP if needed"
    ONLY means "raise ``dns.xfr.UseTCP`` if trying UDP does not succeed"
    r   r   r  N)rJ   rK   rL   ru   NEVER	TRY_FIRSTONLYr\   r   r   r  r    s)          EIDDDr   r  txn_managerudp_modec	                    |#t           j                            |          \  }}	nt           j                            |          }	|j        d         j        }
|
t           j        j        k    }|                                }|	                                }t          | |||          \  }}}t          |          \  }}d}|r)d}|r|t          j        k    rt          j        }d}nt          j        }d}t#          |||          5 }t%          |||           |rt'          ||d|           n6t)          j        dt-          |                    |z   }t/          |||           t           j                            ||
|	|          5 }d}d}|st          |          \  }}||||k    r|}|rt3          |d|          \  }}n9t5          |d|          }t)          j        d|          \  }t5          |||          }t           j                            ||j        |j        d||| |          }	 |                     |          }n?# t           j        j!        $ r( |sJ |t          j"        k    r d}d}t          j        }Y w xY w|j#        }||s-|j        r&|j$        st           j%        &                    d	          ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |'dS dS )
a  Conduct an inbound transfer and apply it via a transaction from the
    txn_manager.

    *where*, a ``str`` containing an IPv4 or IPv6 address,  where
    to send the message.

    *txn_manager*, a ``dns.transaction.TransactionManager``, the txn_manager
    for this transfer (typically a ``dns.zone.Zone``).

    *query*, the query to send.  If not supplied, a default query is
    constructed using information from the *txn_manager*.

    *port*, an ``int``, the port send the message to.  The default is 53.

    *timeout*, a ``float``, the number of seconds to wait for each
    response message.  If None, the default, wait forever.

    *lifetime*, a ``float``, the total number of seconds to spend
    doing the transfer.  If ``None``, the default, then there is no
    limit on the time the transfer may take.

    *source*, a ``str`` containing an IPv4 or IPv6 address, specifying
    the source address.  The default is the wildcard address.

    *source_port*, an ``int``, the port from which to send the message.
    The default is 0.

    *udp_mode*, a ``dns.query.UDPMode``, determines how UDP is used
    for IXFRs.  The default is ``dns.UDPMode.NEVER``, i.e. only use
    TCP.  Other possibilities are ``dns.UDPMode.TRY_FIRST``, which
    means "try UDP but fallback to TCP if needed", and
    ``dns.UDPMode.ONLY``, which means "try UDP and raise
    ``dns.xfr.UseTCP`` if it does not succeed.

    Raises on errors.
    Nr   TFr$  r  r  rg  rl  )'r   rh  rr  extract_serial_from_queryquestionr\  ro  rs  from_wire_originr   r   r)   r  r  r2   r  r3   r1   r4   r   r%  rw  r   r  Inboundr   r  r&  r   r   r   r	  process_messageUseTCPr  rj  r  r   r}  )r   r  r   r:   r   r(   rA   r   r  r`  r\  r  ri  r   r@   r   r=   r   retryr  is_udpr   r!  inboundr  rj  r  rwirer'  r  r   s                                  r   inbound_xfrr    s   ^ }',,[9922599^A%F**G))++F==??D 7tV[! !Rf %X..OQ
E
 4B 	x7=00)IFF*IF"i00 ,	BAQZ000 2!T44444T3t9955<1fj111fffEE %B  *'5g'>'>$Q"*".;3K3K&0 =%.q%%E%E
 )!Q < <%}T599 )!Q < <-- %$)I %!)#)z)0 . 	 	A	!&66q997> ! ! !%v#w|33!# $#*= !  !zHA   *B  B Bqz B-11.AAAK%B %B %B %B %B %B %B %B %B %B %B %B %B %B %B,	B ,	B ,	B ,	B ,	B ,	B ,	B ,	B ,	B ,	B ,	B ,	B ,	B ,	B ,	B  4B 4B 4B 4B 4Bs\   A?KB'K*I ?K 9I<9K;I<<;K7KK	K
K	KK!K)T)NNr   )
NNFFNr   FFFN)
Nr  Nr   FFFFNF)
Nr  Nr   FFFNNF)NFNr   F)Nr  Nr   FFN)
NrG  Nr   FFNNNT)	NrG  Nr   FFNTN)wru   r   r   enumr+  r3  os.pathr   r2   r%  r
   typingr   r   r   r   r   dns._featuresr   dns.exceptiondns.inetdns.messagedns.namedns.quic	dns.rcodedns.rdataclassdns.rdatatype
dns.serialdns.transactiondns.tsigdns.xfrr   r   	_featureshave_have_httpxhttpcore._backends.syncr7   r   NetworkBackend_CoreNetworkBackend	_backendssync
SyncStreamr5   r   HTTPTransportrP   r   r^   ImportErrorr   r   DNSExceptionrs   r}  rw   ry   r|   rh  r{  r)   r   r   hasattrr   r   SelectSelectorr   r   r   r   r   r1   rY   r   r   r   floatintboolr   r   r   bytesr   rm  NametsigKeyr  r  r  r  r  r"  r(  r4   r  r9  ri   rF  rl   rI  rM  SyncQuicConnectionro  r  
rdataclassrd  default_algorithmrp  
RdataClassIntEnumr  r  transactionTransactionManagerr  r\   r   r   <module>r     s  $          				         4 4 4 4 4 4 4 4 4 4 4 4 4 4                                       2 2 2 m  '' S&""""LLL"1(-8O2& 2& 2& 2& 2&- 2& 2& 2&h    ,    ,& & & & & & & &
 .JJJJ . . .. . . . . . . . . ..0 H H H H Hs}1 H H HG G G G G#-) G G G    CM&   
    CM&    %$ $ $$ $ $8% % % 79n%% 	/  ,OO.O0 0 00 0 0	) 	) 	)  " =A)% )% )% )%X   .  $ "!!'+#26",Q Q
{QQ e_Q 	Q
 SMQ Q Q Q c]Q Q Q  }Q $)Q ./Q SMQ  	[!Q Q Q Qh	1 	1 	11 1 1& #'	 

#U*
+  	
 3:   > "&"&#";?#&! %+/g4 g4
g4#g4 g4 	g4
 g4 d38=#(,678g4 %g4 g4 g4 g4 CK'(g4 	g4 g4 g4 g4Z  $ #"! %X X
{XX e_X 	X
 SMX X X X X X 3-X X 	[X X X X|  $ #"!""U  U 
{U U  e_U  	U 
 SMU  U  U  U  U  smU  smU  U  3;$%U  U  U  U p  *1 1 1& #'$ $
$
#U*
+$ $ 3:	$ $ $ $@ #'";?#&!, ,
,, , d38=#(,678	,
 %, , 3;%&, , , ,^- - -  $ "!A A
{AA e_A 	A
 SMA A A A 3-A 	[A A A AH. . .c],1$),<^   2  $ "!$(,0%)#h h
{hh e_h 	h
 SMh h h h 3=
!h #.)h c]h $)h 	[h h h h\  $ "!8<#%)T T
{TT e_T 	T
 SMT T T T 45T $)T c]T 	[T T T Tt 36-2D58^5F#;?37 $ .1h.Hw ww
s"
#w #-)3./w 3>,c12	w
 e_w w d38=#(,678w eCHM3./0w w uow SMw w w w s*+w  	!w w w wt
 
 
 
 
dl 
 
 
  ,0# $ pB pBpB3pB CK'(pB 	pB
 e_pB uopB SMpB pB pB 
pB pB pB pB pB pBs   !C& &C;:C;