Ë
    ÚŠ±jKk  ã                   óŒ   — d 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
 ddlmZ ddlmZ dadadadadad„ Z G d	„ d
«      Zd
gZy)zc
HTTP/2 server connection implementation.

Uses the hyper-h2 library for HTTP/2 protocol handling.
é    N)ÚBytesIOé   )Ú
HTTP2ErrorÚHTTP2ProtocolErrorÚHTTP2ConnectionErrorÚHTTP2NotAvailableÚHTTP2ErrorCode)ÚHTTP2Stream)ÚHTTP2Requestc                  ó~   — t         �y	 ddlma  ddlma ddlma ddl	m
a ddlma y# t        $ r t!        «       ‚w xY w)z$Lazily import h2 library components.Nr   )Ú_h2Úh2.connectionÚ
connectionÚ	h2.configÚconfigÚ
_h2_configÚ	h2.eventsÚeventsÚ
_h2_eventsÚh2.exceptionsÚ
exceptionsÚ_h2_exceptionsÚh2.settingsÚsettingsÚ_h2_settingsÚImportErrorr   © ó    ú^/var/www/io.vulcan-creative.com/venv/lib/python3.12/site-packages/gunicorn/http2/connection.pyÚ
_import_h2r        s8   € ô €Øð"Ý#Ý&Ý&Ý.Þ*øÜò "ÜÓ!Ð!ð"ús   ‰( ¨<c                   óÎ   — e Zd ZdZdZd„ Zd„ Zdd„Zdd„Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	 dd„Zdd„Zdd„Zd„ Zdd„Zd„ Zdd„Zd d„Zd!d„Zd„ Zed„ «       Zd„ Zd„ Zy)"ÚHTTP2ServerConnectionzÑHTTP/2 server-side connection handler.

    Manages the HTTP/2 connection state and multiplexed streams.
    This class wraps the h2 library and provides a higher-level
    interface for gunicorn workers.
    i   c                 ó¶  — t        «        || _        || _        || _        i | _        t        j                  «       | _        g | _        |j                  | _
        |j                  | _        |j                  | _        |j                  | _        t"        j%                  dd¬«      }t&        j)                  |¬«      | _        t-        «       | _        d| _        d| _        y)a.  Initialize an HTTP/2 server connection.

        Args:
            cfg: Gunicorn configuration object
            sock: SSL socket with completed handshake
            client_addr: Client address tuple (host, port)

        Raises:
            HTTP2NotAvailable: If h2 library is not installed
        Fzutf-8)Úclient_sideÚheader_encoding)r   N)r    ÚcfgÚsockÚclient_addrÚstreamsÚcollectionsÚdequeÚ_deferred_eventsÚ_pending_requestsÚhttp2_initial_window_sizeÚinitial_window_sizeÚhttp2_max_concurrent_streamsÚmax_concurrent_streamsÚhttp2_max_frame_sizeÚmax_frame_sizeÚhttp2_max_header_list_sizeÚmax_header_list_sizer   ÚH2Configurationr   ÚH2ConnectionÚh2_connr   Ú_read_bufferÚ_closedÚ_initialized)Úselfr&   r'   r(   r   s        r   Ú__init__zHTTP2ServerConnection.__init__<   sÐ   € ô 	ŒàˆŒØˆŒ	Ø&ˆÔð ˆŒô !,× 1Ñ 1Ó 3ˆÔð "$ˆÔð $'×#@Ñ#@ˆÔ Ø&)×&FÑ&FˆÔ#Ø!×6Ñ6ˆÔØ$'×$BÑ$BˆÔ!ô ×+Ñ+ØØ#ð ,ó 
ˆô ×'Ñ'¨vÐ'Ó6ˆŒô $›IˆÔð ˆŒØ!ˆÕr   c           
      óÖ  — | j                   ry| j                  j                  t        j                  j
                  | j                  t        j                  j                  | j                  t        j                  j                  | j                  t        j                  j                  | j                  i«       | j                  j                  «        | j                  «        d| _         y)z”Send initial HTTP/2 settings to client.

        Should be called after the SSL handshake completes and
        before processing any data.
        NT)r;   r8   Úupdate_settingsr   ÚSettingCodesÚMAX_CONCURRENT_STREAMSr1   ÚINITIAL_WINDOW_SIZEr/   ÚMAX_FRAME_SIZEr3   ÚMAX_HEADER_LIST_SIZEr5   Úinitiate_connectionÚ_send_pending_data©r<   s    r   rE   z)HTTP2ServerConnection.initiate_connectionk   s«   € ð ×ÒØð 	�‰×$Ñ$Ü×%Ñ%×<Ñ<¸d×>YÑ>YÜ×%Ñ%×9Ñ9¸4×;SÑ;SÜ×%Ñ%×4Ñ4°d×6IÑ6IÜ×%Ñ%×:Ñ:¸D×<UÑ<Uð	&
ô 	ð 	�‰×(Ñ(Ô*Ø×ÑÔ!Ø ˆÕr   Nc           
      ó  — | j                   j                  t        j                  j                  | j
                  t        j                  j                  | j                  t        j                  j                  | j                  t        j                  j                  | j                  i«       | j                   j                  |¬«       | j                  «        d| _        t        d| ¬«      }d}|j                   D ]  \  }}|dk(  sŒ|} n d|j"                  fd|j$                  fd	|j&                  fg}|r|j)                  d
|f«       |j                   D ��cg c]  \  }}|dvr|j+                  «       |f‘Œ }	}}|€,d}|j,                  �|j,                  j/                  «       xs d}|j1                  ||	z   | ¬«       |r|j3                  |d¬«       || j4                  d<   t7        || j8                  | j:                  «      S c c}}w )aM  Switch a connection to HTTP/2 after an Upgrade: h2c request.

        The upgraded request becomes stream 1 (RFC 7540 section 3.2). h2
        opens it in the state machine; the matching gunicorn stream is built
        here from the HTTP/1 request that carried the upgrade, so the worker
        sees an ordinary HTTP/2 request.

        ``body`` is the request payload. A caller that has to drain it before
        collecting the bytes pipelined behind the request passes it here;
        leaving it None reads it off the request.

        Returns the HTTP2Request for stream 1.
        )Úsettings_headerTr   )Ú	stream_idr   Ú ÚHOSTz:methodz:pathz:schemez
:authority)Ú
CONNECTIONÚUPGRADEzHTTP2-SETTINGSr   ©Ú
end_stream)r8   r?   r   r@   rA   r1   rB   r/   rC   r3   rD   r5   Úinitiate_upgrade_connectionrF   r;   r
   ÚheadersÚmethodÚuriÚschemeÚappendÚlowerÚbodyÚreadÚreceive_headersÚreceive_datar)   r   r&   r(   )
r<   rI   Ú	http1_reqrX   ÚstreamÚ	authorityÚnameÚvalueÚpseudoÚregulars
             r   Úinitiate_upgradez&HTTP2ServerConnection.initiate_upgrade€   sè  € ð 	�‰×$Ñ$Ü×%Ñ%×<Ñ<¸d×>YÑ>YÜ×%Ñ%×9Ñ9¸4×;SÑ;SÜ×%Ñ%×4Ñ4°d×6IÑ6IÜ×%Ñ%×:Ñ:¸D×<UÑ<Uð	&
ô 	ð 	�‰×0Ñ0ÀÐ0ÔQØ×ÑÔ!Ø ˆÔä q°TÔ:ˆØˆ	Ø$×,Ñ,ò 	‰KˆD�%Ø�v‹~Ø!�	Ùð	ð
 ˜	×(Ñ(Ð)Ø�i—m‘mÐ$Ø˜	×(Ñ(Ð)ð
ˆñ
 Ø�M‰M˜<¨Ð3Ô4Ø<E×<MÑ<M÷ O©[¨T°5ØÐ"MÑMð —J‘J“L %Ò(ð Oˆñ Oð ˆ<ØˆDØ�~‰~Ð)Ø —~‘~×*Ñ*Ó,Ò3°�Ø×Ñ˜v¨Ñ/À¸HÐÔEÙØ×Ñ °ÐÔ6Ø ˆ�‰�Q‰Ü˜F D§H¡H¨d×.>Ñ.>Ó?Ð?ùóOs   Å Hc                 ó*  — |€&	 | j                   j                  | j                  «      }|s	d| _        g S 	 | j                  j                  |«      }g }| j0                  r;t3        | j0                  «      t3        |«      z   }| j0                  j5                  «        |D ]'  }| j7                  |«      }|€Œ|j9                  |«       Œ) | j;                  «        |S # t        t        f$ r}t        d|› �«      ‚d}~ww xY w# t        j                  $ r9}| j                  t        j                  ¬«       t        t        |«      «      ‚d}~wt        j                   $ r9}| j                  t        j"                  ¬«       t        t        |«      «      ‚d}~wt        j$                  $ r[}t'        |dd«      }|�| j                  |¬«       n | j                  t        j(                  ¬«       t        t        |«      «      ‚d}~wt        j*                  $ r9}| j                  t        j,                  ¬«       t        t        |«      «      ‚d}~wt        j.                  $ r9}| j                  t        j(                  ¬«       t        t        |«      «      ‚d}~ww xY w)aA  Process received data and return completed requests.

        Args:
            data: Optional bytes to process. If None, reads from socket.

        Returns:
            list: List of HTTP2Request objects for completed requests

        Raises:
            HTTP2ConnectionError: On protocol or connection errors
        NzSocket read error: T©Ú
error_coderf   )r'   ÚrecvÚREAD_BUFFER_SIZEÚOSErrorÚIOErrorr   r:   r8   r[   r   ÚFlowControlErrorÚcloser	   ÚFLOW_CONTROL_ERRORr   ÚstrÚFrameTooLargeErrorÚFRAME_SIZE_ERRORÚInvalidSettingsValueErrorÚgetattrÚPROTOCOL_ERRORÚTooManyStreamsErrorÚREFUSED_STREAMÚProtocolErrorr,   ÚlistÚclearÚ_handle_eventrV   rF   )r<   ÚdataÚer   rf   Úcompleted_requestsÚeventÚrequests           r   r[   z"HTTP2ServerConnection.receive_data²   s'  € ð ˆ<ðFØ—y‘y—~‘~ d×&;Ñ&;Ó<�ñ àˆDŒLØˆIð	-Ø—\‘\×.Ñ.¨tÓ4ˆFð<  ÐØ× Ò Ü˜$×/Ñ/Ó0´4¸³<Ñ?ˆFØ×!Ñ!×'Ñ'Ô)Øò 	3ˆEØ×(Ñ(¨Ó/ˆGØÑ"Ø"×)Ñ)¨'Õ2ð	3ð 	×ÑÔ!à!Ð!øôk œWÐ%ò FÜ*Ð-@ÀÀÐ+DÓEÐEûðFûô ×.Ñ.ò 	-à�J‰J¤.×"CÑ"CˆJÔDÜ$¤S¨£VÓ,Ð,ûÜ×0Ñ0ò 	-à�J‰J¤.×"AÑ"AˆJÔBÜ$¤S¨£VÓ,Ð,ûÜ×7Ñ7ò 		-ô !  L°$Ó7ˆJØÐ%Ø—
‘
 j�
Õ1à—
‘
¤n×&CÑ&C�
ÔDÜ$¤S¨£VÓ,Ð,ûÜ×1Ñ1ò 	-à�J‰J¤.×"?Ñ"?ˆJÔ@Ü$¤S¨£VÓ,Ð,ûÜ×+Ñ+ò 	-à�J‰J¤.×"?Ñ"?ˆJÔ@Ü$¤S¨£VÓ,Ð,ûð	-ús_   „%C µC< ÃC9Ã&C4Ã4C9Ã<JÄ4EÅJÅ4FÆJÆ#AG9Ç9JÈ4IÉJÉ4JÊJc                 óÔ  — t        |t        j                  «      r| j                  |«      S t        |t        j                  «      r| j                  |«      S t        |t        j                  «      r| j                  |«      S t        |t        j                  «      r| j                  |«       yt        |t        j                  «      r	 yt        |t        j                  «      r| j                  |«       yt        |t        j                  «      r	 yt        |t        j                  «      r| j                  |«       yt        |t        j                   «      r| j#                  |«      S y)z¨Handle a single h2 event.

        Args:
            event: h2 event object

        Returns:
            HTTP2Request if a request is complete, None otherwise
        N)Ú
isinstancer   ÚRequestReceivedÚ_handle_request_receivedÚDataReceivedÚ_handle_data_receivedÚStreamEndedÚ_handle_stream_endedÚStreamResetÚ_handle_stream_resetÚWindowUpdatedÚPriorityUpdatedÚ_handle_priority_updatedÚSettingsAcknowledgedÚConnectionTerminatedÚ_handle_connection_terminatedÚTrailersReceivedÚ_handle_trailers_received©r<   r}   s     r   ry   z#HTTP2ServerConnection._handle_eventø   s.  € ô �eœZ×7Ñ7Ô8Ø×0Ñ0°Ó7Ð7ä˜œz×6Ñ6Ô7Ø×-Ñ-¨eÓ4Ð4ä˜œz×5Ñ5Ô6Ø×,Ñ,¨UÓ3Ð3ä˜œz×5Ñ5Ô6Ø×%Ñ% eÔ,ð" ô ˜œz×7Ñ7Ô8Øð ô ˜œz×9Ñ9Ô:Ø×)Ñ)¨%Ô0ð ô ˜œz×>Ñ>Ô?Øð ô ˜œz×>Ñ>Ô?Ø×.Ñ.¨uÔ5ð
 ô ˜œz×:Ñ:Ô;Ø×1Ñ1°%Ó8Ð8àr   c                 ó�   — |j                   }|j                  }t        || «      }|| j                  |<   |j	                  |d¬«       y)z{Handle RequestReceived event (HEADERS frame).

        Args:
            event: RequestReceived event with headers
        FrO   N)rJ   rR   r
   r)   rZ   )r<   r}   rJ   rR   r]   s        r   r‚   z.HTTP2ServerConnection._handle_request_received  sG   € ð —O‘Oˆ	Ø—-‘-ˆô ˜Y¨Ó-ˆØ"(ˆ�‰�YÑð 	×Ñ˜w°5ÐÕ9r   c                 óì  — |j                   }|j                  }| j                  j                  |«      }|€y|j	                  |d¬«       t        |«      dkD  r^	 | j                  j                  t        |«      |¬«       | j                  j                  t        |«      d¬«       | j                  «        yy# t        t        j                  f$ r# | j                  t        j                  ¬«       Y yw xY w)z¶Handle DataReceived event.

        Args:
            event: DataReceived event with body data

        Returns:
            None (request completion handled by StreamEnded)
        NFrO   r   )rJ   re   )rJ   rz   r)   Úgetr[   Úlenr8   Úincrement_flow_control_windowrF   Ú
ValueErrorr   rk   rl   r	   rm   )r<   r}   rJ   rz   r]   s        r   r„   z+HTTP2ServerConnection._handle_data_received/  sÖ   € ð —O‘Oˆ	Ø�z‰zˆà—‘×!Ñ! )Ó,ˆØˆ>àà×Ñ˜D¨UÐÔ3ô ˆt‹9�qŠ=ð	Ià—‘×:Ñ:¼3¸t»9ÐPYÐ:ÔZà—‘×:Ñ:¼3¸t»9ÐPTÐ:ÔUà×'Ñ'Ô)ñ
 øô	 ¤× ?Ñ ?Ð@ò Ià—
‘
¤n×&GÑ&G�
ÕHàð	Iús   ÁAB7 Â79C3Ã2C3c                 ó   — |j                   }| j                  j                  |«      }|€yd|_        d|_        |j
                  r|j
                  j                  «        t        || j                  | j                  «      S )z›Handle StreamEnded event.

        Args:
            event: StreamEnded event

        Returns:
            HTTP2Request for the completed request
        NT)
rJ   r)   r”   Úrequest_completeÚ_body_completeÚ_body_eventÚsetr   r&   r(   ©r<   r}   rJ   r]   s       r   r†   z*HTTP2ServerConnection._handle_stream_endedQ  sq   € ð —O‘Oˆ	Ø—‘×!Ñ! )Ó,ˆàˆ>Øð
 #'ˆÔØ $ˆÔØ×ÒØ×Ñ×"Ñ"Ô$ô ˜F D§H¡H¨d×.>Ñ.>Ó?Ð?r   c                 óŽ   — |j                   }| j                  j                  |«      }|�|j                  |j                  «       yy)ziHandle StreamReset event (RST_STREAM frame).

        Args:
            event: StreamReset event
        N)rJ   r)   r”   Úresetrf   r�   s       r   rˆ   z*HTTP2ServerConnection._handle_stream_resetk  s>   € ð —O‘Oˆ	Ø—‘×!Ñ! )Ó,ˆàÐØ�L‰L˜×)Ñ)Õ*ð r   c                 ó   — d| _         y)zwHandle ConnectionTerminated event (GOAWAY frame).

        Args:
            event: ConnectionTerminated event
        TN©r:   r‘   s     r   rŽ   z3HTTP2ServerConnection._handle_connection_terminatedx  s   € ð ˆ�r   c                 óÎ   — |j                   }| j                  j                  |«      }|€y|j                  |j                  «       t        || j                  | j                  «      S )z¾Handle TrailersReceived event.

        Args:
            event: TrailersReceived event with trailer headers

        Returns:
            HTTP2Request if this completes the request
        N)rJ   r)   r”   Úreceive_trailersrR   r   r&   r(   r�   s       r   r�   z/HTTP2ServerConnection._handle_trailers_received�  sV   € ð —O‘Oˆ	Ø—‘×!Ñ! )Ó,ˆàˆ>Øà×Ñ §¡Ô.ô ˜F D§H¡H¨d×.>Ñ.>Ó?Ð?r   c                 ó¸   — | j                   j                  |j                  «      }|�3|j                  |j                  |j
                  |j                  ¬«       yy)z‚Handle PriorityUpdated event (PRIORITY frame).

        Args:
            event: PriorityUpdated event with priority info
        N)ÚweightÚ
depends_onÚ	exclusive)r)   r”   rJ   Úupdate_priorityr¥   r¦   r§   )r<   r}   r]   s      r   r‹   z.HTTP2ServerConnection._handle_priority_updated•  sQ   € ð —‘×!Ñ! %§/¡/Ó2ˆØÐØ×"Ñ"Ø—|‘|Ø ×+Ñ+ØŸ/™/ð #õ ð r   c                 ól  — |dk  s|dk\  rt        d|› �«      ‚| j                  j                  |«      }|€t        d|› d�«      ‚dt        |«      fg}|D ]/  \  }}|j	                  |j                  «       t        |«      f«       Œ1 | j                  j                  ||d¬	«       | j                  «        y)
aÆ  Send an informational response (1xx) on a stream.

        This is used for 103 Early Hints and other 1xx responses.
        Informational responses are sent before the final response
        and do not end the stream.

        Args:
            stream_id: The stream ID
            status: HTTP status code (100-199)
            headers: List of (name, value) header tuples

        Raises:
            HTTP2Error: If status is not in 1xx range
        éd   éÈ   zInvalid informational status: NzStream z
 not foundú:statusFrO   )	r   r)   r”   rn   rV   rW   r8   Úsend_headersrF   )r<   rJ   ÚstatusrR   r]   Úresponse_headersr_   r`   s           r   Úsend_informationalz(HTTP2ServerConnection.send_informational£  s¿   € ð �CŠ<˜6 Sš=ÜÐ=¸f¸XÐFÓGÐGà—‘×!Ñ! )Ó,ˆØˆ>Ü˜w y k°Ð<Ó=Ð=ð '¬¨F«Ð4Ð5ÐØ"ò 	@‰KˆD�%à×#Ñ# T§Z¡Z£\´3°u³:Ð$>Õ?ð	@ð
 	�‰×!Ñ! )Ð-=È%Ð!ÔPØ×ÑÕ!r   c                 óF  — | j                   j                  |«      }|€ydt        |«      fg}|D ]/  \  }}|j                  |j	                  «       t        |«      f«       Œ1 | j
                  j                  |||¬«       |j                  ||¬«       | j                  «        y)a  Send response headers on a stream without ending it.

        Returns False if the stream is already gone. Split out of
        send_response() so a response can be streamed: headers first, then
        any number of data frames, then end_stream().
        Fr¬   rO   T)r)   r”   rn   rV   rW   r8   r­   rF   )	r<   rJ   r®   rR   rP   r]   r¯   r_   r`   s	            r   Úsend_response_headersz+HTTP2ServerConnection.send_response_headersÃ  sª   € ð —‘×!Ñ! )Ó,ˆØˆ>àð '¬¨F«Ð4Ð5ÐØ"ò 	@‰KˆD�%à×#Ñ# T§Z¡Z£\´3°u³:Ð$>Õ?ð	@ð 	�‰×!Ñ! )Ð-=Ø-7ð 	"ô 	9à×ÑÐ,¸ÐÔDØ×ÑÔ!Ør   c                 óX  — | j                   j                  |«      €y|r| j                  ||«       y	 | j                  j	                  |dd¬«       | j                   |   j	                  dd¬«       | j                  «        y# t        j                  $ r | j                  |«       Y yw xY w)z;Close the sending half of a stream, with trailers if given.FTr   rO   )	r)   r”   Úsend_trailersr8   Ú	send_datarF   r   ÚStreamClosedErrorÚcleanup_stream)r<   rJ   Útrailerss      r   rP   z HTTP2ServerConnection.end_streamÜ  s£   € à�<‰<×Ñ˜IÓ&Ð.ØÙØ×Ñ˜y¨(Ô3Øð	Ø�L‰L×"Ñ" 9¨c¸dÐ"ÔCØ�L‰L˜Ñ#×-Ñ-¨c¸dÐ-ÔCØ×#Ñ#Ô%ð øô ×/Ñ/ò 	Ø×Ñ 	Ô*Ùð	ús   ³AB Â$B)Â(B)c                 óP  — |du xs t        |«      dk(  }	 | j                  ||||¬«      sy|r"t        |«      dkD  r| j                  ||d¬«       y# t        j                  $ rA | j
                  j                  |«      }|�|j                  «        | j                  |«       Y yw xY w)a©  Send a response on a stream.

        Args:
            stream_id: The stream ID to respond on
            status: HTTP status code (int)
            headers: List of (name, value) header tuples
            body: Optional response body bytes

        Raises:
            HTTP2Error: If stream not found or in invalid state

        Returns:
            bool: True if response sent, False if stream was already closed
        Nr   rO   FT)	r•   r²   rµ   r   r¶   r)   r”   rl   r·   )r<   rJ   r®   rR   rX   rP   r]   s          r   Úsend_responsez#HTTP2ServerConnection.send_responseô  sª   € ð ˜T�\Ò3¤S¨£Y°!¡^ˆ
ð	Ø×-Ñ-¨i¸ÀØ9Cð .ô Eàáœ˜D›	 AšØ—‘˜y¨$¸4�Ô@ØøÜ×/Ñ/ò 	à—\‘\×%Ñ% iÓ0ˆFØÐ!Ø—‘”Ø×Ñ 	Ô*Ùð	ús   –A ¬$A ÁAB%Â$B%c                 óö  — d}	 t        j                  «       }|j                  | j                  t         j                  «       d}	 t        |«      D �]  }| j                  j                  |«      }|dkD  r|} �n|j                  d¬«      }|sŒ>	 | j                  j                  | j                  «      }|s	d| _         nÁ	 | j                  j%                  |«      }	|	D ]p  }
t'        |
t(        j*                  «      r|
j,                  |k(  sŒ-d} nTt'        |
t(        j.                  «      rd| _        d} n/| j0                  j3                  |
«       Œr | j5                  «        �Œ n | j                  j                  |«      }|j7                  «        |S # t
        t        f$ r Y yw xY w# t        t        t        j                   f$ r Y  ŒHw xY w# t        j                   $ r Y  Œbw xY w# |j7                  «        w xY w)z‹Wait for flow control window to become positive.

        Returns:
            int: Available window size, or -1 if waiting failed
        é2   éÿÿÿÿr   gš™™™™™¹?)ÚtimeoutT)Ú	selectorsÚDefaultSelectorÚregisterr'   Ú
EVENT_READÚ	TypeErrorr—   Úranger8   Úlocal_flow_control_windowÚselectrg   rh   ri   rj   r   rv   r:   r[   r€   r   r‡   rJ   r�   r,   rV   rF   rl   )r<   rJ   Úmax_wait_attemptsÚselÚresultÚ_Ú	availableÚreadyÚincomingr   r}   s              r   Ú_wait_for_flow_control_windowz3HTTP2ServerConnection._wait_for_flow_control_window  sÖ  € ð Ðð	Ü×+Ñ+Ó-ˆCØ�L‰L˜Ÿ™¤I×$8Ñ$8Ô9ð
 ˆð+	ÜÐ,Ó-ó (K�Ø ŸL™L×BÑBÀ9ÓM�	Ø˜q’=Ø&�FÚàŸ
™
¨3˜
Ó/�ÚðØ#'§9¡9§>¡>°$×2GÑ2GÓ#H˜ñ $Ø'+˜œÙðØ!%§¡×!:Ñ!:¸8Ó!D˜ð "(ò !˜Ü% e¬Z×-CÑ-CÔDØ$Ÿ™°)Ó;Ø)+ Ù %Ü'¨¬z×/NÑ/NÔOØ+/˜DœLØ%'˜FÙ!ð !×1Ñ1×8Ñ8¸Õ?ð!ð  ×/Ñ/Ô1Ù ÙðK(KðP Ÿ™×?Ñ?À	ÓJ�à�I‰IŒKàˆøôe œ:Ð&ò 	áð	ûô  $¤W¬n×.JÑ.JÐKò Úðûô *×7Ñ7ò Úðûð2 �I‰I�Kúsm   „>F ÁAG& Â%F'Â4G& Ã GÃ.G& Ä
A6G& ÆF$Æ#F$Æ'G	ÇG& ÇG	Ç	G& ÇG#ÇG& Ç"G#Ç#G& Ç&G8c                 ó¬  — | j                   j                  |«      }|€y|}	 |rÔ| j                  j                  |«      }t	        || j
                  t        |«      «      }|dk  rG| j                  «        | j                  |«      }|dk  ryt	        || j
                  t        |«      «      }|d| }||d }|xr t        |«      dk(  }	| j                  j                  |||	¬«       | j                  «        |rŒÔ|j                  ||¬«       y# t        j                  t        j                  f$ r$ |j                  «        | j                  |«       Y yw xY w)a  Send data on a stream.

        Args:
            stream_id: The stream ID
            data: Body data bytes
            end_stream: Whether this ends the stream

        Returns:
            bool: True if data sent, False if stream was already closed
        NFr   rO   T)r)   r”   r8   rÅ   Úminr3   r•   rF   rÎ   rµ   r   r¶   rk   rl   r·   )
r<   rJ   rz   rP   r]   Údata_to_sendrË   Ú
chunk_sizeÚchunkÚis_finals
             r   rµ   zHTTP2ServerConnection.send_dataS  sH  € ð —‘×!Ñ! )Ó,ˆØˆ>Øàˆð	ÙØ ŸL™L×BÑBÀ9ÓM�	Ü  ¨D×,?Ñ,?ÄÀ\ÓARÓS�
à ’?à×+Ñ+Ô-Ø $× BÑ BÀ9Ó M�IØ  A’~Ø$Ü!$ Y°×0CÑ0CÄSÈÓEVÓ!W�Jà$ [ jÐ1�Ø+¨J¨KÐ8�Ø%Ò@¬#¨lÓ*;¸qÑ*@�à—‘×&Ñ& y°%ÀHÐ&ÔMØ×'Ñ'Ô)ò# ð& ×Ñ˜T¨jÐÔ9ØøÜ×0Ñ0´.×2QÑ2QÐRò 	à�L‰LŒNØ×Ñ 	Ô*Ùð		ús    ¢A(D ÂA,D Ã8D ÄAEÅEc                 óþ  — | j                   j                  |«      }|€y|j                  syg }|D ]Q  \  }}|j                  «       }|j	                  d«      rt        d|› d�«      ‚|j                  |t        |«      f«       ŒS 	 | j                  j                  ||d¬«       |j                  |«       | j                  «        y# t        j                  $ r$ |j                  «        | j                  |«       Y yw xY w)aë  Send trailing headers on a stream.

        Trailers are headers sent after the response body, commonly used
        for gRPC status codes, checksums, and timing information.

        Args:
            stream_id: The stream ID
            trailers: List of (name, value) trailer tuples

        Raises:
            HTTP2Error: If stream not found, headers not sent, or pseudo-headers used

        Returns:
            bool: True if trailers sent, False if stream was already closed
        Fú:zPseudo-header 'z' not allowed in trailersTrO   )r)   r”   Úresponse_headers_sentrW   Ú
startswithr   rV   rn   r8   r­   r´   rF   r   r¶   rl   r·   )r<   rJ   r¸   r]   Útrailer_headersr_   r`   Úlnames           r   r´   z#HTTP2ServerConnection.send_trailers  sõ   € ð  —‘×!Ñ! )Ó,ˆØˆ>àØ×+Ò+àð ˆØ#ò 	8‰KˆD�%Ø—J‘J“LˆEØ×Ñ Ô$Ü  ?°4°&Ð8QÐ!RÓSÐSØ×"Ñ" E¬3¨u«:Ð#6Õ7ð		8ð
	à�L‰L×%Ñ% i°ÈTÐ%ÔRØ× Ñ  Ô1Ø×#Ñ#Ô%ØøÜ×/Ñ/ò 	à�L‰LŒNØ×Ñ 	Ô*Ùð		ús   Â?C Ã4C<Ã;C<c                 ó¨   — |r|j                  «       nd}dt        t        |«      «      fg}|r|j                  d«       | j	                  ||||«       y)z»Send an error response on a stream.

        Args:
            stream_id: The stream ID
            status_code: HTTP status code
            message: Optional error message body
        r   zcontent-length)zcontent-typeztext/plain; charset=utf-8N)Úencodern   r•   rV   rº   )r<   rJ   Ústatus_codeÚmessagerX   rR   s         r   Ú
send_errorz HTTP2ServerConnection.send_error«  sM   € ñ $+ˆw�~‰~Ô°ˆØ$¤c¬#¨d«)£nÐ5Ð6ˆÙØ�N‰NÐHÔIà×Ñ˜9 k°7¸DÕAr   c                 óº   — | j                   j                  |«      }|�|j                  |«       | j                  j	                  ||¬«       | j                  «        y)z¡Reset a stream with RST_STREAM.

        Args:
            stream_id: The stream ID to reset
            error_code: HTTP/2 error code (default: CANCEL)
        Nre   )r)   r”   rŸ   r8   Úreset_streamrF   )r<   rJ   rf   r]   s       r   rá   z"HTTP2ServerConnection.reset_streamº  sM   € ð —‘×!Ñ! )Ó,ˆØÐØ�L‰L˜Ô$à�‰×!Ñ! )¸
Ð!ÔCØ×ÑÕ!r   c                 ó
  — | j                   ryd| _         |€1| j                  r#t        | j                  j                  «       «      nd}	 | j                  j                  |¬«       | j                  «        y# t        $ r Y yw xY w)zÊClose the connection gracefully with GOAWAY.

        Args:
            error_code: HTTP/2 error code (default: NO_ERROR)
            last_stream_id: Last processed stream ID (default: highest)
        NTr   re   )r:   r)   ÚmaxÚkeysr8   Úclose_connectionrF   Ú	Exception)r<   rf   Úlast_stream_ids      r   rl   zHTTP2ServerConnection.closeÈ  sr   € ð �<Š<ØàˆŒàÐ!à9=¿ºœS §¡×!2Ñ!2Ó!4Ô5È1ˆNð	Ø�L‰L×)Ñ)°ZÐ)Ô@Ø×#Ñ#Õ%øÜò 	Ùð	ús   Á	,A6 Á6	BÂBc                 óÎ   — | j                   j                  «       }|r	 | j                  j                  |«       yy# t        t
        f$ r}d| _        t        d|› �«      ‚d}~ww xY w)z,Send any pending data from h2 to the socket.TzSocket write error: N)r8   rÑ   r'   Úsendallri   rj   r:   r   )r<   rz   r{   s      r   rF   z(HTTP2ServerConnection._send_pending_dataÞ  sg   € à�|‰|×(Ñ(Ó*ˆÙðGØ—	‘	×!Ñ! $Õ'ð øô œWÐ%ò GØ#�”Ü*Ð-AÀ!ÀÐ+EÓFÐFûðGús   ž; »A$Á
AÁA$c                 ó   — | j                   S )zCheck if connection is closed.r¡   rG   s    r   Ú	is_closedzHTTP2ServerConnection.is_closedè  s   € ð �|‰|Ðr   c                 ó<   — | j                   j                  |d«       y)zvRemove a stream after processing is complete.

        Args:
            stream_id: The stream ID to clean up
        N)r)   Úpop)r<   rJ   s     r   r·   z$HTTP2ServerConnection.cleanup_streamí  s   € ð 	�‰×Ñ˜ DÕ)r   c                 óN   — dt        | j                  «      › d| j                  › d�S )Nz<HTTP2ServerConnection streams=z closed=ú>)r•   r)   r:   rG   s    r   Ú__repr__zHTTP2ServerConnection.__repr__õ  s0   € ðÜ˜4Ÿ<™<Ó(Ð)ð *Ø—l‘l�^ 1ð&ð	
r   )N)F)é   )r   N) Ú__name__Ú
__module__Ú__qualname__Ú__doc__rh   r=   rE   rc   r[   ry   r‚   r„   r†   rˆ   rŽ   r�   r‹   r°   r²   rP   rº   rÎ   rµ   r´   rß   rá   rl   rF   Úpropertyrë   r·   rð   r   r   r   r"   r"   1   sµ   „ ñð Ðò-"ò^!ó*0@ódD"òL$òL:ò" òD@ò4
+òò@ò(ò"ðB */óó2ó0ò@=ó~*òX*óXBó"óò,Gð ñó ðò*ó
r   r"   )rõ   r*   r¿   Úior   Úerrorsr   r   r   r   r	   r]   r
   r~   r   r   r   r   r   r   r    r"   Ú__all__r   r   r   ú<module>rú      s^   ðñó Û Ý ÷õ õ  Ý !ð €Ø€
Ø€
Ø€Ø€ò"÷"I
ñ I
ðX #Ð
#�r   