
    dfe              !       z   d Z ddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZ ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZ ddlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# e"rddl$Z$ejJ                  jL                  Z'd Z(d=dZ)	 d=dejT                  jV                  d	eejX                  jZ                  e.f   d
ede	e/   de
e0e/f   f
dZ1	 	 	 	 	 	 	 	 d>dejT                  jV                  d
e	e   de	e/   de2de2de	eejf                  jh                  ejj                  jl                  f      de	e.   de2de2defdZ7	 	 	 	 	 	 	 	 	 	 d?dejX                  jZ                  de8de	e/   de0de	e8   de0de2de2de2de2de	ejT                  jV                     de	ejT                  jr                     dejX                  jZ                  fdZ:	 	 	 	 	 	 	 	 	 	 d@dejX                  jZ                  de8de	e/   de0de	e8   de0de2de2de2de	ejT                  jV                     d e	ejT                  jv                     de	ejT                  jr                     de
ejX                  jZ                  e2f   fd!Z<	 d=dejT                  jv                  d	eejX                  jZ                  e.f   de	e/   de
e0e/f   fd"Z=d# Z>	 	 	 	 	 dAdejT                  jv                  de	e/   de2de	eejf                  jh                  ejj                  jl                  f      de	e.   de2de
ejX                  jZ                  e/f   fd$Z?	 	 	 	 	 	 	 	 dBdejX                  jZ                  de8de	e/   de0de	e8   de0de2de2de	ejT                  jv                     de	ejT                  jr                     dejX                  jZ                  fd%Z@	 	 	 	 	 	 	 	 	 	 dCdejX                  jZ                  de8de	e/   de0de	e8   de0de2de2de	ejT                  jv                     de	ejT                  jr                     d&e	e#j                     d'e	e8   dejX                  jZ                  fd(ZBdd)dddddd*d+d+ddej                  fdejX                  jZ                  de8de	e/   de0de	e8   de0de2de2d,e	d-   d.e8d/e2d0ee2e8f   d1e	e8   d2e	d3   d4e	e0   dejX                  jZ                  f d5ZDddddddej                  dfde8d6ej                  j                  d7e	ejX                  jZ                     de0de	e/   d8e	e/   de	e8   de0d9ede	ejT                  jr                     ddfd:ZH	 	 	 	 	 	 	 	 	 	 dDdejX                  jZ                  de8de	e/   de0de	e8   de0de2de2d;e	ej                  j                     d0ee2e8f   de	ejT                  jr                     d'e	e8   dejX                  jZ                  fd<ZIy)EzTalk to a DNS server.    N)AnyDictOptionalTupleUnion)NullContext)
BadResponseNoDOHNoDOQUDPMode_compute_times_have_http2_matches_destination
_remaininghave_dohsslc                     |s|rF|@| t         j                  k(  rd}||fS | t         j                  k(  rd}||fS t        d|        ||fS y )Nz0.0.0.0z::zunknown address family )socketAF_INETAF_INET6NotImplementedError)afaddressports      G/home/api-vastappli/venv/lib/python3.12/site-packages/dns/asyncquery.py_source_tupler   :   sl     $?V^^##
 	 v&  *,CB4*HII    c                 R    | %|st        j                          }t        | |z
  d      S y )Nr   )timemax)
expirationnows     r   _timeoutr#   J   s+    ))+C:#Q''r   sockwhatdestinationr!   returnc                    K   t        |t        j                  j                        r|j	                         }t        j
                         }| j                  ||t        ||             d{   }||fS 7 w)a  Send a DNS message to the specified UDP socket.

    *sock*, a ``dns.asyncbackend.DatagramSocket``.

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

    *destination*, a destination tuple appropriate for the address family
    of the socket, specifying where to send the query.

    *expiration*, a ``float`` or ``None``, the absolute time at which
    a timeout exception should be raised.  If ``None``, no timeout will
    occur.  The expiration value is meaningless for the asyncio backend, as
    asyncio's transport sendto() never blocks.

    Returns an ``(int, float)`` tuple of bytes sent and the sent time.
    N)
isinstancednsmessageMessageto_wirer   sendtor#   )r$   r%   r&   r!   	sent_timens         r   send_udpr1   S   s^     . $++,||~		Ikk$Xj)-LMMAy> 	Ns   A)A6+A4,	A6Fignore_unexpectedone_rr_per_rrsetkeyringrequest_macignore_trailingraise_on_truncationc	                   K   d}		 | j                  dt        |             d{   \  }	}
t        | j                  |
||      rn@t	        j                         }t
        j                  j                  |	|||||      }|||
fS 7 _w)aj  Read a DNS message from a UDP socket.

    *sock*, a ``dns.asyncbackend.DatagramSocket``.

    See :py:func:`dns.query.receive_udp()` for the documentation of the other
    parameters, and exceptions.

    Returns a ``(dns.message.Message, float, tuple)`` tuple of the received message, the
    received time, and the address where the message arrived from.
    r     N)r4   r5   r3   r6   r7   )recvfromr#   r   familyr   r*   r+   	from_wire)r$   r&   r!   r2   r3   r4   r5   r6   r7   wirefrom_addressreceived_timers                r   receive_udprA   q   s     , D
%)]]5(::N%OO|KK{4E
   IIKM)'/ 	 	A }l++  Ps   "BBA B5   qwheretimeoutr   sourcesource_portbackendc                   K   | j                         }t        |      \  }}t        j                  j	                  |      }t        ||f|      }|
rt        |
      }no|st        j                  j                         }t        |||      }|j                         r||f}nd}|j                  |t        j                  d||       d{   }|4 d{   }t        ||||       d{    t        |||||| j                   | j"                  ||		       d{   \  }}}||z
  |_        | j'                  |      st(        |cddd      d{    S 7 7 7 o7 B7 # 1 d{  7  sw Y   yxY ww)aF  Return the response obtained after sending a query via UDP.

    *sock*, a ``dns.asyncbackend.DatagramSocket``, or ``None``,
    the socket to use for the query.  If ``None``, the default, a
    socket is created.  Note that if a socket is provided, the
    *source*, *source_port*, and *backend* are ignored.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.udp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    Nr   )r-   r   r*   inetaf_for_address_lltupler   asyncbackendget_default_backendr   datagram_connection_requiredmake_socketr   
SOCK_DGRAMr1   rA   r4   macr   is_responser	   )rC   rD   rE   r   rF   rG   r2   r3   r6   r7   r$   rH   r=   
begin_timer!   r   r&   cmstupledtuplesr@   r?   _s                           r   udprZ      sm    6 99;D-g6Z		 	 	'BE4="-K5@5F&&::<Gr6;7//1T]FF&&r6+<+<aPP  Qq$Z888&1IIEE
'
 
!
M1 +}}Q!   Q8
!
   s~   CE2E
E2EE2E'E(.EE*EE2EE2E2EEE2E/#E&$E/+E2udp_socktcp_sockc                    K   	 t        | ||||||||d|	|       d{   }|dfS 7 # t        j                  j                  $ r$ t	        | ||||||||
|
       d{  7  }|dfcY S w xY ww)a  Return the response to the query, trying UDP first and falling back
    to TCP if UDP results in a truncated response.

    *udp_sock*, a ``dns.asyncbackend.DatagramSocket``, or ``None``,
    the socket to use for the UDP query.  If ``None``, the default, a
    socket is created.  Note that if a socket is provided the *source*,
    *source_port*, and *backend* are ignored for the UDP query.

    *tcp_sock*, a ``dns.asyncbackend.StreamSocket``, or ``None``, the
    socket to use for the TCP query.  If ``None``, the default, a
    socket is created.  Note that if a socket is provided *where*,
    *source*, *source_port*, and *backend*  are ignored for the TCP query.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.udp_with_fallback()` for the documentation
    of the other parameters, exceptions, and return type of this
    method.
    TNF)rZ   r*   r+   	Truncatedtcp)rC   rD   rE   r   rF   rG   r2   r3   r6   r[   r\   rH   responses                r   udp_with_fallbackra      s     D 
 
 %  
 ;;    
 
 
 $ s=   A,( &( A,( 4A)A	A)&A,(A))A,c                 N  K   t        |t        j                  j                        r|j	                         }n|}t        |      }t        j                  d|      |z   }t        j                         }| j                  |t        ||             d{    t        |      |fS 7 w)zSend a DNS message to the specified TCP socket.

    *sock*, a ``dns.asyncbackend.StreamSocket``.

    See :py:func:`dns.query.send_tcp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    !HN)r)   r*   r+   r,   r-   lenstructpackr   sendallr#   )r$   r%   r!   r=   ltcpmsgr/   s          r   send_tcprj     s      $++,||~D	A [[q!D(F		I
,,vx
I>
???K## @s   BB%B#B%c                    K   d}|dkD  rG| j                  |t        |             d{   }|dk(  rt        |t        |      z
  }||z   }|dkD  rG|S 7 *w)z|Read the specified number of bytes from stream.  Keep trying until we
    either get the desired amount, or we hit EOF.
    r   r   N)recvr#   EOFErrorrd   )r$   countr!   rX   r0   s        r   _read_exactlyro   4  sc      	A
!)))E8J#7888NAE !) H 9s   &AA'AAc                   K   t        | d|       d{   }t        j                  d|      \  }t        | ||       d{   }t        j                         }	t        j
                  j                  |||||      }
|
|	fS 7 m7 Bw)zRead a DNS message from a TCP socket.

    *sock*, a ``dns.asyncbackend.StreamSocket``.

    See :py:func:`dns.query.receive_tcp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
       Nrc   r4   r5   r3   r6   )ro   re   unpackr   r*   r+   r<   )r$   r!   r3   r4   r5   r6   ldatarh   r=   r?   r@   s              r   receive_tcpru   B  s        a44E==u%DQtQ
33DIIKM)' 	 	A } 53s"   BB,B BABBc
           	        K   | j                         }
t        |      \  }}|r$|j                          d{    t        |      }n|t        j
                  j                  |      }t        |||      }||f}|	st        j                  j                         }	|	j                  |t        j                  d|||       d{   }|4 d{   }t        ||
|       d{    t        |||| j                  | j                   |       d{   \  }}||z
  |_        | j%                  |      st&        |cddd      d{    S 7 7 7 7 n7 D7 # 1 d{  7  sw Y   yxY ww)aO  Return the response obtained after sending a query via TCP.

    *sock*, a ``dns.asyncbacket.StreamSocket``, or ``None``, the
    socket to use for the query.  If ``None``, the default, a socket
    is created.  Note that if a socket is provided
    *where*, *port*, *source*, *source_port*, and *backend* are ignored.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.tcp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    Nr   )r-   r   getpeernamer   r*   rJ   rK   r   rM   rN   rP   r   SOCK_STREAMrj   ru   r4   rR   r   rS   r	   )rC   rD   rE   r   rF   rG   r3   r6   r$   rH   r=   rT   r!   rU   r   rV   rW   rX   r@   r?   s                       r   r_   r_   `  s_    4 99;D-g6Z    5@5F XX$$U+r6;7&&::<G&&""Avvw
 
   Qq$
+++#.z+QYY$
 
M +}}Q   	!
+
   s   4E(EBE(>E	?
E(	E
E(EE+E
E)E4E( EE(	E(E(EEE(E%EE%!E(ssl_contextserver_hostnamec                   K   t        |      \  }}|rt        |      }n|
<t        j                         }
t        j                  j
                  |
_        |d|
_        t        j                  j                  |      }t        |||      }||f}|	st        j                  j                         }	|	j                  |t        j                   d||||
|       d{   }|4 d{   }t#        |      }t%        | |||||||||	
       d{   }t'        j&                         }||z
  |_        |cddd      d{    S 7 g7 ^7 97 # 1 d{  7  sw Y   yxY ww)a  Return the response obtained after sending a query via TLS.

    *sock*, an ``asyncbackend.StreamSocket``, or ``None``, the socket
    to use for the query.  If ``None``, the default, a socket is
    created.  Note that if a socket is provided, it must be a
    connected SSL stream socket, and *where*, *port*,
    *source*, *source_port*, *backend*, *ssl_context*, and *server_hostname*
    are ignored.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.tls()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    NFr   )r   r   r   create_default_context
TLSVersionTLSv1_2minimum_versioncheck_hostnamer*   rJ   rK   r   rM   rN   rP   r   rx   r#   r_   r   )rC   rD   rE   r   rF   rG   r3   r6   r$   rH   ry   rz   rT   r!   rU   r   rV   rW   rX   r`   end_times                        r   tlsr     sg    :  .g6Z5@5F446K*-..*@*@K'&-2*XX$$U+r6;7&&::<G&&	
 	
   Q:&
 
 99; :-!  	

   sl   CED>
E!E "E%#EE	#E,E8E9E EEEEEEEi  z
/dns-queryTclientzhttpx.AsyncClientpathpostverifybootstrap_addressresolverzdns.asyncresolver.Resolverr;   c           
      @  K   t         st        |r%t        |t        j                        st        d      | j                         }	 t        j                  j                  |      }d}ddi}|mt        j                  j                  |      rN|t        j                  k(  rdj                  |||	      }n)|t        j                  k(  rdj                  |||	      }n|}t        j                  j!                         }|d}d}n|}|} |j#                         |dt$        |||||	      }|rt'        |      }nt        j                  dt$        ||
      }|4 d{   }|
rS|j)                  dt+        t-        |            d       |j/                  |j1                  ||      |       d{   }nbt3        j4                  |      j7                  d      }|j9                         }|j/                  |j;                  |d|i      |       d{   }ddd      d{    j<                  dk  s|j<                  dkD  r0t        dj                  ||j<                  |j>                              t        j@                  jC                  |j>                  | jD                  | jF                  ||      }|jH                  jK                         |_&        | jO                  |      stP        |S # t
        $ r d}Y w xY w7 7 U7 7 # 1 d{  7  sw Y   xY ww)a  Return the response obtained after sending a query via DNS-over-HTTPS.

    *client*, a ``httpx.AsyncClient``.  If provided, the client to use for
    the query.

    Unlike the other dnspython async functions, a backend cannot be provided
    in this function because httpx always auto-detects the async backend.

    See :py:func:`dns.query.https()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    z.session parameter must be an httpx.AsyncClientNacceptzapplication/dns-messagezhttps://{}:{}{}zhttps://[{}]:{}{}r   T)local_addresshttp1http2r   
local_portr   r   r;   )r   r   r   	transport)zcontent-typezcontent-length)headerscontent   =r*   )r   params   i+  z4{} responded with status code {}
Response body: {!r}rr   ))r   r
   r)   httpxAsyncClient
ValueErrorr-   r*   rJ   rK   
is_addressr   r   formatr   rM   rN   get_transport_classr   r   updatestrrd   wait_forr   base64urlsafe_b64encoderstripdecodegetstatus_coder   r+   r<   r4   r5   elapsedtotal_secondsr   rS   r	   )rC   rD   rE   r   rF   rG   r3   r6   r   r   r   r   r   r   r;   r=   r   r   r   urlrH   r   r   rU   
the_clientr`   twirer@   s                               r   httpsr     s    : j):):;IJJ99;DXX$$U+ I23G	~#((--e4#**5$=C6??"%,,UD$?C224G~
 
-++-#+	I 5@5Hk&I
   Z NN$=&)#d)n %--WdCW H ++D188>DKKME$--sGUENKW H! , c!X%9%9C%?$$*Fx++X-=-=%
 	
 			MM)' 	 	A ++-AF==H[  L!   s   ALK- &C3LK?LAL	-L.A"L	LL	L L!CL-K<8L;K<<LL	L	L	LLLLtxn_managerquerylifetimeudp_modec
                   K   |#t         j                  j                  |      \  }}
nt         j                  j                  |      }
|j                  d   j
                  }|t         j                  j                  k(  }|j                         }|j                         }t         j                  j                  |       }t        |||      }| |f}t        |      \  }}d}|rd}|r&|t        j                  k7  rt         j"                  }d}nt         j$                  }d}|	st         j&                  j)                         }	|	j+                  ||d||t-        |             d{   }|4 d{    |r%|j/                  ||t-        |             d{    n<t1        j2                  dt5        |            |z   }|j7                  ||       d{    t         j                  j9                  |||
|      5 }d}d}|st        |      \  }}||||kD  r|}|rGt;        | |f|      }	 t-        |      }|j=                  d|       d{   \  }}t?        |||d      rnC8tA        |d|       d{   } t1        jB                  d|       \  }!tA        ||!|       d{   }|t         j                  j                  k(  }t         jD                  jG                  ||jH                  |jJ                  d||| |      }"	 |jM                  |"      }|"jR                  }|s|s7|jH                  r+"jT                  st         jV                  jY                  d	      ddd       ddd      d{    |ryy7 7 7 7 7 87 7 # t         j                  jN                  $ r0 |sJ |t        jP                  k(  r d}d}t        j                  }Y w xY w# 1 sw Y   xY w7 z# 1 d{  7  sw Y   xY ww)
am  Conduct an inbound transfer and apply it via a transaction from the
    txn_manager.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.inbound_xfr()` for the documentation of
    the other parameters, exceptions, and return type of this method.
    Nr   TFrc   r9   rq   )r4   r5   xfrorigintsig_ctxmultir3   zmissing TSIG)-r*   r   
make_queryextract_serial_from_queryquestionrdtype	rdatatypeIXFRfrom_wire_originr-   rJ   rK   r   r   r   NEVERr   rQ   rx   rM   rN   rP   r#   r.   re   rf   rd   rg   InboundrL   r:   r   ro   rs   r+   r<   r4   rR   process_messageUseTCPONLYr   had_tsig	exception	FormError)#rD   r   r   r   rE   r   rF   rG   r   rH   serialr   is_ixfrr   r=   r   rV   rW   rY   r!   retry	sock_typeis_udprX   ri   inbounddoner   mexpirationr&   rwirer>   rt   rh   r@   s#                                      r   inbound_xfrr   V  s    * }'',,[92259^^A%%F***G))+F==?D		 	 	'B2v{3FT]F$X.OQ
E
x7==0))IF**IF&&::<G%%	1ffhz.B
 
  3	B 3	BhhtVXj-ABBBT3t95<ii
333fffE -B'5g'>$Q"*".;3K&0&.t}b&A"&.{&;G:;**UG:T4T1UL3 "L+t  !& # '4Aq+&F F%}}T59&3Aq+&F F$(:(::G-- %$)II %!)#)z)0 . 	A	!&66q9  !zzHQ R qzz--11.AA[-B3	B 3	B 
3	BB 4 5U !G F 77>> !%#w||3!# $#*== !G-B -B3	B 3	B 3	B 3	Bs   EO8M1
O8)M4*O8-"O#M7<O#M:&O#3AOM='O-N .,ONAO9N
O9OO#O8&O!'O8/O84O87O#:O#=O OOA	OOOOO	O#!O8#O5)O,*O51O8
connectionc           	        K   t         j                  j                  st        d      d| _        | j                         }|r7t         j                  j                  }t         j                  j                  }|}n"t         j                  j                  |
      \  }} |       4 d{   } |||	|      4 d{   }|s|j                  ||||      }t        |      \  }}j                  |       d{   }|4 d{    |j                  |d       d{    |j                  t        |             d{   }ddd      d{    t        j                         }ddd      d{    t         j                  j!                  || j"                  | j$                  ||      }ddd      d{    t'        z
  d      _        | j)                  |      st*        |S 7 F7 57 7 7 7 7 # 1 d{  7  sw Y   xY w7 # 1 d{  7  sw Y   xY w7 m# 1 d{  7  sw Y   }xY ww)ai  Return the response obtained after sending an asynchronous query via
    DNS-over-QUIC.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.quic()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    zDNS-over-QUIC is not available.r   N)verify_modeserver_nameTrr   g        )r*   quic	have_quicr   idr-   null_factoryfactories_for_backendconnectr   make_streamsendreceiver   r   r+   r<   r4   r5   r    rS   r	   )rC   rD   rE   r   rF   rG   r3   r6   r   r   rH   rz   r=   cfactorymfactorythe_connectioncontextthe_managerstartr!   streamfinishr@   s                          r   r   r     s    0 88566AD99;D88((88((#"xx==gF8z 
 
W_
 
	! 
	!!,!4!4UD&+!V"0"9UJ)55g>>F D Dkk$---#^^Jz,BCCD D YY[F
	! 
	! KK!!II-+ " 

 
& %%AF==H-

	! ?D-CD D D D
	! 
	! 
	! 
	!
 
 
 
s  B#H>%G+&H>)H)9G.:H)=9H6G17
HG3
HG;G5
!G;=G7
>G;HG9H&H)1H2<H).H>9H':2H>.H)1H3H5G;7G;9H;HHH	HH)H$	HH$	 H)'H>)H;/H20H;7H>)N)NNFFNr   FF)
NrB   Nr   FFFFNN)
NrB   Nr   FFFNNN)NFNr   F)NrB   Nr   FFNN)
NU  Nr   FFNNNN)
Nr   Nr   FFNTNN)K__doc__r   
contextlibr   re   r   typingr   r   r   r   r   dns.asyncbackendr*   dns.exceptiondns.inetdns.messagedns.namedns.quic	dns.rcodedns.rdataclassdns.rdatatypedns.transactiondns._asyncbackendr   	dns.queryr	   r
   r   r   r   r   r   r   r   r   r   rJ   low_level_address_tuplerL   r   r#   rM   DatagramSocketr+   r,   bytesfloatintr1   boolnameNametsigKeyrA   r   BackendrZ   StreamSocketra   rj   ro   ru   r_   
SSLContextr   	AF_UNSPECr   r   transactionTransactionManagerr   r   AsyncQuicConnection r   r   <module>r     s	  $       4 4           )    88++  #'	



)
)
##U*
+  	
 3:@ "&"&#";?#&! %&,



)
)&,#&, &, 	&,
 &, d388==#((,,678&, %&, &, &, 	&,X  $ #"! %6:26:
{{:: e_: 	:
 SM: : : : : : 3##22
3: c&&../: 	[[:@  $ #"!:>8<26? 
{{? ?  e_?  	? 
 SM?  ?  ?  ?  ?  s''667?  s''445?  c&&../?  3;;$%? J #'$



'
'$
##U*
+$ $ 3:	$6  #'";?#&!



'
'  d388==#((,,678	
 %  3;;%&B  $ "!48265
{{55 e_5 	5
 SM5 5 5 5 3##00
15 c&&../5 	[[5v  $ "!4826,0%)F
{{FF e_F 	F
 SMF F F F 3##00
1F c&&../F #..)F c]F 	[[FX  $ "!,0#'+7;",,r
{{rr e_r 	r
 SMr r r r ()r r r $)r  }r 34r SMr  	[[!rp ,0# $ 26bBbB33bB CKK''(bB 	bB
 e_bB uobB SMbB bB bB c&&../bB 
bBP  $ "!9=#26%);
{{;; e_; 	;
 SM; ; ; ; 556; $); c&&../; c]; 	[[;r   