
    df              !          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
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 Zd ZdZdZ 	 ddl!Z!ddl"Z!ddl#Z#e!jH                  Z%e!jL                  jN                  jP                  Z)dZ	  e#jT                  d      5  dZ ddd        G d	 d
e%      Z, G d de#jZ                        Z.eZ0	 ddl1Z1ej                  Z2 G d dejf                  jh                        Z5 G d dejf                  jl                        Z7 G d dejf                  jh                        Z8 G d dejf                  jh                        Z9ejt                  jv                  Z;d Z<d Z=d Z> e?ed      rej                  aAnej                  aAd ZCd ZDd ZEd ZF	 dcd ZGddd!ZHdd"dddddd#ddddej                  fd$ej                  j                  d%eLd&eeM   d'eNd(eeL   d)eNd*eOd+eOd,ee   d-eLd.eOd/eeL   d0eeOeLf   d1ed2   d3eeN   d4ej                  j                  f d5ZPd6 ZQd7 ZR	 ded8ed9eej                  j                  eSf   d:ed;eeM   d4eeNeMf   f
d<ZT	 	 	 	 	 	 	 	 dfd8ed:ee   d;eeM   d=eOd*eOd>eeej                  j                  ej                  j                  f      d?eeS   d+eOd@eOd4efdAZY	 	 	 	 	 	 	 	 	 dgd$ej                  j                  d%eLd&eeM   d'eNd(eeL   d)eNd=eOd*eOd+eOd@eOd8ee   d4ej                  j                  fdCZZ	 	 	 	 	 	 	 	 	 dhd$ej                  j                  d%eLd&eeM   d'eNd(eeL   d)eNd=eOd*eOd+eOdDee   dEee   d4eej                  j                  eOf   fdFZ[dG Z\dH Z]	 ded8ed9eej                  j                  eSf   d;eeM   d4eeNeMf   fdIZ^	 	 	 	 	 did8ed;eeM   d*eOd>eeej                  j                  ej                  j                  f      d?eeS   d+eOd4eej                  j                  eMf   fdJZ_dK Z`	 	 	 	 	 	 	 djd$ej                  j                  d%eLd&eeM   d'eNd(eeL   d)eNd*eOd+eOd8ee   d4ej                  j                  fdLZadM Zb	 	 	 	 	 	 	 	 	 dkd$ej                  j                  d%eLd&eeM   d'eNd(eeL   d)eNd*eOd+eOd8ee1j                     dNee1j                     dOeeL   d4ej                  j                  fdPZe	 	 	 	 	 	 	 	 	 dld$ej                  j                  d%eLd&eeM   d'eNd(eeL   d)eNd*eOd+eOdQeej                  j                     d0eeOeLf   dOeeL   d4ej                  j                  fdRZfej                  j                  ej                  j                  ddBddddddddej                  j                  fd%eLdSeej                  j                  eLf   dTeej                  j                  eLf   dUeej                  j                  eLf   d&eeM   d'eNd>eeej                  j                  ej                  j                  f      dVeeej                  j                  eLf      dWeOdXeeM   d(eeL   d)eNdYeNdZeOd[eej                  j                  eLf   d4ef d\Z: G d] d^ej                        ZpddBddddepj                  fd%eLd_ej                  j                  d`eej                  j                     d'eNd&eeM   dXeeM   d(eeL   d)eNdaepd4dfdbZty# 1 sw Y   CxY w# e+$ r Y Nw xY w# e/$ r  G d d      Z.Y Dw xY w# e/$ r  G d d      Z1Y Sw xY w)mzTalk to a DNS server.    N)AnyDictOptionalTupleUnionc                 x    | y | t        j                          z
  }|dk  rt        j                  j                  |S )N        )timedns	exceptionTimeout)
expirationtimeouts     B/home/api-vastappli/venv/lib/python3.12/site-packages/dns/query.py
_remainingr   -   s7    499;&G#~mm###N    c                 J    |y t        t        j                         | z   |      S N)minr
   )r   r   s     r   _expiration_for_this_attemptr   6   s#    tyy{W$j11r   FT)http2c                   2     e Zd Z fdZ	 ddZ	 ddZ xZS )_NetworkBackendc                 Z    t         |           || _        || _        || _        || _        y r   )super__init___local_port	_resolver_bootstrap_address_family)selfresolver
local_portbootstrap_addressfamily	__class__s        r   r   z_NetworkBackend.__init__O   s,    G)D%DN&7D#!DLr   c                 l   g }t        |      \  }}t        j                  j                  |      r|j	                  |       n| j
                  |j	                  | j
                         nft        |      }| j                  }	|rt        j                  j                  |      }	| j                  j                  ||	|      }
|
j                         }|D ]  }t        j                  j                  |      }|| j                  dk7  r-t        j                  j                  || j                  f|      }nd }t        |t        j                   |      }t#        d|      }	 t%        |t        j                  j                  ||f|      |       t'        |      c S  t*        j,                  # t(        $ r Y w xY w)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_tcpV   s    I*73MAzxx""4(  &((4  !8!89$Z0  XX44]CF..55' 6  $--/	$ XX,,W5 ,0@0@A0E XX==&(8(892F "F#B(:(:FC%A#z%R"88'4"M*
 +400!& ''' ! s   7F''	F32F3c                     t         r   NotImplementedError)r!   pathr   r<   s       r   connect_unix_socketz#_NetworkBackend.connect_unix_socket}   s
     &%r   r   )__name__
__module____qualname__r   rD   rI   __classcell__r&   s   @r   r   r   N   s    	" FJ%	(P 15	&r   r   c                   >     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                  j                         }t        |   |i | t        ||||      | j                  _        y Nr   )dns.resolverr"   Resolverr   r   r   _pool_network_backend)	r!   r#   r$   r"   r%   argskwargsr   r&   s	           r   r   z_HTTPTransport.__init__   sM     #<<002Gd-f-*9*&7+DJJ'r   )rJ   rK   rL   r2   	AF_UNSPECr   rM   rN   s   @r   rP   rP      s!     "##	 	r   rP   c                       e Zd Zd Zy)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                   p    e Zd Z G d de      Z G d de      Z G d d      Z G d d      Zed	        Z	y
)sslc                       e Zd Zy)ssl.WantReadExceptionNrJ   rK   rL   r\   r   r   WantReadExceptionr`          r   rb   c                       e Zd Zy)ssl.WantWriteExceptionNra   r\   r   r   WantWriteExceptionre      rc   r   rf   c                       e Zd Zy)ssl.SSLContextNra   r\   r   r   
SSLContextrh      rc   r   ri   c                       e Zd Zy)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   r6   rb   rf   ri   rl   classmethodro   r\   r   r   r^   r^      sB    		 		 		 		 	 
	. 
	.r   r^   c                       e Zd ZdZy)UnexpectedSourcez=A DNS query response came from an unexpected address or port.NrJ   rK   rL   __doc__r\   r   r   rr   rr      s    Gr   rr   c                       e Zd ZdZy)BadResponsez<A DNS query response does not respond to the question asked.Nrs   r\   r   r   rv   rv      s    Fr   rv   c                       e Zd ZdZy)NoDOHzMDNS over HTTPS (DOH) was requested but the httpx module is not
    available.Nrs   r\   r   r   rx   rx          r   rx   c                       e Zd ZdZy)NoDOQzNDNS over QUIC (DOQ) was requested but the aioquic module is not
    available.Nrs   r\   r   r   r{   r{      ry   r   r{   c                 D    t        j                          }| |d fS ||| z   fS r   )r
   )r   nows     r   r)   r)      s+    
))+CT{S7]##r   c                    |r.t        | t        j                        r| j                         dkD  ryt	               }d}|r|t
        j                  z  }|r|t
        j                  z  }|r|j                  | |       |d }n6|t        j                         z
  }|dk  rt        j                  j                  |j                  |      st        j                  j                  y )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==1bjjlQ6F

CF)&&&)'''R tyy{*c>--'''::gmm### r   c                     | a y r   )r   )selector_classs    r   _set_selector_classr      s	    
 %Or   PollSelectorc                 "    t        | ddd|       y )NTFr   sr   s     r   _wait_for_readabler     s    audJ/r   c                 "    t        | ddd|       y )NFTr   r   s     r   _wait_for_writabler     s    adJ/r   c                     	 t         j                  j                  | |d         }t         j                  j                  | |d         }||k(  xr |dd  |dd  k(  S # t         j                  j                  $ r Y yw xY w)Nr   F   )r   r*   	inet_ptonr   SyntaxError)r@   a1a2n1n2s        r   _addresses_equalr     s{    XXBqE*XXBqE* 8(12"QR&(( ==$$ s   AA A:9A:c                     |syt        | ||      s-t        j                  j                  |d         r|dd  |dd  k(  ry|ryt	        d| d|       )NTr   r   Fzgot a response from z instead of )r   r   r*   is_multicastrr   )r@   from_addressdestinationignore_unexpecteds       r   _matches_destinationr     sh     L+6k!n-,qr2BkRSRTo2U	

|nL[MJ r   c                    d }d }	 t         j                  j                  |       }| }|r3t         j                  j                  |      }|r||k7  rt	        d      |}|r"|s 	 t         j                  j                  |      }|r"t         j                  j                  ||f|      }|r"t         j                  j                  ||f|      }|||fS # t        $ r |r Y w xY w# t        $ r t	        d      w xY w)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   ,  s
   
 
BKXX$$U+
 hh%%f-by K  B6	TXX((,F hh66T7JBO116;2GLV$$?    !,  	TRSS	Ts   !C !C CCC4c                     t        | |      }	 |j                  d       ||j                  |       |r|j                  |d|      S |S # t        $ r |j                           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   X  sv    r4 A	eFF6N**(- / +   H 		s   9A
 A
 
A%i  z
/dns-queryqr   r   r:   rA   r   one_rr_per_rrsetignore_trailingsessionrH   postr$   verifyr"   zdns.resolver.Resolverr%   returnc           
      &   t         st        |r%t        |t        j                        st        d      | j                         }t        ||||d      \  }}}d}ddi}|mt        j                  j                  |      rN|t        j                  k(  rdj                  |||	      }n)|t        j                  k(  rdj                  |||	      }n|}|d}d}n
|d   }|d	   }t        |d
t         |||||      }|rt#        j$                  |      }nt        j                  d
t         ||      }|5 }|
r<|j'                  dt)        t+        |            d       |j-                  |||      }nKt/        j0                  |      j3                  d      }|j5                         }|j7                  ||d|i      }ddd       j8                  dk  s|j8                  dkD  r0t        dj                  ||j8                  |j:                              t        j<                  j?                  |j:                  | j@                  | jB                  ||      }|jD                  jG                         |_$        | jK                  |      stL        |S # 1 sw Y   xY w)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;   http1r   r   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_dohrx   r   httpxClientr   to_wirer   r   r*   r+   r2   AF_INETformatAF_INET6rP   _have_http2
contextlibnullcontextupdatestrlenr   base64urlsafe_b64encoderstripdecodegetstatus_coder   message	from_wirer   r   elapsedtotal_secondsr
   is_responserv   )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   l  s   H z'5<<8DEE99;D1tV[%RJ I23G	~#((--e4#**5$=C6??"%,,UD$?C 
"1]
#+	I 0:0F0Fw0O\\k&I
 
 w NN$=&)#d)n ||C$PW|XH++D188>DKKME{{Wguen # H( c!X%9%9C%?""(&0D0DhFVFV"W
 	
 			MM)' 	 	A ++-AF==HG s   -B
JJc                 `    	 	 | j                  |      S # t        $ r t        | |       Y nw xY w.)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     s9    
 	1==** 	1tZ0	1 s    ,,c                     	 	 |r| j                  ||      S | j                  |      S # t        $ r t        | |       Y nw xY wB)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     sL    
 	1{{455yy& 	1tZ0	1 s   ( ( A A rB   whatr   r   c                     t        |t        j                  j                        r|j	                         }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     sH    , $++,||~		I$k:6Ay>r   r   r   r   raise_on_truncationc	                     d}		 t        | d|      \  }	}
t        | j                  |
||      rn*t        j                         }t        j
                  j                  |	|||||      }|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.
    r     )r   r   r   r   r   )r   r   r%   r
   r   r   r   )rB   r   r   r   r   r   r   r   r   r   r   received_timer   s                r   receive_udpr   :  s    h D
(ujA|KK{4E
   IIKM)'/ 	 	A =!!=,//r   5   c                    | j                         }t        ||||      \  }}}t        |      \  }}|
rt        j                  |
      }nt        |t        j                  |      }|5 }t        ||||       t        |||||| j                  | j                  ||		      \  }}||z
  |_        | j                  |      st        |cddd       S # 1 sw Y   nxY w	 J )aL  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.

    Returns a ``dns.message.Message``.
    N)r   r   r)   r   r   r1   r2   
SOCK_DGRAMr   r   r   macr
   r   rv   )r   r   r   r:   rA   r   r   r   r   r   rB   r   r@   r   
begin_timer   r   r   r   r   s                       r   udpr    s    f 99;D 7tV[!Rf  .g6Z0:0F0Ft0L"f//8	 qD+z2(IIEE

M +}}Q!  $ 	s   &A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.

    Returns a (``dns.message.Message``, tcp) tuple where tcp is ``True``
    if and only if TCP was used.
    TF)r  r   r   	Truncatedtcp)r   r   r   r:   rA   r   r   r   r   r  r  r   s               r   udp_with_fallbackr    s    n 
 %  ;;    

 $ s    4AAc                    d}|dkD  r6	 | j                  |      }|dk(  rt        |t        |      z  }||z  }|dkD  r6|S # t        t        j
                  f$ r t        | |       Y /t        j                  $ r t        | |       Y Ow xY w)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  +  s     	A
!)		1		% ACxSVOEFA !) H	  !5!56 	1tZ0$$ 	1tZ0	1s   /A   %B'BBc                     d}t        |      }||k  r	 || j                  ||d       z  }||k  ryy# t        t        j                  f$ r t        | |       Y /t        j                  $ r t        | |       Y Ow xY w)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  @  s~    
 GD	A
A+	1tyygh00G A+  !6!67 	1tZ0## 	1tZ0	1s   3 %A;A;:A;c                    t        |t        j                  j                        r|j	                         }n|}t        |      }t        j                  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.
    !H)
r   r   r   r   r   r   structpackr
   r  )rB   r   r   r   r  tcpmsgr   s          r   send_tcpr  P  sn    $ $++,||~D	A [[q!D(F		ItVZ(K##r   c                     t        | d|      }t        j                  d|      \  }t        | ||      }t        j                         }	t        j
                  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  r   )r  r  unpackr
   r   r   r   )rB   r   r   r   r   r   ldatar  r   r   r   s              r   receive_tcpr"  p  ss    B dAz*E==u%DQT1j)DIIKM)' 	 	A }r   c                 P   | j                  |      }|dk(  ry |t        j                  t        j                  t        j                  fv r:t        | |       | j                  t        j                  t        j                        }|dk7  rt        |t        j                  |            y 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
ax
u  %"3"3U^^DD1j)ll6,,foo>
axc2;;s+,, r   c	           	         | j                         }	t        |      \  }
}|rt        j                  |      }n-t	        ||||      \  }}}t        |t        j                  |      }|5 }|st        ||       t        ||	|       t        |||| j                  | j                  |      \  }}||
z
  |_        | j                  |      st        |cddd       S # 1 sw Y   nxY w	 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   rv   )r   r   r   r:   rA   r   r   r   rB   r   r  r   r   r@   r   r   r   r   s                     r   r  r    s    V 99;D-g6Z0:0F0Ft0L$;4%
![& "f00&9	 
qQZ0D*%(z+QYY
M +}}Q
 
 
 	s   &A&CCc                     	 	 | j                          y # t        j                  $ r t        | |       Y n$t        j                  $ r t        | |       Y nw xY wXr   )do_handshaker^   r  r   r  r   r   s     r   _tls_handshaker3    sS    
	.NN## 	.q*-$$ 	.q*-	. s    AAAr   r   c                 Z   |rt        | ||||||||	      S | j                         }t        |      \  }}t        ||||      \  }}}|	>|s<t	        j
                         }	t        j                  j                  |	_        |
d|	_	        t        |t        j                  ||	|
      5 }t        |||       t        ||       t        |||       t!        |||| j"                  | j$                  |      \  }}||z
  |_        | j)                  |      st*        |cddd       S # 1 sw Y   nxY w	 J )a:  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.

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

    NF)r   r   )r  r   r)   r   r^   ro   
TLSVersionTLSv1_2minimum_versioncheck_hostnamer1   r2   r3   r4   r3  r  r"  r   r  r
   r   rv   )r   r   r   r:   rA   r   r   r   rB   r   r   r   r  r   r@   r   r   r   r   s                      r   tlsr9    sK   n  

 
	
 99;D-g6Z 7tV[!Rf 4002&)nn&<&<#").K&	
'
  
K,q*%D*%(z+QYY
M +}}Q!  $ 	s   $A0DD'
connectionc                     t         j                  j                  st        d      d| _        | j                         }|rt        j                  d      }|}n#t         j                  j                  |	|
      }|}|5  |sj                  ||||      }t        |      \  }}j                  |      5 }|j                  |d       |j                  t        |            }ddd       t        j                         }ddd       t         j                   j#                  || j$                  | j&                  ||      }t)        z
  d      |_        | j+                  |      st,        |S # 1 sw Y   xY w# 1 sw Y   zxY w)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)verify_modeserver_nameTr   r	   )r   quic	have_quicr{   idr   r   r   SyncQuicManagerconnectr)   make_streamr   receiver   r
   r   r   r   r   maxr   rv   )r   r   r   r:   rA   r   r   r   r:  r   r   r   managerthe_connectionthe_managerstartr   streamfinishr   s                       r   r>  r>  a  s_   d 88566AD99;D 5?5K5KD5Q#((**O + 
 	 (00fkRN,W5
''0 	:FKKd#>>*Z"89D	:  			MM)' 	 	A %%AF==H	: 	:	 s$   <6E42-E(E4(E1	-E44E=zonerdtyperdclasskeyname
relativizer(   serialuse_udpkeyalgorithmc              #   
  K   t        |t              rt        j                  j	                  |      }t        j
                  j                  j                  |      }t        j                  j                  |||      }|t        j
                  j                  k(  rAt        j                  j	                  |dddd|z        }|j                  j                  |       ||j                  |||       |j                         }t!        | ||
|      \  }}}
|r(|t        j
                  j                  k7  rt#        d      |rt$        j&                  nt$        j(                  }t+        |||
      5 }t-        |	      \  }}t/        |||       t1        |      }|rt3        ||d|       n&t5        j6                  d|      |z   }t9        |||       d	}d
}d	}d}|r|}t        j                  j:                  }nd}|}d} |sgt-        |      \  }}!|!||!|kD  r|}!|rt=        |d|!      \  }}n2t?        |d|!      }"t5        j@                  d|"      \  }t?        |||!      }|t        j
                  j                  k(  }#t        j                  jC                  ||jD                  |jF                  d
|| d
|#      }$|$jI                         }%|%t        jH                  jJ                  k7  rtM        |%      |$jN                  } d}&||$jP                  r|$jP                  d   j                  |k7  rt        jR                  jU                  d      |$jP                  d   }|jV                  t        j
                  jX                  k7  rt        jR                  jU                  d      d}&|j[                         }|t        j
                  j                  k(  r4t        j\                  j_                  |d   j\                        |k  rd
}nd
}|$jP                  |&d D ]  }|rt        jR                  jU                  d      |jV                  t        j
                  jX                  k(  r|j                  |k(  r|r4|d   j\                  |k7  rt        jR                  jU                  d      d	}n |t        j
                  j                  k(  r| }||k(  s|t        j
                  j`                  k(  s!|t        j
                  j                  k(  s|sd
}|st        j
                  j`                  }d	} |r7|jD                  r+|$jb                  st        jR                  jU                  d      |$ |sgddd       y# 1 sw Y   yxY ww)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  r  r  emptyr   r  r   r   r   r  rcodeNOERRORTransferErrorr[  answerr   	FormErrorrM  rV  copyrQ  SerialAXFRhad_tsig)'r   rL  rM  rN  r   r:   r   rO  rP  r(   rA   r   rQ  rR  rS  r   re  r   r@   r   	sock_typer   r=   r   r  r  donedelete_modeexpecting_SOA	soa_rrsetrZ  onamer[  mexpirationr!  is_ixfrr   ri  answer_indexs'                                          r   rY  rY    s    J $xx!!$']]$$))&1FtVW5A###		##D!T5:JV:ST	5!	

7G|
<99;D 7tV[!Rf 6S]]////00%,!!&2D2DI	b)V	, b(2JK,IatZ0[[q)D0Fq&*-	FHHNNEFE-g6Q"&;+C(%a<	q!!Q4}}T51 A{3 2 22G%%		EE!!( & 	A GGIE		)))#E**zzHL xx188A;#3#3u#<--112TUU<<3==#4#44--112MNN !JJL	S]]///zz((1)<)<=G  $(,
 ,-0 *--112KLL<<3==#4#44u9L$ 8??f4"%--"9"9:U"VV(-3==#5#55*5o 	)#--"4"44"cmm&8&88[#" !]]//F$)M7*8 		!**mm--n==G] )b b bs8   E)U5+MU)<:U)7U):U) AU) 	U5)U2.U5c                       e Zd ZdZdZdZdZy)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   rt   NEVER	TRY_FIRSTONLYr\   r   r   r|  r|  r  s     EIDr   r|  txn_managerqueryudp_modec	                    |#t         j                  j                  |      \  }}	nt         j                  j                  |      }	|j                  d   j
                  }
|
t         j                  j                  k(  }|j                         }|j                         }t        | |||      \  }}}t        |      \  }}d}|rd}|r&|t        j                  k7  rt        j                  }d}nt        j                   }d}t#        |||      5 }t%        |||       |rt'        ||d|       n/t)        j*                  dt-        |            |z   }t/        |||       t         j                  j1                  ||
|	|      5 }d}d}|st        |      \  }}||||kD  r|}|rt3        |d|      \  }}n2t5        |d|      }t)        j6                  d|      \  }t5        |||      }t         j8                  j;                  ||j<                  |j>                  d||| |      }	 |jA                  |      }|jF                  }|s|s7|j<                  r+jH                  st         jJ                  jM                  d	      ddd       ddd       |ryy# t         j                  jB                  $ r0 |sJ |t        jD                  k(  r d}d}t        j                  }Y Xw xY w# 1 sw Y   gxY w# 1 sw Y   kxY w)
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  rX  r]  )'r   rY  rc  extract_serial_from_queryquestionrM  r`  rd  from_wire_originr   r   r)   r|  r}  r2   r  r3   r1   r4   r   r  r  r   r  Inboundr   r  r   r   r   r   r  process_messageUseTCPr  r[  rq  r   rm  )r   r  r  r:   r   r(   rA   r   r  rQ  rM  ry  rZ  r   r@   r   r=   r   retryrr  is_udpr   r  inboundrs  r[  rx  rwirer!  r  r   s                                  r   inbound_xfrr    s   ^ }'',,[92259^^A%%F***G))+F==?D 7tV[!Rf %X.OQ
E
x7==0))IF**IF"i0 ,	BAQZ0!T44T3t95<1fj1fffE %B'5g'>$Q"*".;3K&0%.q%%E
 )!Q <%}}T59 )!Q <-- %$)II %!)#)z)0 . 	A	!&66q9  !zzHA B qzz--11.AAK%B,	B T 77>> !%#w||3!# $#*== !7%B %B,	B ,	BsQ   	A0K&9B!KJ
,K;9K4K&
A	KKKKK#	K&&K/)T)NNr   )NNFFNr   FF)	Nr  Nr   FFFFN)	Nr  Nr   FFFNN)NFNr   F)Nr  Nr   FFN)	NU  Nr   FFNNN)	Nr  Nr   FFNTN)urt   r   r   enumr%  r-  r   r2   r  r
   typingr   r   r   r   r   dns.exceptionr   dns.inetdns.messagedns.namedns.quic	dns.rcodedns.rdataclassdns.rdatatype
dns.serialdns.transactiondns.tsigdns.xfrr   r   _have_httpxr   r7   httpcore._backends.syncr   NetworkBackend_CoreNetworkBackend	_backendssync
SyncStreamr5   r   r6   r   HTTPTransportrP   ImportErrorr   r^   r   r   DNSExceptionrr   rm  rv   rx   r{   rY  rk  r)   r   r   hasattrr   r   SelectSelectorr   r   r   r   r   r1   rY   r   r   r   floatintboolr   r   r   bytesr   r^  NametsigKeyr   r  r  r  r  r  r"  r4   r  r3  rl   ri   r9  r>  SyncQuicConnectionr`  rp  
rdataclassrU  default_algorithmra  
RdataClassIntEnumr|  r}  transactionTransactionManagerr  r\   r   r   <module>r     s|  $      	     4 4            2 \&""11((--88OKU\\% 	K	
2&- 2&h,, 6 .. Hs}}11 HG#--)) GCMM&& 
CMM&&  %%$$8% 9n%  ,,O..O00	)" =A)%X.  $ "!!'+#26",,S
{{SS e_S 	S
 SMS S S S c]S S S  }S $)S ./S SMS  	[[!Sl	11& #'	

##U*
+  	
 3:> "&"&#";?#&! %G0
G0#G0 G0 	G0
 G0 d388==#((,,678G0 %G0 G0 G0 	G0Z  $ #"! %O
{{OO e_O 	O
 SMO O O O O O 3-O 	[[Oj  $ #"!""R 
{{R R  e_R  	R 
 SMR  R  R  R  R  smR  smR  3;;$%R j*1& #'$
$
##U*
+$ $ 3:	$D #'";?#&!,
,, , d388==#((,,678	,
 %, , 3;;%&,^-  $ "!A
{{AA e_A 	A
 SMA A A A 3-A 	[[AH.  $ "!$(,0%)e
{{ee e_e 	e
 SMe e e e 3==
!e #..)e c]e 	[[eV  $ "!8<#%)T
{{TT e_T 	T
 SMT T T T 445T $)T c]T 	[[Tt 36--2D2D58^^5F5F#;?37 $ .1hh.H.Hww
s"
#w #--))3./w 3>>,,c12	w
 e_w w d388==#((,,678w eCHHMM3./0w w uow SMw w w w s*+w  	!wt
dll 
  ,0# $ pBpB33pB CKK''(pB 	pB
 e_pB uopB SMpB pB pB 
pBm)	 	 V  && &&  .. ..s`   0:\ +\ >\\ 	 \ ,\1 \\ \\ \\ \.-\.1]]