+
    j*                     d    R t ^ RIHtHt ^ RIHt ^RIHt  ! R R]4      t ! R R4      t	RR.t
R# )	zd
HTTP/2 stream state management.

Each HTTP/2 stream represents a single request/response exchange.
)Enumauto)BytesIO)HTTP2StreamErrorc                   |    ] tR t^tRt]! 4       t]! 4       t]! 4       t]! 4       t	]! 4       t
]! 4       t]! 4       tRtR# )StreamStatez8HTTP/2 stream states as defined in RFC 7540 Section 5.1. N)__name__
__module____qualname____firstlineno____doc__r   IDLERESERVED_LOCALRESERVED_REMOTEOPENHALF_CLOSED_LOCALHALF_CLOSED_REMOTECLOSED__static_attributes__r       J/var/www/idalgo/venv/lib/python3.14/site-packages/gunicorn/http2/stream.pyr   r      s8    B6DVNfO6DVFr   r   c                      a  ] tR t^t o RtR t]R 4       t]R 4       t]R 4       t	]R 4       t
RR ltRR ltR	 tRR
 ltRR ltR tRR ltR tRR ltR tR tR tR tR tR tR tRtV tR# )HTTP2StreamzRepresents a single HTTP/2 stream.

Manages stream state, headers, and body data for a single
request/response exchange within an HTTP/2 connection.
c                >   Wn         W n        \        P                  V n        . V n        \        4       V n        RV n        RV n	        RV n
        RV n        VP                  V n        RV n        RV n        ^V n        ^ V n        RV n        . V n        RV n        RV n        R# )zInitialize an HTTP/2 stream.

Args:
    stream_id: The unique stream identifier (odd for client-initiated)
    connection: The parent HTTP2ServerConnection
FN)	stream_id
connectionr   r   staterequest_headersr   request_bodyrequest_completeresponse_startedresponse_headers_sentresponse_completeinitial_window_sizewindow_sizetrailersresponse_trailerspriority_weightpriority_depends_onpriority_exclusive_body_chunks_body_event_body_complete)selfr   r   s   &&&r   __init__HTTP2Stream.__init__%   s     #$ !%%
  "#I % !&%*"!& &99  "&  "#$ "' #r   c                .    V P                   ^,          ^8H  # )z;Check if this is a client-initiated stream (odd stream ID).r   r.   s   &r   is_client_streamHTTP2Stream.is_client_streamO        ~~!Q&&r   c                .    V P                   ^,          ^ 8H  # )z<Check if this is a server-initiated stream (even stream ID).r2   r3   s   &r   is_server_streamHTTP2Stream.is_server_streamT   r6   r   c                \    V P                   \        P                  \        P                  39   # )z&Check if this stream can receive data.)r   r   r   r   r3   s   &r   can_receiveHTTP2Stream.can_receiveY   s,     zz))
 
 	
r   c                \    V P                   \        P                  \        P                  39   # )z#Check if this stream can send data.)r   r   r   r   r3   s   &r   can_sendHTTP2Stream.can_senda   s,     zz**
 
 	
r   c                   V P                   \        P                  8X  d   \        P                  V n         M\V P                   \        P                  \        P                  39  d.   \        V P                  RV P                   P                   24      hV P                  P                  V4       V'       d   V P                  4        RV n        R# R# )zProcess received HEADERS frame.

Args:
    headers: List of (name, value) tuples
    end_stream: True if END_STREAM flag is set

Raises:
    HTTP2StreamError: If headers received in invalid state
z Cannot receive headers in state TN)r   r   r   r   r   r   r   namer   extend_half_close_remoter    r.   headers
end_streams   &&&r   receive_headersHTTP2Stream.receive_headersi   s     ::)))$))DJZZ 0 0+2O2OPP"24::??2CD 
 	##G,##%$(D! r   c                   V P                   '       g.   \        V P                  RV P                  P                   24      hV'       dH   V P
                  P                  V4       V P                  '       d   V P                  P                  4        V P                  P                  V4       V'       dO   V P                  4        RV n        RV n        V P                  '       d   V P                  P                  4        R# R# R# )zProcess received DATA frame with streaming support.

Args:
    data: Bytes received
    end_stream: True if END_STREAM flag is set

Raises:
    HTTP2StreamError: If data received in invalid state
zCannot receive data in state TN)r;   r   r   r   rA   r+   appendr,   setr   writerC   r    r-   r.   datarF   s   &&&r   receive_dataHTTP2Stream.receive_data   s     "/

/@A  $$T*  $$& 	%##%$(D!"&D  $$&  	 r   c                    V P                   '       g.   \        V P                  RV P                  P                   24      hWn        V P                  4        RV n        R# )zUProcess received trailing headers.

Args:
    trailers: List of (name, value) tuples
z!Cannot receive trailers in state TN)r;   r   r   r   rA   r&   rC   r    r.   r&   s   &&r   receive_trailersHTTP2Stream.receive_trailers   sR     "3DJJOO3DE 
 !! $r   c                    V P                   '       g.   \        V P                  RV P                  P                   24      hRV n        RV n        V'       d   V P                  4        RV n        R# R# )zMark headers as sent.

Args:
    headers: List of (name, value) tuples to send
    end_stream: True if this completes the response

Raises:
    HTTP2StreamError: If headers cannot be sent in current state
zCannot send headers in state TN)	r>   r   r   r   rA   r!   r"   _half_close_localr#   rD   s   &&&r   send_headersHTTP2Stream.send_headers   sb     }}}"/

/@A 
 !%%)"""$%)D" r   c                    V P                   '       g.   \        V P                  RV P                  P                   24      hV'       d   V P                  4        RV n        R# R# )zMark data as sent.

Args:
    data: Bytes to send
    end_stream: True if this completes the response

Raises:
    HTTP2StreamError: If data cannot be sent in current state
zCannot send data in state TN)r>   r   r   r   rA   rV   r#   rM   s   &&&r   	send_dataHTTP2Stream.send_data   sR     }}}",TZZ__,=> 
 ""$%)D" r   c                    V P                   '       g.   \        V P                  RV P                  P                   24      hWn        V P                  4        RV n        R# )zMark trailers as sent and close the stream.

Args:
    trailers: List of (name, value) trailer tuples

Raises:
    HTTP2StreamError: If trailers cannot be sent in current state
zCannot send trailers in state TN)r>   r   r   r   rA   r'   rV   r#   rR   s   &&r   send_trailersHTTP2Stream.send_trailers   sP     }}}"00AB  "* !%r   c                L    \         P                  V n        RV n        RV n        R# )z^Reset this stream with RST_STREAM.

Args:
    error_code: HTTP/2 error code (default: CANCEL)
TNr   r   r   r#   r    )r.   
error_codes   &&r   resetHTTP2Stream.reset   s!     !''
!% $r   c                L    \         P                  V n        RV n        RV n        R# )zClose this stream normally.TNr`   r3   s   &r   closeHTTP2Stream.close   s     ''
!% $r   Nc                p    Ve   \        ^\        RV4      4      V n        Ve   W n        Ve	   W0n        R# R# )zUpdate stream priority from PRIORITY frame.

Args:
    weight: Priority weight (1-256), higher = more resources
    depends_on: Stream ID this stream depends on
    exclusive: Whether this is an exclusive dependency
N   )maxminr(   r)   r*   )r.   weight
depends_on	exclusives   &&&&r   update_priorityHTTP2Stream.update_priority   s=     #&q#c6*:#;D !'1$ &/# !r   c                4   V P                   \        P                  8X  d   \        P                  V n         R# V P                   \        P                  8X  d   \        P
                  V n         R# \        V P                  RV P                   P                   24      h)z(Transition to half-closed (local) state.z!Cannot half-close local in state N)	r   r   r   r   r   r   r   r   rA   r3   s   &r   rV   HTTP2Stream._half_close_local  sg    ::)))$66DJZZ;999$++DJ"3DJJOO3DE r   c                4   V P                   \        P                  8X  d   \        P                  V n         R# V P                   \        P                  8X  d   \        P
                  V n         R# \        V P                  RV P                   P                   24      h)z)Transition to half-closed (remote) state.z"Cannot half-close remote in state N)	r   r   r   r   r   r   r   r   rA   r3   s   &r   rC   HTTP2Stream._half_close_remote  sg    ::)))$77DJZZ;888$++DJ"4TZZ__4EF r   c                6    V P                   P                  4       # )zJGet the complete request body.

Returns:
    bytes: The request body data
)r   getvaluer3   s   &r   get_request_bodyHTTP2Stream.get_request_body%  s       ))++r   c                  "   ^ RI pV P                  fT   VP                  4       V n        V P                  '       g   V P                  '       d   V P                  P                  4         V P                  '       d   V P                  P                  ^ 4      # V P                  '       d   R# V P                  P                  4        V P                  P                  4       G Rj  xL
  K   L5i)z~Read next body chunk asynchronously for streaming.

Returns:
    bytes: Next chunk of body data, or None if body is complete.
N)	asyncior,   Eventr+   r-   rK   popclearwait)r.   ry   s   & r   read_body_chunkHTTP2Stream.read_body_chunk-  s      	 #&}}D    D$7$7$7  $$&   ((,,Q// """ ""$""'')))s(   9C*C*,C*;,C*(9C*!C("C*c                n    / pV P                    F"  w  r#VP                  R4      '       g   K  W1V&   K$  	  V# )zExtract HTTP/2 pseudo-headers from request headers.

Returns:
    dict: Mapping of pseudo-header names to values
          (e.g., {':method': 'GET', ':path': '/'})
:r   
startswith)r.   pseudorA   values   &   r   get_pseudo_headersHTTP2Stream.get_pseudo_headersJ  s8     //KDs##$t 0 r   c                    V P                    UUu. uF!  w  rVP                  R4      '       d   K  W3NK#  	  upp# u uppi )ztGet regular (non-pseudo) headers from request.

Returns:
    list: List of (name, value) tuples for regular headers
r   r   )r.   rA   r   s   &  r   get_regular_headersHTTP2Stream.get_regular_headersW  sA      $33
3??3' TM3
 	
 
s   ;;c           	         R V P                    RV P                  P                   RV P                   RV P                   R2	# )z<HTTP2Stream id=z state=z req_complete=z resp_complete=>)r   r   rA   r    r#   r3   s   &r   __repr__HTTP2Stream.__repr__c  sO    t~~. /ZZ__% & 112 3!334A7	
r   )r+   r-   r,   r   r)   r*   r(   r   r    r   r#   r"   r!   r'   r   r   r&   r%   )F)   )NNN)r	   r
   r   r   r   r/   propertyr4   r8   r;   r>   rG   rO   rS   rW   rZ   r]   rb   re   rn   rV   rC   rv   r~   r   r   r   r   __classdictcell__)__classdict__s   @r   r   r      s     ($T ' ' ' ' 
 
 
 
)0'@% *.*(&$%%0

,*:


 
r   r   N)r   enumr   r   ior   errorsr   r   r   __all__r   r   r   <module>r      s:      $	$ 	K
 K
\
 -
(r   