
    ,h $                         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  G d de      Z G d de      Z G d d	e      Zy)
    N)NullContext)QUIC_MAX_DATAGRAMAsyncQuicConnectionAsyncQuicManagerBaseQuicStreamUnexpectedEOFc                   R     e Zd Z fdZd Zd Zd
dZddZd Zd Z	d Z
d	 Z xZS )TrioQuicStreamc                 X    t         |   ||       t        j                         | _        y N)super__init__trio	Condition_wake_up)self
connection	stream_id	__class__s      P/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/dns/quic/_trio.pyr   zTrioQuicStream.__init__   s     Y/(    c                 &  K   	 | j                   j                  |      ry || _        | j                  4 d {    | j                  j	                          d {    d d d       d {    d| _        r7 >7 7 # 1 d {  7  sw Y    xY ww)Nr   )_bufferhave
_expectingr   wait)r   amounts     r   wait_forzTrioQuicStream.wait_for   s     ||  ($DO}} + +mm((***+ +DO +*+ + + +sV   5BA6BA<A8A<B)A:*B8A<:B<BBB
Bc                   K   	 | j                   j                         ry | j                  4 d {    | j                  j                          d {    d d d       d {    c7 77 7 	# 1 d {  7  sw Y   xY wwr   )r   seen_endr   r   r   s    r   wait_for_endzTrioQuicStream.wait_for_end'   sq     ||$$&}} + +mm((***+ + +*+ + + +sV   -BA'BA-A)A-B!A+"B)A-+B-A?3A64A?;Bc                 d  K   |t        d       }nt        j                  |      }|5  | j                  j	                         r;| j                          d {    | j                  j                         cd d d        S | j                  d       d {    t        j                  d| j                  j                  d            \  }| j                  |       d {    | j                  j                  |      cd d d        S 7 7 t7 ,# 1 sw Y   t        j                  j                  xY ww)N   z!H)r   r   move_on_after_connectionis_h3r"   r   get_allr   structunpackgetdns	exceptionTimeout)r   timeoutcontextsizes       r   receivezTrioQuicStream.receive.   s     ?!$'G((1G 	.%%''')))||++-	. 	.
 mmA&&& --dll.>.>q.ABmmD)))||''-	. 	.) ')	. mm###s_   &D0.DDD4
D0>DDA	DD	D;
D0DD	DD- D0c                    K   | j                  |      }| j                  j                  | j                  ||       d {    y 7 wr   )_encapsulater&   write
_stream_id)r   datagramis_enddatas       r   sendzTrioQuicStream.send>   s8       *$$T__dFCCCs   <AAAc                    K   | j                  ||      r@| j                  4 d {    | j                  j                          d d d       d {    y y 7 07 # 1 d {  7  sw Y   y xY wwr   )_common_add_inputr   notify)r   r9   r8   s      r   
_add_inputzTrioQuicStream._add_inputB   sf     !!$/}} ' '$$&' ' ' 0' ' ' ' 'sD   #A/AA/AA/AA/A/A, A#!A,(A/c                 ,   K   | j                          y wr   )_closer!   s    r   closezTrioQuicStream.closeG   s     s   c                    K   | S wr    r!   s    r   
__aenter__zTrioQuicStream.__aenter__L           c                    K   | j                          d {    | j                  4 d {    | j                  j                          d d d       d {    y7 D7 17 	# 1 d {  7  sw Y   yxY wwNF)rA   r   r=   )r   exc_typeexc_valexc_tbs       r   	__aexit__zTrioQuicStream.__aexit__O   sg     jjl== 	# 	#MM  "	# 	# 		# 	# 	# 	# 	#sT   A6AA6AA6A!
A6AA6A6A6!A3'A*(A3/A6r   F)__name__
__module____qualname__r   r   r"   r2   r:   r>   rA   rD   rL   __classcell__r   s   @r   r
   r
      s1    ) +$ D'

r   r
   c                   H     e Zd Zd fd	Zd Zd Zd	dZd ZddZd Z	 xZ
S )
TrioQuicConnectionc                 *   t         |   ||||||       t        j                  j                  | j                  t        j
                  d      | _        t        j                         | _        t        j                         | _	        d | _
        d| _        y )Nr   F)r   r   r   socket_af
SOCK_DGRAM_socketEvent_handshake_complete	_run_done_worker_scope_send_pending)r   r   addressportsourcesource_portmanagerr   s          r   r   zTrioQuicConnection.__init__W   si    WdFKQ{{))$((F4E4EqI#'::< !"r   c                    K   	 | j                   rU| j                  j                  t        j                  j                  | j                   | j                               d {    | j                  j                  | j                         d {    | j                  sZ| j                  d      \  }}| j                  rd}t        j                  t        j                         |z         5 | _        | j                  j!                  t"               d {   }| j$                  j'                  || j                  t)        j(                                d d d        d | _        | j+                  |       | j-                          d {    d| _        | j$                  j/                  t)        j(                               }|D ](  \  }}| j                  j1                  |       d {    * | j                  sZd| _	        | j                  j3                          | j4                  j7                          y 7 7 7 '# 1 sw Y   xY w7 7 g# d| _	        | j                  j3                          | j4                  j7                          w xY ww)NFg        )deadlineT)_sourcerY   bindr,   inetlow_level_address_tuplerW   connect_peer_done_get_timer_valuesr^   r   CancelScopecurrent_timer]   recvr   r&   receive_datagramtime_handle_timer_handle_eventsdatagrams_to_sendr:   rA   r[   set)r   
expirationintervalr7   	datagrams_s         r   _workerzTrioQuicConnection._worker_   s    "	+||ll''HH44T\\488L   ,,&&tzz222jj)-)?)?)F&X%%  #H%%!..08; Y'%)\\%6%67H%IIH$$55h

DIIKX	Y
 &*""":.))+++ &+" ,,>>tyy{K	#, 6KHa,,++H5556/ jj4 DJLL $$((*A 3  JY Y , 6DJLL $$((*s   JAI  H5!,I H8AI ,(H>H;=H>3I I
AI $I%I 9<J5I 8I ;H>>II I =JJc                   K   d}	 | j                   j                         }|y t        |t        j                  j
                  j                        r| j                         re| j                  j                  |      }|D ]B  }t        |t        j                  j
                  j                        r| j                  j                  |j                        }|sZ|j                  |j                   |_        n|j"                  |j                   |_        |j$                  s|j'                  dd       d {    t        |t        j                  j
                  j(                        s| j                  j                  |j                        }|s|j'                  |j*                  |j$                         d {    E n`| j                  j                  |j                        }|r8|j'                  |j*                  |j,                         d {    nt        |t        j                  j
                  j.                        r| j0                  j3                          nt        |t        j                  j
                  j4                        r"d| _        | j8                  j;                          not        |t        j                  j
                  j<                        rA| j                  j                  |j                        }|r|j'                  dd       d {    |dz  }|dkD  rd}t?        j@                  d       d {    M7 7 7 @7 87 w)Nr   Tr      
   )!r&   
next_event
isinstanceaioquicquiceventsStreamDataReceivedr'   _h3_connhandle_eventh3HeadersReceived_streamsr+   r   _headersheaders	_trailersstream_endedr>   DataReceivedr9   
end_streamHandshakeCompletedr[   rv   ConnectionTerminatedrl   rY   rA   StreamResetr   sleep)r   countevent	h3_eventsh3_eventstreams         r   rt   z!TrioQuicConnection._handle_events   s    $$//1E}%!4!4!G!GH::< $ : :5 AI$- "%h

0A0A0Q0QR%)]]%6%6u%GF%#)??#:6>6F6FFO%+%5%5%=7?7G7GF$4#+#8#8*0*;*;C*F$F$F''**2C2C2P2PQ%)]]%6%6u%GF%&,&7&7$,MM83H3H'" !" !""" "]]..u?F$//

E<L<LMMME7<<#6#6#I#IJ((,,.E7<<#6#6#K#KL!
""$E7<<#6#6#B#BC**5??; ++C666QJErzjjm##Q   %G!" N 7
 $su   CM AM "M 7M83M ,'M )M >M?AM MD	M #M$(M MM M M M M c                    K   | j                   j                  |||       d| _        | j                  | j                  j	                          y y w)NT)r&   send_stream_datar^   r]   cancel)r   r   r9   r8   s       r   r5   zTrioQuicConnection.write   sI     ))&$?!)%%' *s   AAc                   K   | j                   ry t        j                         4 d {   }|j                  | j                         d d d       d {    | j
                  j                          y 7 J7 !# 1 d {  7  sw Y   1xY wwr   )_closedr   open_nursery
start_soonr{   r\   rv   )r   nurserys     r   runzTrioQuicConnection.run   so     <<$$& 	- 	-'t||,	- 	-	- 	- 	- 	- 	-sD   &BA3BA7BA5 B5B7B	=B >B	Bc                   K   |t        d       }nt        j                  |      }|5  | j                  j	                          d {    | j
                  rt        | j                  j                  d      }t        | |      }|| j                  |<   |cd d d        S 7 W# 1 sw Y   t        j                  j                  xY wwrH   )r   r   r%   r[   r   rl   r   r&   get_next_available_stream_idr
   r   r,   r-   r.   )r   r/   r0   r   r   s        r   make_streamzTrioQuicConnection.make_stream   s     ?!$'G((1G 	**//111zz##((EEeLI#D)4F'-DMM)$	 	1	 mm###s/   &CB BAB 
CB  C% Cc                 v  K   | j                   s| j                  j                  | j                  d   | j                  d          d| _         | j                  j                          d| _        | j                  | j                  j                          | j                  j                          d {    y y 7 w)Nr   r}   T)r   _managerclosedrk   r&   rA   r^   r]   r   r\   r   r!   s    r   rA   zTrioQuicConnection.close   s     ||MM  A

1>DL""$!%D!!-""))+..%%'''  (s   B.B90B71B9r   rM   )rN   rO   rP   r   r{   rt   r5   r   r   rA   rQ   rR   s   @r   rT   rT   V   s(    ##+J*$X($(r   rT   c                   R     e Zd Zdej                  ddf fd	Z	 ddZd Zd Z xZ	S )TrioQuicManagerNFc                 B    t         |   ||t        ||       || _        y r   )r   r   rT   _nursery)r   r   confverify_modeserver_namer   r   s         r   r   zTrioQuicManager.__init__   s"     	{,>RPr   c                     | j                  |||||      \  }}|r%| j                  j                  |j                         |S r   )_connectr   r   r   )r   r_   r`   ra   rb   want_session_ticketr   starts           r   rj   zTrioQuicManager.connect   sD     #mmT6;0C
U MM$$Z^^4r   c                    K   | S wr   rC   r!   s    r   rD   zTrioQuicManager.__aenter__   rE   rF   c                    K   t        | j                  j                               }|D ]  }|j                          d {     y7 wrH   )list_connectionsvaluesrA   )r   rI   rJ   rK   connectionsr   s         r   rL   zTrioQuicManager.__aexit__   sJ      4,,3356% 	%J""$$$	% %s   <AAA)iU  Nr   T)
rN   rO   rP   sslCERT_REQUIREDr   rj   rD   rL   rQ   rR   s   @r   r   r      s2     %%	  RVr   r   )rV   r   r)   rr   aioquic.quic.configurationr   aioquic.quic.connectionaioquic.quic.eventsr   dns.exceptionr,   dns.inetdns._asyncbackendr   dns.quic._commonr   r   r   r   r   r
   rT   r   rC   r   r   <module>r      s\     
   !      ) :^ :z~(, ~(B& r   