
    gST                        d Z ddlZddlmZmZ  G d d      Z G d de      Z G d	 d
e      Z G d de      Z G d de      Z	 G d de	      Z
 G d de	      Z G d de	      Z G d de	      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Z G d' d(e      Z G d) d*e      Z G d+ d,e      Z G d- d.e      Z G d/ d0e      Z G d1 d2e      Zd3 Zy)4a  
h2/events
~~~~~~~~~

Defines Event types for HTTP/2.

Events are returned by the H2 state machine to allow implementations to keep
track of events triggered by receiving data. Each time data is provided to the
H2 state machine it processes the data and returns a list of Event objects.
    N   )ChangedSetting_setting_code_from_intc                       e Zd ZdZy)Eventz#
    Base class for h2 events.
    N__name__
__module____qualname____doc__     >/var/www/openai/venv/lib/python3.12/site-packages/h2/events.pyr   r      s     	r   r   c                       e Zd ZdZd Zd Zy)RequestReceiveda  
    The RequestReceived event is fired whenever request headers are received.
    This event carries the HTTP headers for the given request and the stream ID
    of the new stream.

    .. versionchanged:: 2.3.0
       Changed the type of ``headers`` to :class:`HeaderTuple
       <hpack:hpack.HeaderTuple>`. This has no effect on current users.

    .. versionchanged:: 2.4.0
       Added ``stream_ended`` and ``priority_updated`` properties.
    c                 <    d | _         d | _        d | _        d | _        y N	stream_idheadersstream_endedpriority_updatedselfs    r   __init__zRequestReceived.__init__%   &      ! !%r   c                 <    d| j                   d| j                  dS )Nz<RequestReceived stream_id:
, headers:>r   r   r   s    r   __repr__zRequestReceived.__repr__:       NNDLL
 	
r   Nr	   r
   r   r   r   r!   r   r   r   r   r          %*
r   r   c                       e Zd ZdZd Zd Zy)ResponseReceiveda  
    The ResponseReceived event is fired whenever response headers are received.
    This event carries the HTTP headers for the given response and the stream
    ID of the new stream.

    .. versionchanged:: 2.3.0
       Changed the type of ``headers`` to :class:`HeaderTuple
       <hpack:hpack.HeaderTuple>`. This has no effect on current users.

   .. versionchanged:: 2.4.0
      Added ``stream_ended`` and ``priority_updated`` properties.
    c                 <    d | _         d | _        d | _        d | _        y r   r   r   s    r   r   zResponseReceived.__init__M   r   r   c                 <    d| j                   d| j                  dS )Nz<ResponseReceived stream_id:r   r   r    r   s    r   r!   zResponseReceived.__repr__b   r"   r   Nr#   r   r   r   r&   r&   @   r$   r   r&   c                       e Zd ZdZd Zd Zy)TrailersReceiveda  
    The TrailersReceived event is fired whenever trailers are received on a
    stream. Trailers are a set of headers sent after the body of the
    request/response, and are used to provide information that wasn't known
    ahead of time (e.g. content-length). This event carries the HTTP header
    fields that form the trailers and the stream ID of the stream on which they
    were received.

    .. versionchanged:: 2.3.0
       Changed the type of ``headers`` to :class:`HeaderTuple
       <hpack:hpack.HeaderTuple>`. This has no effect on current users.

    .. versionchanged:: 2.4.0
       Added ``stream_ended`` and ``priority_updated`` properties.
    c                 <    d | _         d | _        d | _        d | _        y r   r   r   s    r   r   zTrailersReceived.__init__x   s&      ! !%r   c                 <    d| j                   d| j                  dS )Nz<TrailersReceived stream_id:r   r   r    r   s    r   r!   zTrailersReceived.__repr__   r"   r   Nr#   r   r   r   r*   r*   h   s    %(
r   r*   c                       e Zd ZdZy)_HeadersSentz
    The _HeadersSent event is fired whenever headers are sent.

    This is an internal event, used to determine validation steps on
    outgoing header blocks.
    Nr   r   r   r   r.   r.      s     	r   r.   c                       e Zd ZdZy)_ResponseSentz
    The _ResponseSent event is fired whenever response headers are sent
    on a stream.

    This is an internal event, used to determine validation steps on
    outgoing header blocks.
    Nr   r   r   r   r0   r0           	r   r0   c                       e Zd ZdZy)_RequestSentz
    The _RequestSent event is fired whenever request headers are sent
    on a stream.

    This is an internal event, used to determine validation steps on
    outgoing header blocks.
    Nr   r   r   r   r3   r3      r1   r   r3   c                       e Zd ZdZy)_TrailersSentaf  
    The _TrailersSent event is fired whenever trailers are sent on a
    stream. Trailers are a set of headers sent after the body of the
    request/response, and are used to provide information that wasn't known
    ahead of time (e.g. content-length).

    This is an internal event, used to determine validation steps on
    outgoing header blocks.
    Nr   r   r   r   r5   r5      s     	r   r5   c                       e Zd ZdZy)_PushedRequestSentz
    The _PushedRequestSent event is fired whenever pushed request headers are
    sent.

    This is an internal event, used to determine validation steps on outgoing
    header blocks.
    Nr   r   r   r   r7   r7      r1   r   r7   c                       e Zd ZdZd Zd Zy)InformationalResponseReceiveda=  
    The InformationalResponseReceived event is fired when an informational
    response (that is, one whose status code is a 1XX code) is received from
    the remote peer.

    The remote peer may send any number of these, from zero upwards. These
    responses are most commonly sent in response to requests that have the
    ``expect: 100-continue`` header field present. Most users can safely
    ignore this event unless you are intending to use the
    ``expect: 100-continue`` flow, or are for any reason expecting a different
    1XX status code.

    .. versionadded:: 2.2.0

    .. versionchanged:: 2.3.0
       Changed the type of ``headers`` to :class:`HeaderTuple
       <hpack:hpack.HeaderTuple>`. This has no effect on current users.

    .. versionchanged:: 2.4.0
       Added ``priority_updated`` property.
    c                 .    d | _         d | _        d | _        y r   )r   r   r   r   s    r   r   z&InformationalResponseReceived.__init__   s       !%r   c                 <    d| j                   d| j                  dS )Nz)<InformationalResponseReceived stream_id:r   r   r    r   s    r   r!   z&InformationalResponseReceived.__repr__   r"   r   Nr#   r   r   r   r9   r9      s    *%
r   r9   c                       e Zd ZdZd Zd Zy)DataReceiveda	  
    The DataReceived event is fired whenever data is received on a stream from
    the remote peer. The event carries the data itself, and the stream ID on
    which the data was received.

    .. versionchanged:: 2.4.0
       Added ``stream_ended`` property.
    c                 <    d | _         d | _        d | _        d | _        y r   )r   dataflow_controlled_lengthr   r   s    r   r   zDataReceived.__init__   s&     	 '+# !r   c           
      n    d| j                   d| j                  dt        | j                  d d       dS )Nz<DataReceived stream_id:z, flow_controlled_length:z, data:   r   )r   r@   _bytes_representationr?   r   s    r   r!   zDataReceived.__repr__  s0    
 ++%diin5	
r   Nr#   r   r   r   r=   r=      s    !(	
r   r=   c                       e Zd ZdZd Zd Zy)WindowUpdatedav  
    The WindowUpdated event is fired whenever a flow control window changes
    size. HTTP/2 defines flow control windows for connections and streams: this
    event fires for both connections and streams. The event carries the ID of
    the stream to which it applies (set to zero if the window update applies to
    the connection), and the delta in the window size.
    c                      d | _         d | _        y r   r   deltar   s    r   r   zWindowUpdated.__init__&  s      
r   c                 <    d| j                   d| j                  dS )Nz<WindowUpdated stream_id:z, delta:r   rG   r   s    r   r!   zWindowUpdated.__repr__.  s    NNDJJ
 	
r   Nr#   r   r   r   rE   rE     s    
r   rE   c                   ,    e Zd ZdZd Zed        Zd Zy)RemoteSettingsChangedaT  
    The RemoteSettingsChanged event is fired whenever the remote peer changes
    its settings. It contains a complete inventory of changed settings,
    including their previous values.

    In HTTP/2, settings changes need to be acknowledged. h2 automatically
    acknowledges settings changes for efficiency. However, it is possible that
    the caller may not be happy with the changed setting.

    When this event is received, the caller should confirm that the new
    settings are acceptable. If they are not acceptable, the user should close
    the connection with the error code :data:`PROTOCOL_ERROR
    <h2.errors.ErrorCodes.PROTOCOL_ERROR>`.

    .. versionchanged:: 2.0.0
       Prior to this version the user needed to acknowledge settings changes.
       This is no longer the case: h2 now automatically acknowledges
       them.
    c                     i | _         y r   changed_settingsr   s    r   r   zRemoteSettingsChanged.__init__H       !#r   c                      |        }|j                         D ]=  \  }}t        |      }|j                  |      }t        |||      }||j                  |<   ? |S )a  
        Build a RemoteSettingsChanged event from a set of changed settings.

        :param old_settings: A complete collection of old settings, in the form
                             of a dictionary of ``{setting: value}``.
        :param new_settings: All the changed settings and their new values, in
                             the form of a dictionary of ``{setting: value}``.
        )itemsr   getr   rN   )clsold_settingsnew_settingsesetting	new_valueoriginal_valuechanges           r   from_settingsz#RemoteSettingsChanged.from_settingsN  sb     E"."4"4"6GY,W5G)--g6N#G^YGF*0Aw'	 #7 r   c                 j    ddj                  d | j                  j                         D              dS )Nz)<RemoteSettingsChanged changed_settings:{, c              3   2   K   | ]  }t        |        y wr   repr.0css     r   	<genexpr>z1RemoteSettingsChanged.__repr__.<locals>.<genexpr>c       H)G2d2h)G   }>joinrN   valuesr   s    r   r!   zRemoteSettingsChanged.__repr__a  -    IIH)>)>)E)E)GHH
 	
r   N)r	   r
   r   r   r   classmethodr[   r!   r   r   r   rK   rK   4  s%    &#  $
r   rK   c                       e Zd ZdZd Zd Zy)PingReceivedz
    The PingReceived event is fired whenever a PING is received. It contains
    the 'opaque data' of the PING frame. A ping acknowledgment with the same
    'opaque data' is automatically emitted after receiving a ping.

    .. versionadded:: 3.1.0
    c                     d | _         y r   	ping_datar   s    r   r   zPingReceived.__init__o  	    r   c                 4    dt        | j                        dS )Nz<PingReceived ping_data:r   rC   rq   r   s    r   r!   zPingReceived.__repr__s      !$..1
 	
r   Nr#   r   r   r   rn   rn   g  s    
r   rn   c                       e Zd ZdZd Zd Zy)PingAckReceivedaH  
    The PingAckReceived event is fired whenever a PING acknowledgment is
    received. It contains the 'opaque data' of the PING+ACK frame, allowing the
    user to correlate PINGs and calculate RTT.

    .. versionadded:: 3.1.0

    .. versionchanged:: 4.0.0
       Removed deprecated but equivalent ``PingAcknowledged``.
    c                     d | _         y r   rp   r   s    r   r   zPingAckReceived.__init__  rr   r   c                 4    dt        | j                        dS )Nz<PingAckReceived ping_data:r   rt   r   s    r   r!   zPingAckReceived.__repr__  ru   r   Nr#   r   r   r   rw   rw   y  s    	
r   rw   c                       e Zd ZdZd Zd Zy)StreamEndedz
    The StreamEnded event is fired whenever a stream is ended by a remote
    party. The stream may not be fully closed if it has not been closed
    locally, but no further data or headers should be expected on that stream.
    c                     d | _         y r   r   r   s    r   r   zStreamEnded.__init__  rr   r   c                      d| j                   z  S )Nz<StreamEnded stream_id:%s>r}   r   s    r   r!   zStreamEnded.__repr__  s    +dnn<<r   Nr#   r   r   r   r{   r{     s    
=r   r{   c                       e Zd ZdZd Zd Zy)StreamReseta  
    The StreamReset event is fired in two situations. The first is when the
    remote party forcefully resets the stream. The second is when the remote
    party has made a protocol error which only affects a single stream. In this
    case, h2 will terminate the stream early and return this event.

    .. versionchanged:: 2.0.0
       This event is now fired when h2 automatically resets a stream.
    c                 .    d | _         d | _        d| _        y )NTr   
error_coderemote_resetr   s    r   r   zStreamReset.__init__  s      !r   c                 V    d| j                   d| j                  d| j                  dS )Nz<StreamReset stream_id:z, error_code:z, remote_reset:r   r   r   s    r   r!   zStreamReset.__repr__  s!    NNDOOT->->
 	
r   Nr#   r   r   r   r   r     s    	!
r   r   c                       e Zd ZdZd Zd Zy)PushedStreamReceivedz
    The PushedStreamReceived event is fired whenever a pushed stream has been
    received from a remote peer. The event carries on it the new stream ID, the
    ID of the parent stream, and the request headers pushed by the remote peer.
    c                 .    d | _         d | _        d | _        y r   pushed_stream_idparent_stream_idr   r   s    r   r   zPushedStreamReceived.__init__  s     $ !% r   c                 V    d| j                   d| j                  d| j                  dS )Nz'<PushedStreamReceived pushed_stream_id:z, parent_stream_id:r   r   r   r   s    r   r!   zPushedStreamReceived.__repr__  s'     %%%%		
r   Nr#   r   r   r   r   r     s    

r   r   c                       e Zd ZdZd Zd Zy)SettingsAcknowledgedz
    The SettingsAcknowledged event is fired whenever a settings ACK is received
    from the remote peer. The event carries on it the settings that were
    acknowedged, in the same format as
    :class:`h2.events.RemoteSettingsChanged`.
    c                     i | _         y r   rM   r   s    r   r   zSettingsAcknowledged.__init__  rO   r   c                 j    ddj                  d | j                  j                         D              dS )Nz(<SettingsAcknowledged changed_settings:{r]   c              3   2   K   | ]  }t        |        y wr   r_   ra   s     r   rd   z0SettingsAcknowledged.__repr__.<locals>.<genexpr>  re   rf   rg   rh   r   s    r   r!   zSettingsAcknowledged.__repr__  rk   r   Nr#   r   r   r   r   r     s    #
r   r   c                       e Zd ZdZd Zd Zy)PriorityUpdateda"  
    The PriorityUpdated event is fired whenever a stream sends updated priority
    information. This can occur when the stream is opened, or at any time
    during the stream lifetime.

    This event is purely advisory, and does not need to be acted on.

    .. versionadded:: 2.0.0
    c                 <    d | _         d | _        d | _        d | _        y r   r   weight
depends_on	exclusiver   s    r   r   zPriorityUpdated.__init__  s$      
 r   c           	      p    d| j                   d| j                  d| j                  d| j                  d	S )Nz<PriorityUpdated stream_id:z	, weight:z, depends_on:z, exclusive:r   r   r   s    r   r!   zPriorityUpdated.__repr__  s*     	
r   Nr#   r   r   r   r   r     s     	
r   r   c                       e Zd ZdZd Zd Zy)ConnectionTerminatedz
    The ConnectionTerminated event is fired when a connection is torn down by
    the remote peer using a GOAWAY frame. Once received, no further action may
    be taken on the connection: a new connection must be established.
    c                 .    d | _         d | _        d | _        y r   )r   last_stream_idadditional_datar   s    r   r   zConnectionTerminated.__init__  s     
 #  $r   c           
          d| j                   d| j                  dt        | j                  r| j                  d d nd       dS )Nz!<ConnectionTerminated error_code:z, last_stream_id:z, additional_data:rB   r   )r   r   rC   r   r   s    r   r!   zConnectionTerminated.__repr__  sD     ##%++ (("-157			
r   Nr#   r   r   r   r   r     s    
$

r   r   c                       e Zd ZdZd Zd Zy)AlternativeServiceAvailableaU  
    The AlternativeServiceAvailable event is fired when the remote peer
    advertises an `RFC 7838 <https://tools.ietf.org/html/rfc7838>`_ Alternative
    Service using an ALTSVC frame.

    This event always carries the origin to which the ALTSVC information
    applies. That origin is either supplied by the server directly, or inferred
    by h2 from the ``:authority`` pseudo-header field that was sent by
    the user when initiating a given stream.

    This event also carries what RFC 7838 calls the "Alternative Service Field
    Value", which is formatted like a HTTP header field and contains the
    relevant alternative service information. h2 does not parse or in any
    way modify that information: the user is required to do that.

    This event can only be fired on the client end of a connection.

    .. versionadded:: 2.3.0
    c                      d | _         d | _        y r   )originfield_valuer   s    r   r   z$AlternativeServiceAvailable.__init__@  s       r   c                 |    d| j                   j                  dd      d| j                  j                  dd      dS )Nz$<AlternativeServiceAvailable origin:zutf-8ignorez, field_value:r   )r   decoder   r   s    r   r!   z$AlternativeServiceAvailable.__repr__O  s8     ""7H5  '':	
r   Nr#   r   r   r   r   r   ,  s    & 
r   r   c                       e Zd ZdZd Zd Zy)UnknownFrameReceiveda  
    The UnknownFrameReceived event is fired when the remote peer sends a frame
    that h2 does not understand. This occurs primarily when the remote
    peer is employing HTTP/2 extensions that h2 doesn't know anything
    about.

    RFC 7540 requires that HTTP/2 implementations ignore these frames. h2
    does so. However, this event is fired to allow implementations to perform
    special processing on those frames if needed (e.g. if the implementation
    is capable of handling the frame itself).

    .. versionadded:: 2.7.0
    c                     d | _         y r   )framer   s    r   r   zUnknownFrameReceived.__init__f  s	    
r   c                      y)Nz<UnknownFrameReceived>r   r   s    r   r!   zUnknownFrameReceived.__repr__j  s    'r   Nr#   r   r   r   r   r   X  s    (r   r   c                 P    | yt        j                  |       j                  d      S )a	  
    Converts a bytestring into something that is safe to print on all Python
    platforms.

    This function is relatively expensive, so it should not be called on the
    mainline of the code. It's safe to use in things like object repr methods
    though.
    Nascii)binasciihexlifyr   )r?   s    r   rC   rC   n  s(     |D!((11r   )r   r   settingsr   r   r   r   r&   r*   r.   r0   r3   r5   r7   r9   r=   rE   rK   rn   rw   r{   r   r   r   r   r   r   r   rC   r   r   r   <module>r      s2  	  <	 	%
e %
P%
u %
P'
u '
T	5 		L 		< 	
	L 
		 	(
E (
V&
5 &
R
E 
,0
E 0
f
5 
$
e 
*=% =
% 
6
5 
6
5 
&#
e #
L
5 
B)
% )
X(5 (,2r   