
    mbi                    L   d dl mZ d dlZd dlZd dlZd dlZd dlmZm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 ddlmZmZ ddlmZmZm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& d
dl'm(Z(  ej)        d          Z*dgZ+dZ, ej-        d          Z. G d de          Z/ G d de          Z0 G d de          Z1 G d de          Z2 G d de          Z3 G d de4          Z5 G d de5          Z6 G d d e5          Z7 G d! d"e5          Z8 G d# d$e5          Z9 G d% d&e5          Z: G d' d(e5          Z; G d) d*e5          Z< G d+ d,e5          Z= G d- d.e5          Z>dMd4Z?dNd7Z@dOd9ZAdPd:ZB	 dQdRdBZCdSdDZDdSdEZEdTdGZFdSdHZG G dI dJ          ZH G dK dL          ZIdS )U    )annotationsN)EnumIntEnum   )UINT_VAR_MAX_SIZE)	BufferBufferReadErrorDecoderStreamErrorDecompressionFailedEncoderStreamErrorQpackDecoderQpackEncoderStreamBlockedencode_uint_var)QuicConnectionstream_is_unidirectional)DatagramFrameReceived	QuicEventStreamDataReceived)QuicLoggerTrace   )DatagramReceivedDataReceivedH3EventHeadersHeadersReceivedInformationalHeadersReceivedPushPromiseReceivedWebTransportStreamDataReceived)NoAvailablePushIDErrorhttp3h3)r   r            s   [A-Z]c                  ^    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZdZdS )	ErrorCode   i  i  i  i  i  i  i  i  i	  i
  i  i  i  i  i  i  i   i  i  N)__name__
__module____qualname__H3_NO_ERRORH3_GENERAL_PROTOCOL_ERRORH3_INTERNAL_ERRORH3_STREAM_CREATION_ERRORH3_CLOSED_CRITICAL_STREAMH3_FRAME_UNEXPECTEDH3_FRAME_ERRORH3_EXCESSIVE_LOADH3_ID_ERRORH3_SETTINGS_ERRORH3_MISSING_SETTINGSH3_REQUEST_REJECTEDH3_REQUEST_CANCELLEDH3_REQUEST_INCOMPLETEH3_MESSAGE_ERRORH3_CONNECT_ERRORH3_VERSION_FALLBACKQPACK_DECOMPRESSION_FAILEDQPACK_ENCODER_STREAM_ERRORQPACK_DECODER_STREAM_ERROR     a/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/qh3/h3/connection.pyr'   r'   +   s        K %$ %NK !!&!&!&rA   r'   c                  6    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdS )	FrameTyper   r   r   r#   r$   r%            A   N)r)   r*   r+   DATAHEADERSPRIORITYCANCEL_PUSHSETTINGSPUSH_PROMISEGOAWAYMAX_PUSH_IDDUPLICATE_PUSHWEBTRANSPORT_STREAMr@   rA   rB   rD   rD   B   sC        DGHKHLFKNrA   rD   c                      e Zd ZdZdZdZdS )HeadersStater   r   r   N)r)   r*   r+   INITIALAFTER_HEADERSAFTER_TRAILERSr@   rA   rB   rT   rT   O   s        GMNNNrA   rT   c                  *    e Zd ZdZdZdZdZdZdZdZ	dS )	Settingr      rE      iw iB7`+!   N)
r)   r*   r+   QPACK_MAX_TABLE_CAPACITYMAX_FIELD_SECTION_SIZEQPACK_BLOCKED_STREAMSENABLE_CONNECT_PROTOCOLH3_DATAGRAMENABLE_WEBTRANSPORTDUMMYr@   rA   rB   rY   rY   U   s:        "  "K$ EEErA   rY   c                  "    e Zd ZdZdZdZdZdZdS )
StreamTyper   r   r   r#   T   N)r)   r*   r+   CONTROLPUSHQPACK_ENCODERQPACK_DECODERWEBTRANSPORTr@   rA   rB   re   re   f   s'        GDMMLLLrA   re   c                  *    e Zd ZdZej        ZdddZdS )	ProtocolErrorz
    Base class for protocol errors.

    These errors are not exposed to the API user, they are handled
    in :meth:`H3Connection.handle_event`.
     reason_phrasestrc                    || _         d S N)ro   )selfro   s     rB   __init__zProtocolError.__init__x   s    *rA   N)rn   )ro   rp   )r)   r*   r+   __doc__r'   r-   
error_codert   r@   rA   rB   rm   rm   n   sA          4J+ + + + + + +rA   rm   c                      e Zd Zej        ZdS )QpackDecompressionFailedN)r)   r*   r+   r'   r=   rv   r@   rA   rB   rx   rx   |           5JJJrA   rx   c                      e Zd Zej        ZdS )QpackDecoderStreamErrorN)r)   r*   r+   r'   r?   rv   r@   rA   rB   r{   r{      ry   rA   r{   c                      e Zd Zej        ZdS )QpackEncoderStreamErrorN)r)   r*   r+   r'   r>   rv   r@   rA   rB   r}   r}      ry   rA   r}   c                      e Zd Zej        ZdS )ClosedCriticalStreamN)r)   r*   r+   r'   r0   rv   r@   rA   rB   r   r      s        4JJJrA   r   c                      e Zd Zej        ZdS )FrameUnexpectedN)r)   r*   r+   r'   r1   rv   r@   rA   rB   r   r              .JJJrA   r   c                      e Zd Zej        ZdS )MessageErrorN)r)   r*   r+   r'   r:   rv   r@   rA   rB   r   r      s        +JJJrA   r   c                      e Zd Zej        ZdS )MissingSettingsErrorN)r)   r*   r+   r'   r6   rv   r@   rA   rB   r   r      r   rA   r   c                      e Zd Zej        ZdS )SettingsErrorN)r)   r*   r+   r'   r5   rv   r@   rA   rB   r   r      s        ,JJJrA   r   c                      e Zd Zej        ZdS )StreamCreationErrorN)r)   r*   r+   r'   r/   rv   r@   rA   rB   r   r      s        3JJJrA   r   
frame_typeint
frame_databytesreturnc                    t          |          }t          |dt          z  z             }|                    |            |                    |           |                    |           |j        S )Nr   capacity)lenr   r   push_uint_var
push_bytesdata)r   r   frame_lengthbufs       rB   encode_framer      si    z??L
,->)>>
?
?
?Cj!!!l###NN:8OrA   settingsdict[int, int]c                    t          d          }|                                 D ]/\  }}|                    |           |                    |           0|j        S )Ni   r   )r   itemsr   r   )r   r   settingvalues       rB   encode_settingsr      sa    
$


C"..** ! !'"""%    8OrA   r   c                z    t          |           }|                                }|                                sJ |S )Nr   )r   pull_uint_vareof)r   r   max_push_ids      rB   parse_max_push_idr      s=    
d


C##%%K7799rA   c                X   t          |           }i }|                                sv|                                }|                                }|t          v rt	          d|dd          ||v rt	          d|dd          |||<   |                                vt          |          S )Nr   zSetting identifier 0xxz is reserved is included twice)r   r   r   RESERVED_SETTINGSr   dict)r   r   r   r   r   s        rB   parse_settingsr      s    
d


C!Hggii "##%%!!##''' O O O O OPPPh U U U U UVVV! ggii " >>rA   headersr   allowed_pseudo_headersfrozenset[bytes]required_pseudo_headersextract_headerbytes | Nonec                z   d}d }d }d }t                      }d }	| D ]\  }
}t                              |
          rt          d|
d          ||	|}	|
                    d          rs|rt          d|
d          |
|vrt          d|
d          |
|v rt          d|
d          |                    |
           |
d	k    r|}|
d
k    r|}|
dk    r|}d}|                    |          }|r t          dt          |           d          |dv r"|st          d          |st          d          |	S )NFzHeader z contains uppercase letters   :zPseudo-header z% is not allowed after regular headersz is not validr   
   :authority   :path   :schemeTzPseudo-headers z are missing)s   https   httpsz+Pseudo-header b':authority' cannot be emptyz&Pseudo-header b':path' cannot be empty)set	UPPERCASEsearchr   
startswithadd
differencesorted)r   r   r   r   after_pseudo_headers	authoritypathschemeseen_pseudo_headersextracted_header_valuekeyr   missings                rB   validate_headersr      s    !"IDF&)ee+/ ( (
UC   	MKKKKLLL%*@*H%*">>$ 	(# "QSQQQ   000"#HC#H#H#HIII)))"#MC#M#M#MNNN##C((( m##!		
"" $(   &001DEEG LJVG__JJJKKK$$$ 	NLMMM 	IGHHH!!rA   Nonec                ^    t          | t          d          t          d                     d S )N)   :methodr   r   r   r   r   r   	frozensetr   s    rB   validate_push_promise_headersr      sH    (= 
  
 !*=!
 !
     rA   c                ^    t          | t          d          t          d                     d S )N)r   r   r   r   s	   :protocol)r   r   r   r   r   s    rB   validate_request_headersr     sG    ( L 
  

 !**E F F     rA   
int | Nonec                    t          | t          d          t          d          d          }|d S 	 t          |          S # t          $ r Y d S w xY w)N)   :statusr   )r   r   r   )r   r   r   
ValueError)r   status_codes     rB   validate_response_headersr     st     0(77 )- 8 8!	! ! !K t;   tts   A 
AAc                Z    t          | t                      t                                 d S )Nr   r   r   s    rB   validate_trailersr   )  s4    ({{ )     rA   c                  &    e Zd Zd
dZddZddZd	S )H3Stream	stream_idr   r   r   c                    d| _         d | _        d| _        d| _        d | _        d | _        t          j        | _        t          j        | _	        d | _
        d | _        || _        d | _        d| _        d| _        d S )NFrA   )blockedblocked_frame_sizebufferended
frame_sizer   rT   rU   headers_recv_stateheaders_send_statepush_id
session_idr   stream_typereceiving_endedsending_ended)rs   r   s     rB   rt   zH3Stream.__init__2  sv    .2
&*&*0<0D0<0D#'&*"'+$"rA   boolc                .    | j         o| j        o| j         S rr   )r   r   r   rs   s    rB   is_endedzH3Stream.is_endedB  s    !Od&:O4<?OOrA   c                @    | j         rt          d          d| _         d S )Nzstream was already endedT)r   r   r   s    rB   finish_sendingzH3Stream.finish_sendingE  s*     	>!"<===!rA   N)r   r   r   r   )r   r   r   r   )r)   r*   r+   rt   r   r   r@   rA   rB   r   r   1  sT        # # # # P P P P" " " " " "rA   r   c                     e Zd ZdZd<d=d	Z	 d<d>dZd?dZd@dZdAdZdBdZ		 d<dCdZ
edDd            ZedDd            ZdEdFd$ZdGd'ZdHd(Zej        dId*            ZdJd,ZdKd.ZdLd2ZdMd3Z	 dEdNd4ZdOd5ZdPd7ZdQd8ZdQd9ZdRd;Zd S )SH3Connectionzu
    A low-level HTTP/3 connection object.

    :param quic: A :class:`~qh3.connection.QuicConnection` instance.
    Fquicr   enable_webtransportr   r   r   c                   d| _         d| _        || _        |j        j        | _        d| _        || _        |j        | _        t          | j         | j                  | _
        d| _        d| _        t                      | _        d| _        d| _        d| _        i | _        | j        rdnd | _        d| _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        i | _        |                                  d S )Ni      Fr   r[   )_max_table_capacity_blocked_streams_enable_webtransportconfiguration	is_client
_is_client_is_done_quic_quic_loggerr   _decoder_decoder_bytes_received_decoder_bytes_sentr   _encoder_encoder_bytes_received_encoder_bytes_sent_settings_received_stream_max_push_id_next_push_id_local_control_stream_id_local_decoder_stream_id_local_encoder_stream_id_peer_control_stream_id_peer_decoder_stream_id_peer_encoder_stream_id_received_settings_sent_settings_blocked_stream_map_init_connection)rs   r   r   s      rB   rt   zH3Connection.__init__S  s   #'  "$7!,6
484E$T%=t?TUU'($#$ $'($#$ "',.-1_(F$"#48%48%48%37$37$37$9=598: rA   r   r   is_unidirectionalc                   |rH|                      t          j                  }| j                            |t          |                     n|| j                                        }|                     |t          j                   | j                            |t          t          j	                  t          |          z              |S )z
        Create a WebTransport stream and return the stream ID.

        :param session_id: The WebTransport session identifier.
        :param is_unidirectional: Whether to create a unidirectional stream.
        r   r   )
_create_uni_streamre   rk   r   send_stream_datar   get_next_available_stream_id_log_stream_typerD   rR   )rs   r   r  r   s       rB   create_webtransport_streamz'H3Connection.create_webtransport_streamw  s      	//
0GHHIJ''	?:3N3NOOOO
??AAI!!#1H "    J''	 =>>!*--.  
 rA   eventr   list[H3Event]c                R   | j         s	 t          |t                    r|                     |          S t          |t                    r|                     |j                  S nD# t          $ r7}d| _         | j        	                    |j
        |j                   Y d}~nd}~ww xY wg S )zx
        Handle a QUIC event and return a list of HTTP events.

        :param event: The QUIC event to handle.
        T)rv   ro   N)r   
isinstancer   _receive_stream_datar   _receive_datagramr   rm   r   closerv   ro   )rs   r  excs      rB   handle_eventzH3Connection.handle_event  s     } 
		e%788 >44U;;;'<== >11%*===>     $
  "~S=N !         	s   )A# .A# #
B$--BB$flow_idr   r   c                Z    | j                             t          |          |z              dS )z
        Send a datagram for the specified flow.

        :param flow_id: The flow ID.
        :param data: The HTTP/3 datagram payload.
        N)r   send_datagram_framer   )rs   r%  r   s      rB   send_datagramzH3Connection.send_datagram  s-     	
&&w'?'?$'FGGGGGrA   r   r   r   c                   | j         r
J d            | j        | j        | j        k    rt          | j        }| xj        dz  c_        | j                            |t          t          j        t          |          | 
                    ||          z                        |                     t          j        |          }| j                            |t          |                     |S )a  
        Send a push promise related to the specified stream.

        Returns the stream ID on which headers and data can be sent.

        :param stream_id: The stream ID on which to send the data.
        :param headers: The HTTP request headers for this push.
        z%Only servers may send a push promise.Nr   )r   )r   r  r	  r    r   r  r   rD   rN   r   _encode_headersr  re   rh   )rs   r   r   r   push_stream_ids        rB   send_push_promisezH3Connection.send_push_promise  s     ?KK$KKKK$(:d>O(O(O(( $a
##&((4+?+?	7+S+SS 	
 	
 	
 00'0RR
##NOG4L4LMMMrA   
end_streamc           	        |                      |          5 }|j        t          j        k    rt	          d          |r|                                 ddd           n# 1 swxY w Y   | j        D| j                            dd| j                            t          |          |                     | j
                            |t          t          j        |          |           dS )a  
        Send data on the given stream.

        To retrieve datagram which need to be sent over the network call the QUIC
        connection's :meth:`~qh3.connection.QuicConnection.datagrams_to_send`
        method.

        :param stream_id: The stream ID on which to send the data.
        :param data: The data to send.
        :param end_stream: Whether to end the stream.
        'DATA frame is not allowed in this stateNhttpframe_createdlengthr   categoryr  r   )_get_or_create_streamr   rT   rV   r   r   r   	log_eventencode_http3_data_framer   r   r  r   rD   rI   )rs   r   r   r-  streams        rB   	send_datazH3Connection.send_data  s4    ''	22 	(f(L,FFF%&OPPP (%%'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( (''%&>>t99	 ?   (    	
##|IND99:	
 	
 	
 	
 	
s   ;AA!$A!c           
        |                      |          5 }|j        t          j        k    rt	          d          |r|                                 |                     ||          }| j        E| j                            dd| j        	                    t          |          ||                     |j        t          j        k    r\d}| j        s?|s=|D ]:\  }}|dk    rt          |          d	k     rd
} n#|                    d          s n;|st          j        |_        nt          j        |_        | j                            |t%          t&          j        |          |           ddd           dS # 1 swxY w Y   dS )a  
        Send headers on the given stream.

        To retrieve datagram which need to be sent over the network call the QUIC
        connection's :meth:`~qh3.connection.QuicConnection.datagrams_to_send`
        method.

        :param stream_id: The stream ID on which to send the headers.
        :param headers: The HTTP headers to send.
        :param end_stream: Whether to end the stream.
        *HEADERS frame is not allowed in this stateNr0  r1  r3  r   r   r4  Fr      Tr   )r6  r   rT   rW   r   r   r*  r   r7  encode_http3_headers_framer   rU   r   r   r   rV   r   r  r   rD   rJ   )	rs   r   r   r-  r9  r   is_informational_headerskvs	            rB   send_headerszH3Connection.send_headers  s    ''	22 '	f(L,GGG%&RSSS (%%'''--iAAJ  ,!++#)*EE":9 F   ,    (L,@@@+0( "z " ' " "1
??"1vv||;? 8 %  , "#d!3!3 "!E" 0 K0<0JF-,8,G)J''<	(9:FF
  K'	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	 '	s   EE66E:=E:dict[int, int] | Nonec                    | j         S )z>
        Return the received SETTINGS frame, or None.
        )r  r   s    rB   received_settingszH3Connection.received_settings%  s    
 &&rA   c                    | j         S )z:
        Return the sent SETTINGS frame, or None.
        )r  r   s    rB   sent_settingszH3Connection.sent_settings,  s    
 ""rA   Nr   r   r   c                    | j                             d          }|                     |||           | j                             |t	          |                     |S )zD
        Create an unidirectional stream of the given type.
        T)r  r   r   r   )r   r  r  r  r   )rs   r   r   r   s       rB   r  zH3Connection._create_uni_stream3  sh     J;;d;SS	yk 	 	
 	
 	
 	
##I{/K/KLLLrA   r   r   c                l   	 |#| j         |         j        \  }}| j         |         `n.|st                      | j                            ||          \  }}| xj        t          |          z  c_        | j                            | j	        |           n!# t          $ r}t                      |d}~ww xY w|S )z
        Decode a HEADERS block and send decoder updates on the decoder stream.

        This is called with frame_data=None when a stream becomes unblocked.
        N)r  _pendingr   r   feed_headerr  r   r   r  r  rx   )rs   r   r   decoderr   r#  s         rB   _decode_headerszH3Connection._decode_headers>  s    	6!#'#;I#F#O ,Y7@@ " 0-///#'=#<#<Y
#S#S $$G4$$J''(EwOOOO" 	6 	6 	6*,,#5	6 s   BB 
B1B,,B1c                   	 | j                             ||          \  }}n!# t          $ r}t                      |d}~ww xY w| xj        t          |          z  c_        | j                            | j        |           |S )zX
        Encode a HEADERS block and send encoder updates on the encoder stream.
        N)	r  encoder   r}   r  r   r   r  r  )rs   r   r   encoderr   r#  s         rB   r*  zH3Connection._encode_headersU  s    	5"&-"6"6y'"J"JGZZ! 	5 	5 	5)++4	5 	  CLL0  
##D$A7KKKs   ! 
?:?typing.Generator[H3Stream]c              #     K   || j         vrt          |          | j         |<   | j         |         }	 |V  |                                r
| j         |= d S d S # |                                r| j         |= w xY wrr   )r  r   r   )rs   r   r9  s      rB   r6  z"H3Connection._get_or_create_streamb  s      DL((&.y&9&9DL#i(	,LLL    ,L+++, ,v   ,L+++++s   A A3r   c                    t           j        | j        t           j        | j        t           j        dt           j        di}| j        rd|t           j        <   d|t           j	        <   |S )z3
        Return the local HTTP/3 settings.
        r   )
rY   r]   r   r_   r   r`   rc   r   ra   rb   )rs   r   s     rB   _get_local_settingsz H3Connection._get_local_settingsp  s\    
 ,d.F)4+@+QM1	$
 $ 	6,-HW()45HW01rA   r   c                   |t           j        k    r| j        st          |t           j        k    r| j        rt	          d          t          |          }|                     |           || _        | j        	                    |
                    t          j        d          |
                    t          j        d          |
                    t          j        d                    }| j                            | j        |           d| _        dS |t           j        k    r,| j        rt	          d          t'          |          | _        dS |t           j        t           j        t           j        t           j        fv rt	          d          dS )zG
        Handle a frame received on the peer's control stream.
        z#SETTINGS have already been receivedr   )max_table_capacitydyn_table_capacityblocked_streamsTz!Servers must not send MAX_PUSH_IDz$Invalid frame type on control streamN)rD   rM   r  r   r   r   _validate_settingsr  r  apply_settingsgetrY   r]   r_   r   r  r  rP   r   r   r  rI   rJ   rN   rQ   )rs   r   r   r   rR  s        rB   _handle_control_framez"H3Connection._handle_control_frame  sy    +++D4K+&&+++& M%&KLLL%j11H##H---&.D#m22#+<<0PRS#T#T#+<<0PRS#T#T (W-JA N N 3  G
 J''(EwOOO&*D###9000 K%&IJJJ 1* = =DN"$	
 
 
 ""HIII
 
rA   r9  r   stream_endedc           
     <   g }|t           j        k    rZ|j        t          j        k    rt          d          |s|r0|                    t          ||j        ||j	                             n/|t           j
        k    r|j        t          j        k    rt          d          |                     |j	        |          }d}|j        t          j        k    r'| j        rt          |          }nt!          |           nt#          |           | j        S| j                            dd| j                            ||j        nt-          |          ||j	                             |j        t          j        k    r||d	k    s|rt          j        |_        nt          j        |_        |j        t          j        k    r3|1|d	k     r+|                    t/          ||j	        
                     n|                    t1          ||j        |j	        |                     n||t           j        k    r|j        | j        st          d          t5          |          }|                                }	|                     |j	        ||                                d                   }t;          |           | j        K| j                            dd| j                            t-          |          ||	|j	                             |                    t?          ||	|j	                             ni|t           j         t           j!        t           j"        t           j        t           j#        t           j$        t           j%        fv rt          |j        dnd          |S )zF
        Handle a frame received on a request or push stream.
        r/  )r   r   r_  r   r<  Nr0  frame_parsedr=  r4  r>  )r   r   )r   r   r   r_  z"Clients must not send PUSH_PROMISEr   )r3  r   r   r   )r   r   r   z$Invalid frame type on request streamz!Invalid frame type on push stream)&rD   rI   r   rT   rV   r   appendr   r   r   rJ   rW   rO  rU   r   r   r   r   r   r7  r?  r   r   r   r   rN   r   r   tellr   encode_http3_push_promise_framer   rK   rL   rM   rO   rP   rQ   )
rs   r   r   r9  r_  http_eventsr   r   	frame_bufr   s
             rB   _handle_request_or_push_framez*H3Connection._handle_request_or_push_frame  s
    &(''(L,FFF%&OPPP z "" ' &%1"("2	     9,,,(L,GGG%&RSSS **6+;ZHHG&*K (L,@@@? 6";G"D"DKK,W5555!'***  ,!++#(*EE  *1 #55!$Z '"("2 F   ,    (L,@@@ &+*<*<*<0<0JF-,8,G) )\-AAA+#%%""0 '"("2      ""# ' &"("2%1	      9111fn6L? L%&JKKKJ///I--//G** *Y^^-=-=-?-?"@ G
 *'222  ,!++#(*JJ": ' '"("2	 K   , 	 	 	 ##W@P     
 !"!$
 
 
 ">) 768   rA   c           	     T   |                      t          j                  | _        |                                 | _        | j                            | j        t          t          j
        t          | j                                       | j        rQ| j        J| j                            | j        t          t          j        t          | j                                       |                      t          j                  | _        |                      t          j                  | _        d S rr   )r  re   rg   r
  rV  r  r   r  r   rD   rM   r   r   r  rP   r   ri   r  rj   r  r   s    rB   r  zH3Connection._init_connection)  s    (,(?(?
@R(S(S%"6688
##)+_T=P-Q-QRR	
 	
 	
 ? 	t0<J''-Y2ODDU4V4VWW   )-(?(?$)
 )
% )-(?(?$)
 )
%%%rA   c                    | j         Gdddddd                    |d          }||d}|||d	<   | j                             d
d|           d S d S )Ncontrolpushqpack_encoderqpack_decoderwebtransport)r   r   r   r#   rf   unknown)newr   associated_push_idr0  stream_type_setr4  )r   r]  r7  )rs   r   r   r   	type_namer   s         rB   r  zH3Connection._log_stream_type?  s     (""$  c+y))  %9==D"-4)*''' (      )(rA   c                    t          |          }	 |                                }n# t          $ r t          d          w xY wt	          ||                                d         |          gS )z$
        Handle a datagram.
        r   zCould not parse flow IDN)r   r%  )r   r   r	   rm   r   rc  )rs   r   r   r%  s       rB   r!  zH3Connection._receive_datagramU  s}     $	;''))GG 	; 	; 	; 9:::	; d388::<<&8'JJJKKs	   ' Ar   c                (   |j         }|                     |          5 }t          |          r-|                     ||j        |j                  cd d d            S |                     ||j        |j                  cd d d            S # 1 swxY w Y   d S rr   )r   r6  r   _receive_stream_data_unir   r-  _receive_request_or_push_data)rs   r  r   r9  s       rB   r   z!H3Connection._receive_stream_data`  s    O	''	22 	f'	22 44EJ(8 	 	 	 	 	 	 	 	 99EJ(8 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   0B BBBc           	     ,   g }|xj         |z  c_         |rd|_        |j        r|S |j        t          j        k    rE|j        >|                    t          |j         |j        |j	        |                     d|_         |S |j        t          j
        k    r|j        }t          |j                   |j        k     r`|                    t          |j         |j        |j	        d                     |xj        t          |j                   z  c_        d|_         |S |r9|j         s2|                    t          d|j        |j	        d                     |S t          |j                   }d}|                                s|j        P	 |                                |_        |                                |_        n# t$          $ r Y n8w xY w|                                }|j        t          j        k    r|j        |_        d|_        |j         |d         }d|_         |                     |j	        t*          j        	           |s|r0|                    t          ||j        |j	        |                     |S | j        V|j        t          j
        k    rA| j                            d
d| j                            |j        |j	                             t5          |j        |j        |z
            }|j        t          j
        k    r||j        k     rn|                    |          }|j        }	|                                }|xj        |z  c_        |j        sd|_        d|_        	 |                    |                     |	|||j        o|                                                     n:# t>          $ r- d|_        t          |          |_         || j!        |j	        <   Y nw xY w|                                |j         |d         |_         |S )zC
        Handle data received on a request or push stream.
        TN)r   r   r   r_  rA   F)r   r   r   r_  r   r   r  r0  ra  r2  r4  r   r   r9  r_  )"r   r   r   r   rD   rR   r   rb  r   r   rI   r   r   r   r   r   r   r   r	   rc  r  re   rk   r   r7  r8  minr   
pull_bytesextendrg  r   r   r  )
rs   r9  r   r_  re  r   consumedr   
chunk_sizer   s
             rB   rw  z*H3Connection._receive_request_or_push_datam  s    &( 	*%)F"> 	 !>>>!-.%0$.!-	      FM //!-FM""V%666"N$.!&	     V]!3!33FM  		 		"N$.!%	     &-((('')) K	 ((+(9(9(;(;F%(+(9(9(;(;F%%&   E88:: $	(EEE(.(9F%(,F%!'xyy!9J$'FM))"("2
@W *    " \ #**:%/+1+<*0*:-9	     '& %1)Y^;;%//!',!.FF#)#4@P G   0    V.x0GHHJ IN22zFDU7U7U 
33J*JxxzzH +$ )$(!$(!""66#-#-%%+%;%I			 7      !   !%,/
OO)=C()9:	O '')) K	\ hii0s%   2F; ;
G	G	+AN1 14O('O(c           	     4   g }|xj         |z  c_         |rd|_        t          |j                   }d}t                      }|j        t
          j        t
          j        t
          j        fv s|	                                sc|j        	 |
                                |_        n# t          $ r Y n3w xY w|                                }|j        t
          j        k    r#| j        t          d          |j        | _        no|j        t
          j        k    r#| j        t          d          |j        | _        n7|j        t
          j        k    r"| j        t          d          |j        | _        |j        t
          j        k    r!|                     |j        |j                   |j        t
          j        k    r|rt+          d          	 |
                                }|
                                }	|                    |	          }
n# t          $ r Y nw xY w|                                }|                     ||
           n\|j        t
          j        k    r|j        g	 |
                                |_        n# t          $ r Y nXw xY w|                                }|                     |j        |j        |j        	           |j         |d          |_         |                     |d
|          S |j        t
          j        k    r|j        @	 |
                                |_        n# t          $ r Y nw xY w|                                }|j         |d          }
d
|_         |
s|r5|                    t9          |
|j        |j        |j                             |S |j        t
          j        k    r|                    |j        |                                z
            }|                                }	 | j                            |           n!# t@          $ r}tC                      |d }~ww xY w| xj"        tG          |          z  c_"        nM|j        t
          j        k    r	|                    |j        |                                z
            }|                                }	 | j$        %                    |           n!# tL          $ r}tO                      |d }~ww xY w| j(        )                                D ]Q\  }}	 | j$        *                    |          \  }}||f|_+        |,                    |           B# tZ          $ r Y Nw xY w| xj.        tG          |          z  c_.        n.|/                    |j                   |                                }|j        t
          j        t
          j        t
          j        fv N|	                                c|j         |d          |_         |D ]}| j0        |         }|1                    | 2                    tf          j4        d ||j        o|j                               d|_5        d |_6        | j(        |= |j         r/|1                    |                     |d
|j                             |S )NTr   r   z"Only one control stream is allowedz(Only one QPACK decoder stream is allowedz(Only one QPACK encoder stream is allowedr  z%Closing control stream is not allowedrJ  rA   )r   r   r_  r   ry  F)7r   r   r   r   r   re   rh   rg   rk   r   r   r	   rc  r  r   r   rj   r  ri   r  r  r   r{  r^  r   rw  r   rb  r   r   r  feed_decoderr
   r{   r  r   r   feed_encoderr   r}   r  r   resume_headerrL  r   r   r  seekr  r|  rg  rD   rJ   r   r   )rs   r9  r   r_  re  r   r}  unblocked_streamsr   r   r   r#  
blocked_idblocked_streamstream_datar   r   s                    rB   rv  z%H3Connection._receive_stream_data_uni  s    &( 	*%)F"&-(((&)ee !3Z5LMN N7799N
 !)),):):)<)<F&&&   E88:: %);;;3?12VWWW393CD00':+CCC3?1F   4:3CD00':+CCC3?1F   4:3CD0 %88))"("2@R *    !Z%777 X./VWWW!$!2!2!4!4J#&#4#4#6#6L!$!=!=JJ&   E88::**:zBBBB#z66>)),):):)<)<*   "xxzzH)) &"("2$*$6 *    !'hii 899&#|TTT#z'>>>$,,/,=,=,?,?))*   "xxzzH#]8995
 #  &&6!+'-'8)/)?&,&6	     #"#z'???~~clSXXZZ&?@@88::=M..t4444) = = =133<=,,D		9,,,#z'???~~clSXXZZ&?@@88::=M..t4444) = = =133<= 372J2P2P2R2R 	! 	!.J!/3}/J/J:/V/V,W'#3/ *--j9999( ! ! ! ! ,,D		9,,, &&&88::y !3Z5LMN N7799N~ hii0 + 	 	I\),F 22(0#!!'!7!M<M	 3     #FN(,F%(3 } ""66.    s   	B# #
B10B1=H
 

HH$I> >
JJL, ,
L:9L:;P 
P4 P//P40S 
S)S$$S);U
UUr   c                   t           j        t           j        t           j        fD ]'}||v r!||         dvrt	          |j         d          (|                    t           j                  dk    r| j        j        t	          d          |                    t           j                  dk    r2|                    t           j                  dk    rt	          d          d S d S )N)r   r   z setting must be 0 or 1r   z@H3_DATAGRAM requires max_datagram_frame_size transport parameterz(ENABLE_WEBTRANSPORT requires H3_DATAGRAM)	rY   r`   rb   ra   r   namer]  r   _remote_max_datagram_frame_size)rs   r   r   s      rB   r[  zH3Connection._validate_settings  s    +'
 	N 	NG
 (""x'8'F'F#w|$L$L$LMMM LL,--22
:BR  
 LL455::W011Q66 JKKK ;:66rA   )F)r   r   r   r   r   r   )r   r   r  r   r   r   )r  r   r   r  )r%  r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r-  r   r   r   )r   r   r   r   r-  r   r   r   )r   rD  rr   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   rS  )r   r   )r   r   r   r   r   r   )
r   r   r   r   r9  r   r_  r   r   r  r   )r   r   r   r   r   r   r   r   )r   r   r   r  )r  r   r   r  )r9  r   r   r   r_  r   r   r  )r   r   r   r   )r)   r*   r+   ru   rt   r  r$  r(  r,  r:  rC  propertyrF  rH  r  rO  r*  
contextlibcontextmanagerr6  rV  r^  rg  r  r  r!  r   rw  rv  r[  r@   rA   rB   r   r   L  sc        "  "  "  "  " J :?    0   *H H H H   < 
  
  
  
F DI6 6 6 6 6p ' ' ' X' # # # X#	 	 	 	 	   .    , , , ,   J J J J@H H H HT
 
 
 
. GK    ,	L 	L 	L 	L   O O O Obj j j jXL L L L L LrA   r   )r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   rr   )
r   r   r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )J
__future__r   r  loggingretypingenumr   r   _compatr   _hazmatr   r	   r
   r   r   r   r   r   r   quic.connectionr   r   quic.eventsr   r   r   quic.loggerr   eventsr   r   r   r   r   r   r   r   
exceptionsr    	getLoggerloggerH3_ALPNr   compiler   r'   rD   rT   rY   re   	Exceptionrm   rx   r{   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r@   rA   rB   <module>r     sl   " " " " " "      				          ' ' ' ' ' '
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G F F F F F F F N N N N N N N N N N ) ) ) ) ) )	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 / . . . . .		7	#	#&- BJx  	' ' ' ' ' ' ' '.
 
 
 
 
 
 
 
    4       g   "       + + + + +I + + +6 6 6 6 6} 6 6 66 6 6 6 6m 6 6 66 6 6 6 6m 6 6 65 5 5 5 5= 5 5 5/ / / / /m / / /, , , , ,= , , ,/ / / / /= / / /- - - - -M - - -4 4 4 4 4- 4 4 4            $ $(	7" 7" 7" 7" 7"t	 	 	 		 	 	 	   "   " " " " " " " "6sL sL sL sL sL sL sL sL sL sLrA   