
    @OOf
                        d dl Z d dlZd dlmZmZ d dlmZmZmZm	Z	m
Z
 d dlZd dlmZmZmZmZ d dl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 d dlm Z m!Z!m"Z" d d	l#m$Z$  e jJ                  d
      Z&g dZ'dZ( ejR                  d      Z*dZ+d Z,dZ-dZ.dZ/dZ0e/e0fZ1 G d de      Z2 G d de      Z3 G d de      Z4 G d de      Z5 G d de      Z6 G d de7      Z8 G d d e8      Z9 G d! d"e8      Z: G d# d$e8      Z; G d% d&e8      Z< G d' d(e8      Z= G d) d*e8      Z> G d+ d,e8      Z? G d- d.e8      Z@ G d/ d0e8      ZA G d1 d2e8      ZBd3eCd4eDd5eDfd6ZEd7eeCeCf   d5eDfd8ZFd9eDd5eCfd:ZGd9eDd5eeCeCf   fd;ZHd<eCfd=ZId>eDd5dfd?ZJd>eDd@eDfdAZK	 dOdBedCeeD   dDeeD   dEe	dF   d5df
dGZLdBed5dfdHZM	 dOdBedEe	dF   d5dfdIZN	 dOdBedEe	dF   d5dfdJZOdBed5dfdKZP G dL dF      ZQ G dM dN      ZRy)P    N)EnumIntEnum)Dict	FrozenSetListOptionalSet)UINT_VAR_MAX_SIZEBufferBufferReadErrorencode_uint_var)DatagramReceivedDataReceivedH3EventHeadersHeadersReceivedPushPromiseReceivedWebTransportStreamDataReceived)InvalidStreamTypeErrorNoAvailablePushIDError)QuicConnectionstream_is_unidirectional)DatagramFrameReceived	QuicEventStreamDataReceived)QuicLoggerTracehttp3)h3zh3-32zh3-31zh3-30zh3-29)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Zy)	ErrorCode3      i  i  i  i  i  i  i  i  i	  i
  i  i  i  i  i  i  i   i  i  N)__name__
__module____qualname__H3_DATAGRAM_ERROR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     V/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/aioquic/h3/connection.pyr)   r)   %   s}    K %$ %NK !!&!&!&rE   r)   c                   4    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
Zy)	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_STREAMrD   rE   rF   rH   rH   =   s5    DGHKHLFKNrE   rH   c                       e Zd ZdZdZdZy)HeadersStater   rI   r   N)r,   r-   r.   INITIALAFTER_HEADERSAFTER_TRAILERSrD   rE   rF   rX   rX   J   s    GMNrE   rX   c                   (    e Zd ZdZdZdZdZdZdZdZ	y)	SettingrI      rJ      r*   iB7`+!   N)
r,   r-   r.   QPACK_MAX_TABLE_CAPACITYMAX_FIELD_SECTION_SIZEQPACK_BLOCKED_STREAMSENABLE_CONNECT_PROTOCOLH3_DATAGRAMENABLE_WEBTRANSPORTDUMMYrD   rE   rF   r]   r]   P   s.    "  "K$ ErE   r]   c                        e Zd ZdZdZdZdZdZy)
StreamTyper   rI   r   r    T   N)r,   r-   r.   CONTROLPUSHQPACK_ENCODERQPACK_DECODERWEBTRANSPORTrD   rE   rF   ri   ri   a   s    GDMMLrE   ri   c                   6    e Zd ZdZej
                  ZddefdZy)ProtocolErrorz
    Base class for protocol errors.

    These errors are not exposed to the API user, they are handled
    in :meth:`H3Connection.handle_event`.
    reason_phrasec                     || _         y N)rr   )selfrr   s     rF   __init__zProtocolError.__init__s   s
    *rE   N) )	r,   r-   r.   __doc__r)   r1   
error_codestrrv   rD   rE   rF   rq   rq   i   s      44J+c +rE   rq   c                   $    e Zd Zej                  Zy)QpackDecompressionFailedN)r,   r-   r.   r)   rA   ry   rD   rE   rF   r|   r|   w       55JrE   r|   c                   $    e Zd Zej                  Zy)QpackDecoderStreamErrorN)r,   r-   r.   r)   rC   ry   rD   rE   rF   r   r   {   r}   rE   r   c                   $    e Zd Zej                  Zy)QpackEncoderStreamErrorN)r,   r-   r.   r)   rB   ry   rD   rE   rF   r   r      r}   rE   r   c                   $    e Zd Zej                  Zy)ClosedCriticalStreamN)r,   r-   r.   r)   r4   ry   rD   rE   rF   r   r      s    44JrE   r   c                   $    e Zd Zej                  Zy)DatagramErrorN)r,   r-   r.   r)   r/   ry   rD   rE   rF   r   r          ,,JrE   r   c                   $    e Zd Zej                  Zy)FrameUnexpectedN)r,   r-   r.   r)   r5   ry   rD   rE   rF   r   r          ..JrE   r   c                   $    e Zd Zej                  Zy)MessageErrorN)r,   r-   r.   r)   r>   ry   rD   rE   rF   r   r      s    ++JrE   r   c                   $    e Zd Zej                  Zy)MissingSettingsErrorN)r,   r-   r.   r)   r:   ry   rD   rE   rF   r   r      r   rE   r   c                   $    e Zd Zej                  Zy)SettingsErrorN)r,   r-   r.   r)   r9   ry   rD   rE   rF   r   r      r   rE   r   c                   $    e Zd Zej                  Zy)StreamCreationErrorN)r,   r-   r.   r)   r3   ry   rD   rE   rF   r   r      s    33JrE   r   
frame_type
frame_datareturnc                     t        |      }t        |dt        z  z         }|j                  |        |j                  |       |j	                  |       |j
                  S )Nr   capacity)lenr   r
   push_uint_var
push_bytesdata)r   r   frame_lengthbufs       rF   encode_framer      sQ    z?L
,->)>>
?Cj!l#NN:88OrE   settingsc                     t        d      }| j                         D ]'  \  }}|j                  |       |j                  |       ) |j                  S )Ni   r   )r   itemsr   r   )r   r   settingvalues       rF   encode_settingsr      sM    
$
C"..* !'"% ! 88OrE   r   c                 b    t        |       }|j                         }|j                         sJ |S )Nr   )r   pull_uint_vareof)r   r   max_push_ids      rF   parse_max_push_idr      s.    
d
C##%K7799rE   c                    t        |       }i }|j                         s^|j                         }|j                         }|t        v rt	        d|z        ||v rt	        d|z        |||<   |j                         s^t        |      S )Nr   z#Setting identifier 0x%x is reservedz)Setting identifier 0x%x is included twice)r   r   r   RESERVED_SETTINGSr   dict)r   r   r   r   r   s        rF   parse_settingsr      s    
d
C!Hggi##%!!#'' E OPPh Kg UVV! ggi >rE   	stream_idc                     | dz  dk(  S )zP
    Returns True if the stream is a client-initiated bidirectional stream.
    r!   r   rD   )r   s    rF   stream_is_request_responser      s     q=ArE   keyc                     t        |       D ]D  \  }}|dk  s|dk\  r|dk  s|dk\  rt        d| z        |t        k(  s2|dk7  s8t        d| z         y)	zH
    Validate a header name as specified by RFC 9113 section 8.2.1.
    r&   rL   Z      z%Header %r contains invalid charactersr   z&Header %r contains a non-initial colonN)	enumerater   COLON)r   ics      rF   validate_header_namer      sg     # O19dqDyQ$YFLMM:!q& G#MNNOrE   r   c                    |D ]+  }|t         k(  s|t        k(  s
|t        k(  st        d| z         t	        |      dkD  rF|d   }|t
        v rt        d| z        t	        |      dkD  r|d   }|t
        v rt        d| z        yyy)zI
    Validate a header value as specified by RFC 9113 section 8.2.1.
    z(Header %r value has forbidden charactersr   z&Header %r value starts with whitespacerI   z$Header %r value ends with whitespaceN)NULLFCRr   r   
WHITESPACE)r   r   r   firstlasts        rF   validate_header_valuer      s      Q8qBw!r'ICOPPQ 5zA~aJG#MNNu:>9Dz!"#IC#OPP " 	 rE   headersallowed_pseudo_headersrequired_pseudo_headersstreamH3Streamc                    d}d }d }d }t               }| D ]  \  }	}
t        |	       t        |	|
       |	j                  d      r^|rt	        d|	z        |	|vrt	        d|	z        |	|v rt	        d|	z        |j                  |	       |	dk(  r|
}{|	dk(  r|
}|	dk(  s|
}d	}|	d
k(  r#	 t        |
      }|dk  rt        	 |s||_        |	dk(  s|
dk7  st	        d       |j                  |      }|rt	        dt        |      z        |dv r|st	        d      |st	        d      y y # t        $ r t	        d      w xY w)NF   :z5Pseudo-header %r is not allowed after regular headerszPseudo-header %r is not validz"Pseudo-header %r is included twice
   :authority   :path   :schemeTs   content-lengthr   z,content-length is not a non-negative integers   transfer-encodings   trailersz6The only valid value for transfer-encoding is trailerszPseudo-headers %s are missing)s   https   httpsz+Pseudo-header b':authority' cannot be emptyz&Pseudo-header b':path' cannot be empty)setr   r   
startswithr   addint
ValueErrorexpected_content_length
differencesorted)r   r   r   r   after_pseudo_headers	authoritypathschemeseen_pseudo_headersr   r   content_lengthmissings                rF   validate_headersr      s    !!%I D"F&)e '
US!c5)>>$#"KcQ  00"#BS#HII))"#G##MNN##C( m#!	
" $( ''W%(ZN%)(( * 5CF2,,+1E"L K'T &001DEG:VG_LMM$$LMMGHH  % " W&'UVVWs   )D--Ec                 D    t        | t        d      t        d             y )N)   :methodr   r   r   r   r   r   	frozensetr   s    rF   validate_push_promise_headersr   *  s%    (= 
 !*=!
rE   c                 F    t        | t        d      t        d      |       y )N)r   r   r   r   s	   :protocol)r   r   r   r   r   r   r   r   s     rF   validate_request_headersr   6  s+     ( L 

 !**E F	rE   c                 F    t        | t        d      t        d      |       y )N)s   :statusr   r   r   s     rF   validate_response_headersr   E  s"     (7 )- 8	rE   c                 @    t        | t               t                      y )Nr   r   r   s    rF   validate_trailersr   P  s    ({ )rE   c                       e Zd ZdeddfdZy)r   r   r   Nc                     d| _         d | _        d| _        d| _        d | _        d | _        t        j                  | _        t        j                  | _	        d | _
        d | _        || _        d | _        d | _        d| _        y )NFrE   r   )blockedblocked_frame_sizebufferended
frame_sizer   rX   rY   headers_recv_stateheaders_send_statepush_id
session_idr   stream_typer   r   ru   r   s     rF   rv   zH3Stream.__init__Y  sv    15
)-)-0<0D0D0<0D0D&*)-"*.6:$#$rE   )r,   r-   r.   r   rv   rD   rE   rF   r   r   X  s    %# %$ %rE   c                   L   e Zd ZdZd+dededdfdZ	 d+dededefd	Zd
e	de
e   fdZdededdfdZdededefdZdedededdfdZ	 d+dedededdfdZedeeeef      fd       Zedeeeef      fd       Z	 d,dedee   defdZdedee   defdZdededefdZdedefdZdeeef   fdZdededdfdZd efd!Zdedee   d ed"ede
e   f
d#Z d-d$Z!	 d,dededee   ddfd%Z"dede
e   fd&Z#d eded"ede
e   fd'Z$d eded"ede
e   fd(Z%d)eeef   ddfd*Z&y).H3Connectionz~
    A low-level HTTP/3 connection object.

    :param quic: A :class:`~aioquic.quic.connection.QuicConnection` instance.
    quicenable_webtransportr   Nc                 N   d| _         d| _        || _        |j                  j                  | _        d| _        || _        |j                  | _        t        j                  | j                   | j                        | _        d| _        d| _        t        j                         | _        d| _        d| _        d| _        i | _        | j
                  rdnd | _        d| _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d | _        | j=                          y )Ni      Fr   r_   )_max_table_capacity_blocked_streams_enable_webtransportconfiguration	is_client
_is_client_is_done_quic_quic_logger	pylsqpackDecoder_decoder_decoder_bytes_received_decoder_bytes_sentEncoder_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_init_connection)ru   r   r   s      rF   rv   zH3Connection.__init__q  s   #'  "$7!,,66
7;7H7H!))$$d&;&;
 ()$#$ !))+'($#$ "',.041T"#7;%7;%7;%6:$6:$6:$<@8<rE   r   is_unidirectionalc                    |rF| j                  t        j                        }| j                  j	                  |t        |             |S | j                  j                         }| j                  |t        j                         | j                  j	                  |t        t        j                        t        |      z          |S )z
        Create a WebTransport stream and return the stream ID.

        .. aioquic_transmit::

        :param session_id: The WebTransport session identifier.
        :param is_unidirectional: Whether to create a unidirectional stream.
        r   r   )
_create_uni_streamri   ro   r  send_stream_datar   get_next_available_stream_id_log_stream_typerH   rV   )ru   r   r  r   s       rF   create_webtransport_streamz'H3Connection.create_webtransport_stream  s     //
0G0GHIJJ''	?:3NO  

??AI!!#1H1H "  JJ''	 = =>!*-.
 rE   eventc                 &   | j                   s	 t        |t              rv|j                  }| j	                  |      }t        |      r'| j                  ||j                  |j                        S | j                  ||j                  |j                        S t        |t              r| j                  |j                        S 	 g S g S # t        $ rC}d| _         | j                  j                  |j                  |j                          Y d}~g S d}~ww xY w)zx
        Handle a QUIC event and return a list of HTTP events.

        :param event: The QUIC event to handle.
        T)ry   rr   N)r  
isinstancer   r   _get_or_create_streamr   _receive_stream_data_unir   
end_stream_receive_request_or_push_datar   _receive_datagramrq   r  closery   rr   )ru   r'  r   r   excs        rF   handle_eventzH3Connection.handle_event  s    }}e%78 %I!77	BF/	:#<<"EJJ0@0@    $AA"EJJ0@0@    '<=11%**== > 	r	 !  $

  "~~S=N=N !   	s$   AC -&C *C 	D8DDr   r   c                     t        |      st        d      | j                  j                  t	        |dz        |z          y)aW  
        Send a datagram for the specified stream.

        If the stream ID is not a client-initiated bidirectional stream, an
        :class:`~aioquic.h3.exceptions.InvalidStreamTypeError` exception is raised.

        .. aioquic_transmit::

        :param stream_id: The stream ID.
        :param data: The HTTP/3 datagram payload.
        zEDatagrams can only be sent for client-initiated bidirectional streamsr!   N)r   r   r  send_datagram_framer   )ru   r   r   s      rF   send_datagramzH3Connection.send_datagram  s>     *)4(W  	

&&yA~'F'MNrE   r   c                    | j                   rJ d       t        |      st        d      | j                  | j                  | j                  k\  rt
        | j                  }| xj                  dz  c_        | j                  j                  |t        t        j                  t        |      | j                  ||      z                | j                  t        j                  |      }| j                  j                  |t        |             |S )aU  
        Send a push promise related to the specified stream.

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

        If the stream ID is not a client-initiated bidirectional stream, an
        :class:`~aioquic.h3.exceptions.InvalidStreamTypeError` exception is raised.

        If there are not available push IDs, an
        :class:`~aioquic.h3.exceptions.NoAvailablePushIDError` exception is raised.

        .. aioquic_transmit::

        :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.zIPush promises can only be sent for client-initiated bidirectional streamsrI   )r   )r  r   r   r  r  r   r  r#  r   rH   rR   r   _encode_headersr"  ri   rl   )ru   r   r   r   push_stream_ids        rF   send_push_promisezH3Connection.send_push_promise  s    " ??K$KK" *)4(  $(:(:d>O>O(O(( $$a

##&&(4+?+?	7+SS	
 00'0R

##NOG4LMrE   r,  c           	      |   | j                  |      }|j                  t        j                  k7  rt	        d      | j
                  B| j
                  j                  dd| j
                  j                  t        |      |             | j                  j                  |t        t        j                  |      |       y)z
        Send data on the given stream.

        .. aioquic_transmit::

        :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   )r*  r   rX   rZ   r   r  	log_eventencode_http3_data_framer   r  r#  r   rH   rM   )ru   r   r   r,  r   s        rF   	send_datazH3Connection.send_data  s     ++I6$$(B(BB!"KLL (''%&&>>t9	 ?  (  	

##|INND9:	
rE   c           	      2   | j                  |      }|j                  t        j                  k(  rt	        d      | j                  ||      }| j                  C| j                  j                  dd| j                  j                  t        |      ||             |j                  t        j                  k(  rt        j                  |_        nt        j                  |_        | j                  j                  |t        t        j                   |      |       y)a  
        Send headers on the given stream.

        .. aioquic_transmit::

        :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 stateNr;  r<  r>  r   r   r?  )r*  r   rX   r[   r   r6  r  rA  encode_http3_headers_framer   rY   rZ   r  r#  r   rH   rN   )ru   r   r   r,  r   r   s         rF   send_headerszH3Connection.send_headers.  s     ++I6$$(C(CC!"NOO)))W=
 (''%&&AAz?Gy B  (  $$(<(<<(4(B(BF%(4(C(CF%

##|I$5$5zBJ	
rE   c                     | j                   S )z>
        Return the received SETTINGS frame, or None.
        )r  ru   s    rF   received_settingszH3Connection.received_settingsT  s    
 &&&rE   c                     | j                   S )z:
        Return the sent SETTINGS frame, or None.
        )r  rJ  s    rF   sent_settingszH3Connection.sent_settings[  s    
 """rE   r   r   c                     | j                   j                  d      }| j                  |||       | j                   j                  |t	        |             |S )zD
        Create an unidirectional stream of the given type.
        T)r  r   r   r   )r  r$  r%  r#  r   )ru   r   r   r   s       rF   r"  zH3Connection._create_uni_streamb  sV     JJ;;d;S	yk 	 	
 	

##I{/KLrE   r   c                 \   	 || j                   j                  |      \  }}n| j                   j                  ||      \  }}| xj                  t	        |      z  c_        | j
                  j                  | j                  |       |S # t        j                  $ r}t               |d}~ww xY w)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  resume_headerfeed_headerr  r   r  r#  r  r	  DecompressionFailedr|   )ru   r   r   decoderr   r0  s         rF   _decode_headerszH3Connection._decode_headerso  s    	6!#'==#>#>y#I #'==#<#<Y
#S $$G4$JJ''(E(EwO  ,, 	6*,#5	6s   BB B+B&&B+c                     | j                   j                  ||      \  }}| xj                  t        |      z  c_        | j                  j                  | j                  |       |S )zX
        Encode a HEADERS block and send encoder updates on the encoder stream.
        )r  encoder  r   r  r#  r  )ru   r   r   encoderr   s        rF   r6  zH3Connection._encode_headers  sT     #mm229gF  CL0 

##D$A$A7KrE   c                 l    || j                   vrt        |      | j                   |<   | j                   |   S rt   )r  r   r   s     rF   r*  z"H3Connection._get_or_create_stream  s0    DLL(&.y&9DLL#||I&&rE   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.
        rI   )
r]   ra   r   rc   r  rd   rg   r  re   rf   )ru   r   s     rF   _get_local_settingsz H3Connection._get_local_settings  sq    
 ,,d.F.F))4+@+@++QMM1	$
 $$,-HW(()45HW001rE   r   c                    |t         j                  k7  r| j                  st        |t         j                  k(  r| j                  rt	        d      t        |      }| j                  |       || _        | j                  j                  |j                  t        j                  d      |j                  t        j                  d            }| j                  j                  | j                   |       d| _        y|t         j"                  k(  r(| j$                  rt	        d      t'        |      | _        y|t         j*                  t         j,                  t         j.                  t         j0                  fv rt	        d      y)zG
        Handle a frame received on the peer's control stream.
        z#SETTINGS have already been receivedr   )max_table_capacityblocked_streamsTz!Servers must not send MAX_PUSH_IDz$Invalid frame type on control streamN)rH   rQ   r  r   r   r   _validate_settingsr  r  apply_settingsgetr]   ra   rc   r  r#  r  rT   r  r   r  rM   rN   rR   rU   )ru   r   r   r   rX  s        rF   _handle_control_framez"H3Connection._handle_control_frame  s9    +++D4K4K&&+++&&%&KLL%j1H##H-&.D#mm22#+<<0P0PRS#T (W-J-JA N 3 G JJ''(E(EwO&*D#9000%&IJJ 1* =DNN""$$	
 
 ""HII
rE   r   c                 f    |j                   %|j                  |j                   k7  rt        d      y y )Nz'content-length does not match data size)r   r   r   )ru   r   s     rF   _check_content_lengthz"H3Connection._check_content_length  s9    **6%%)G)GGHII H 7rE   stream_endedc           
         g }|t         j                  k(  r|j                  t        j                  k7  rt        d      ||xj                  t        |      z  c_        |r| j                  |       |s|r2|j                  t        ||j                  ||j                               |S |t         j                  k(  r|j                  t        j                  k(  rt        d      | j                  |j                  |      }|j                  t        j                   k(  r&| j"                  rt%        ||       nt'        ||       nt)        |       |r| j                  |       | j*                  [| j*                  j-                  dd| j*                  j/                  ||j0                  n
t        |      ||j                               |j                  t        j                   k(  rt        j                  |_        nt        j                  |_        |j                  t3        ||j                  |j                  |	             |S |t         j4                  k(  r|j                  | j"                  st        d
      t7        |      }|j9                         }| j                  |j                  ||j;                         d       }t=        |       | j*                  N| j*                  j-                  dd| j*                  j?                  t        |      |||j                               |j                  tA        |||j                               |S |t         jB                  t         jD                  t         jF                  t         j4                  t         jH                  t         jJ                  t         jL                  fv rt        |j                  d      d      |S )zF
        Handle a frame received on a request or push stream.
        r:  N)r   r   re  r   rE  r;  frame_parsedrF  r?  )r   r   r   re  z"Clients must not send PUSH_PROMISEr   )r>  r   r   r   )r   r   r   z$Invalid frame type on request streamz!Invalid frame type on push stream)'rH   rM   r   rX   rZ   r   r   r   rd  appendr   r   r   rN   r[   rU  rY   r  r   r   r   r  rA  rG  r   r   rR   r   r   tellr   encode_http3_push_promise_framer   rO   rP   rQ   rS   rT   rU   )	ru   r   r   r   re  http_eventsr   	frame_bufr   s	            rF   _handle_request_or_push_framez*H3Connection._handle_request_or_push_frame  s    &('((L,F,FF%&OPP%%%Z8%**62z"" ' &%1"("2"2	P A 9,,,((L,G,GG%&RSS **6+;+;ZHG ((L,@,@@??-gv>,Wf=!'* **62   ,!!++#(**EE  *1 #55!$Z '"("2"2 F  ,  ((L,@,@@,8,F,F),8,G,G)#"NN$..!-	l ] 9111fnn6L??%&JKKJ/I--/G**  *Y^^-=-?"@G
 *'2   ,!!++#(**JJ": ' '"("2"2	 K  , 	 ##W@P@P(  !!""!!$$
 
 ">>) 7  9  rE   c           	      z   | j                  t        j                        | _        | j	                         | _        | j                  j                  | j                  t        t        j                  t        | j
                                     | j                  r]| j                  Q| j                  j                  | j                  t        t        j                  t        | j                                     | j                  t        j                         | _        | j                  t        j$                        | _        y rt   )r"  ri   rk   r  r[  r  r  r#  r   rH   rQ   r   r  r  rT   r   rm   r  rn   r  rJ  s    rF   r  zH3Connection._init_connectionF  s    (,(?(?
@R@R(S%"668

##))++_T=P=P-QR	
 ??t00<JJ''--Y22ODDUDU4VW )-(?(?$$)
% )-(?(?$$)
%rE   c                     | j                   Cddddddj                  |d      }||d}|||d	<   | j                   j                  d
d|       y y )Ncontrolpushqpack_encoderqpack_decoderwebtransport)r   rI   r   r    rj   unknown)newr   associated_push_idr;  stream_type_setr?  )r  ra  rA  )ru   r   r   r   	type_namer   s         rF   r%  zH3Connection._log_stream_type\  s{     (""$ c+y)  %9=D"-4)*''' (  )rE   c                     t        |      }	 |j                         }t	        ||j                         d |dz        gS # t        $ r t        d      w xY w)z$
        Handle a datagram.
        r   z!Could not parse quarter stream IDNr!   )r   r   )r   r   r   r   r   ri  )ru   r   r   quarter_stream_ids       rF   r.  zH3Connection._receive_datagramr  sl     $	E # 1 1 3 $sxxz|"4@QTU@UV
 	
  	E CDD	Es   A   Ac           	      r	   g }|xj                   |z  c_         |rd|_        |j                  r|S |j                  t        j
                  k(  rQ|j                  E|j                  t        |j                   |j                  |j                  |             d|_         |S |j                  t        j                  k(  r|j                  t        |j                         |j                  k  r|xj                  t        |j                         z  c_        |j                  t        |j                   |j                  |j                  d             |xj                  t        |j                         z  c_        d|_         |S |rQ|j                   sE| j!                  |       |j                  t        d|j                  |j                  d             |S t#        |j                         }d}|j%                         sk|j                  _	 |j'                         |_        |j'                         |_        |j+                         }|j                  t        j
                  k(  r|j                  |_        d|_        |j                   |d }d|_         | j-                  |j                  t.        j0                  	       |s|r2|j                  t        ||j                  |j                  |             |S | j2                  j|j                  t        j                  k(  rM| j2                  j5                  d
d| j2                  j7                  |j                  |j                               t9        |j                  |j:                  |z
        }|j                  t        j                  k7  r||j                  k  rn|j=                  |      }|j                  }	|j+                         }|xj                  |z  c_        |j                  sd|_        d|_        	 |j?                  | jA                  |	|||j                  xr |j%                                      |j%                         sk|j                   |d |_         |S # t(        $ r Y !w xY w# tB        jD                  $ r d|_        t        |      |_#        Y Qw xY w)zC
        Handle data received on a request or push stream.
        TN)r   r   r   re  rE   F)r   r   r   re  r   r   r!  r;  rg  r=  r?  r   r   r   re  )$r   r   r   r   rH   rV   r   rh  r   r   rM   r   r   r   r   r   rd  r   r   r   r   ri  r%  ri   ro   r  rA  rB  minr   
pull_bytesextendrm  r	  StreamBlockedr   )
ru   r   r   re  rk  r   consumedr   
chunk_sizer   s
             rF   r-  z*H3Connection._receive_request_or_push_data  s-    &(FL>> !>!>>!!-.%00$..!-	  FM /!!-FMM"V%6%66!!S%77!"NN$..!&	 V]]!33FM &&v."NN$..!%	 &--('')  ((+(9(9(;F%(+(9(9(;F% 88: $$	(E(EE(.(9(9F%(,F%!'xy!9J$'FM))"("2"2
@W@W *  "\#**:%/+1+<+<*0*:*:-9	 '& %%1))Y^^;%%//!',!..FF#)#4#4@P@P G  0  V..x0GHJ  INN2zFDUDU7U 
3J**JxxzH +$$$(!$(!""66#-#-%%+\\%?cggi	 7  '')Z hi0S ' B ** !%,/
O)s%   *Q: A R	 :	RR	*R65R6c           
      :   g }|xj                   |z  c_         |rd|_        t        |j                         }d}t               }|j                  t
        j                  t
        j                  t
        j                  fv s|j                         s|j                  ;	 |j                         |_        |j                         }|j                  t
        j                  k(  r)| j                  t        d      |j                  | _        n|j                  t
        j                   k(  r)| j"                  t        d      |j                  | _        nE|j                  t
        j$                  k(  r(| j&                  t        d      |j                  | _        |j                  t
        j                  k7  r'| j)                  |j                  |j                         |j                  t
        j                  k(  rc|rt+        d      	 |j                         }|j                         }	|j-                  |	      }
|j                         }| j/                  ||
       n|j                  t
        j                  k(  r|j0                  X	 |j                         |_        |j                         }| j)                  |j0                  |j                  |j                  	       |j                   |d  |_         | j3                  |d
|      S |j                  t
        j                  k(  r|j4                  &	 |j                         |_        |j                         }|j                   |d  }
d
|_         |
s|r<|j7                  t9        |
|j4                  |j                  |j                               |S |j                  t
        j                   k(  rw|j-                  |j:                  |j                         z
        }|j                         }	 | j<                  j?                  |       | xjF                  tI        |      z  c_#        n|j                  t
        j$                  k(  r|j-                  |j:                  |j                         z
        }|j                         }	 |jK                  | jL                  jO                  |             | xjT                  tI        |      z  c_*        n+|jW                  |j:                         |j                         }|j                  t
        j                  t
        j                  t
        j                  fv r|j                         s|j                   |d  |_         |D ]  }| jX                  |   }|j[                  | j]                  t^        j`                  d ||j                  xr |j                                 d|_1        d |_2        |j                   sx|j[                  | j3                  |d
|j                                |S # t        $ r Y w xY w# t        $ r Y w xY w# t        $ r Y w xY w# t        $ r Y w xY w# t@        jB                  $ r}tE               |d }~ww xY w# t@        jP                  $ r}tS               |d }~ww xY w)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 allowedrO  rE   )r   r   re  r   r}  F)3r   r   r   r   r   ri   rl   rk   ro   r   r   r   ri  r  r   r   rn   r  rm   r  r%  r   r  rb  r   r-  r   rh  r   r   r  feed_decoderr	  DecoderStreamErrorr   r  r   updater  feed_encoderEncoderStreamErrorr   r  seekr  r  rm  rH   rN   r   r   )ru   r   r   re  rk  r   r  unblocked_streamsr   r   r   r0  r   s                rF   r+  z%H3Connection._receive_stream_data_uni  s    &(FL&--(&)e !3!3Z5L5LMN779 !!)),):):)<F& 88: %%););;33?12VWW393C3CD0'':+C+CC33?1F  4:3C3CD0'':+C+CC33?1F  4:3C3CD0 %%8))"("2"2@R@R *  !!Z%7%77./VWW!$!2!2!4J#&#4#4#6L!$!=J 88:**:zB##z6>>)),):):)<  #xxzH)) &"("2"2$*$6$6 *  !'hi 899&#|TT##z'>'>>$$,,/,=,=,?)  #xxzH#]]895
 #&&6!+'-'8'8)/&,&6&6	 #"##z'?'??~~cllSXXZ&?@88:=MM..t4 ,,D	9,##z'?'??~~cllSXXZ&?@88:=%,,T]]-G-G-MN ,,D	9, &88:a !3!3Z5L5LMN779b hi0 + 	I\\),F 22(00#!!'!Cfmm2C	 3  #FN(,F% }}""66vsFLLQ#	* G ' J '  + & + . !33 =13<= !33 =13<=sx   X 1X$ X3 )Y  Y *Y7 	X! X!$	X0/X03	X?>X?	YYY4$Y//Y47Z
ZZr   c                    t         j                  t         j                  t         j                  fD ]&  }||v s||   dvst	        |j
                   d       |j                  t         j                        dk(  r!| j                  j                  t	        d      |j                  t         j                        dk(  r.|j                  t         j                        dk7  rt	        d      y y )N)r   rI   z setting must be 0 or 1rI   z@H3_DATAGRAM requires max_datagram_frame_size transport parameterz(ENABLE_WEBTRANSPORT requires H3_DATAGRAM)	r]   rd   rf   re   r   namera  r  _remote_max_datagram_frame_size)ru   r   r   s      rF   r_  zH3Connection._validate_settings  s    ++''
 	NG
 ("x'8'F#w||n4K$LMM	N LL,,-2

::BR 
 LL445:W001Q6 JKK 7 ;rE   )Frt   )r   N)'r,   r-   r.   rx   r   boolrv   r   r&  r   r   r   r1  bytesr4  r   r8  rC  rH  propertyr   r   rK  rM  r"  rU  r6  r   r*  r[  rb  rd  rm  r  r%  r.  r-  r+  r_  rD   rE   rF   r   r   j  s   " ^ " $ " SW " J :?26	4) W <Os O% OD O*-3 - -S -^
3 
e 
 
$ 
< DI$
$
'.$
<@$
	$
L '8DcN#; ' ' #xS#X7 # # :>)1#	 (5/ g $ w 5 's 'x '
T#s(^ J J J4 J>JH J@@ UO@ 	@
 @ 
g@D
. JN+.9A#	,
e 
W 
QQ&+Q;?Q	gQfYY&+Y;?Y	gYvL4S> Ld LrE   r   rt   )Sloggingreenumr   r   typingr   r   r   r   r	   r	  aioquic.bufferr
   r   r   r   aioquic.h3.eventsr   r   r   r   r   r   r   aioquic.h3.exceptionsr   r   aioquic.quic.connectionr   r   aioquic.quic.eventsr   r   r   aioquic.quic.loggerr   	getLoggerloggerH3_ALPNr   compile	UPPERCASEr   r   r   r   SPHTABr   r)   rH   rX   r]   ri   	Exceptionrq   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   rE   rF   <module>r     s    	  7 7  V V   Q L T T /			7	#
4- BJJx 	
			$Z
' '0
 
4 g " +I +6} 66m 66m 65= 5-M -/m /,= ,/= /-M -4- 4S e  d38n  E c  4S> # 
Oe 
O 
OQu QU Q* $(	=I=I%e,=I 'u-=I Z 	=I
 
=I@	7 	t 	 6:&z2	  6:&z2	w 4 % %$XL XLrE   