
    hg                     |   S SK JrJrJrJrJrJrJrJrJ	r	  SSK
JrJrJrJrJrJrJr  SSKJrJrJr  SSKJrJr  SSKJr  SSKJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%  SSK&J'r'J(r(J)r)  SS	K*J+r+J,r,  / S
Qr- " S S\)\)S9r. " S S\)\)S9r/Sr0S\	\\4   S\14S jr2S\3S\	\\4   S\\4\	\S   \\5   4   4   4S jr6 " S S5      r7g)    )	AnyCallablecastDictListOptionalTupleTypeUnion   )ConnectionClosedDataEndOfMessageEventInformationalResponseRequestResponse)get_comma_headerhas_expect_100_continueset_comma_header)READERSReadersType)ReceiveBuffer)
_SWITCH_CONNECT_SWITCH_UPGRADECLIENTConnectionStateDONEERRORMIGHT_SWITCH_PROTOCOL	SEND_BODYSERVERSWITCHED_PROTOCOL)LocalProtocolErrorRemoteProtocolErrorSentinel)WRITERSWritersType)
Connection	NEED_DATAPAUSEDc                       \ rS rSrSrg)r*   (    N__name__
__module____qualname____firstlineno____static_attributes__r.       A/var/www/html/env/lib/python3.13/site-packages/h11/_connection.pyr*   r*   (       r5   r*   )	metaclassc                       \ rS rSrSrg)r+   ,   r.   Nr/   r.   r5   r6   r+   r+   ,   r7   r5   r+   i @  eventreturnc                 b    [        U R                  S5      nSU;   a  g[        U SS5      S:  a  gg)N
   connection   closeFhttp_version   1.1T)r   headersgetattr)r;   
connections     r6   _keep_aliverE   H   s4    !%--?J:unf-6r5   request_methodr.   c                    [        U5      [        [        4;   d   e[        U5      [        L aJ  UR                  S;   d'  U S:X  d!  U S:X  a  SUR                  s=::  a  S:  a   g  OgUR                  S:  d   e[	        UR
                  S5      nU(       a
  US/:X  d   eg	[	        UR
                  S
5      nU(       a  S[        US   5      44$ [        U5      [        L a  gg)N)   i0     HEAD   CONNECT   ,  )content-length)r      transfer-encoding   chunked)chunkedr.      content-lengthrM   r   )http/1.0r.   )typer   r   status_coder   rB   int)rF   r;   transfer_encodingscontent_lengthss       r6   _body_framingrX   Q   s     ;7H---- E{h+(*,8I8I1OC1O+ 2P+   C''' *%--9MN!j\111 'u}}6GHO 3q'9#:"<== E{g'r5   c                   b   \ rS rSrSr\4S\\   S\SS4S jjr	\
S\\\   \\   4   4S j5       r\
S\\   4S	 j5       r\
S\\   4S
 j5       r\
S\4S j5       rS"S jrS\\   SS4S jrS\S\\\      4S jrS\\   S\SS4S jrS\\   S\\   S\\\4   S\\S\4      4S jr S#S\\\   \\   4   S\\   SS4S jjr\
S\\\4   4S j5       r S\SS4S jr!S\\\\"   \\#   4   4S jr$S\\\\"   \\#   4   4S jr%S\S\\   4S jr&S\S\\'\      4S jr(S"S jr)S\*S\*4S  jr+S!r,g)$r)      a  An object encapsulating the state of an HTTP connection.

Args:
    our_role: If you're implementing a client, pass :data:`h11.CLIENT`. If
        you're implementing a server, pass :data:`h11.SERVER`.

    max_incomplete_event_size (int):
        The maximum number of bytes we're willing to buffer of an
        incomplete event. In practice this mostly sets a limit on the
        maximum size of the request/response line + headers. If this is
        exceeded, then :meth:`next_event` will raise
        :exc:`RemoteProtocolError`.

our_rolemax_incomplete_event_sizer<   Nc                    X l         U[        [        4;  a  [        SR	                  U5      5      eXl        U   U[        L a  [        U l        O[        U l        [        5       U l        U R                  U R
                  S [        5      U l        U R                  U R                  S [        5      U l        [        5       U l        SU l        S U l        S U l        SU l        g )Nz#expected CLIENT or SERVER, not {!r}F)_max_incomplete_event_sizer   r"   
ValueErrorformatr[   
their_roler   _cstate_get_io_objectr'   _writerr   _readerr   _receive_buffer_receive_buffer_closedtheir_http_version_request_method"client_is_waiting_for_100_continue)selfr[   r\   s      r6   __init__Connection.__init__   s    
 +D'FF++BII(STT v$DO$DO&( **4==$H**4??D'J  - ',# 4804 38/r5   c                 @    [        U R                  R                  5      $ )zqA dictionary like::

   {CLIENT: <client state>, SERVER: <server state>}

See :ref:`state-machine` for details.

)dictrb   statesrk   s    r6   rp   Connection.states   s     DLL''((r5   c                 H    U R                   R                  U R                     $ )zZThe current state of whichever role we are playing. See
:ref:`state-machine` for details.
)rb   rp   r[   rq   s    r6   	our_stateConnection.our_state   s    
 ||""4==11r5   c                 H    U R                   R                  U R                     $ )z^The current state of whichever role we are NOT playing. See
:ref:`state-machine` for details.
)rb   rp   ra   rq   s    r6   their_stateConnection.their_state   s    
 ||""4??33r5   c                 L    U R                   [        L =(       a    U R                  $ N)ra   r   rj   rq   s    r6   !they_are_waiting_for_100_continue,Connection.they_are_waiting_for_100_continue   s    &(TT-T-TTr5   c                     [        U R                  R                  5      nU R                  R                  5         SU l        U R
                  (       a   eU R                  U5        g)aI  Attempt to reset our connection state for a new request/response
cycle.

If both client and server are in :data:`DONE` state, then resets them
both to :data:`IDLE` state in preparation for a new request/response
cycle on this same connection. Otherwise, raises a
:exc:`LocalProtocolError`.

See :ref:`keepalive-and-pipelining`.

N)ro   rb   rp   start_next_cycleri   rj   _respond_to_state_changes)rk   
old_statess     r6   r~   Connection.start_next_cycle   sO     $,,--.
%%'# ::::&&z2r5   rolec                     [        U R                  R                  5      nU R                  R                  U5        U R	                  U5        g rz   )ro   rb   rp   process_errorr   )rk   r   r   s      r6   _process_errorConnection._process_error   s6    $,,--.
""4(&&z2r5   r;   c                     [        U5      [        L a  UR                  S:X  a  [        $ [        U5      [        L a>  [
        U R                  R                  ;   a   SUR                  s=::  a  S:  a	   [
        $   g g )Ne   rK   rL   )rS   r   rT   r   r   r   rb   pending_switch_proposals)rk   r;   s     r6   _server_switch_eventConnection._server_switch_event   sc    ;//E4E4E4L"";("4<<#H#HH5,,2s2&& 3 r5   c                    [        U R                  R                  5      nU[        L a{  [	        U5      [
        L ai  UR                  S:X  a  U R                  R                  [        5        [        UR                  S5      (       a  U R                  R                  [        5        S nU[        L a  U R                  U5      nU R                  R                  U[	        U5      U5        [	        U5      [
        L a  UR                  U l        XR                   L aQ  [	        U5      [
        ["        [$        4;   a3  ['        [(        [
        ["        [$        4   U5      nUR*                  U l        [	        U5      [
        ["        4;   aE  [/        ['        [(        [
        ["        4   U5      5      (       d  U R                  R1                  5         [	        U5      [
        L a  [3        U5      (       a  SU l        [	        U5      [$        ["        4;   a  SU l        U[        L a   [	        U5      [6        [8        4;   a  SU l        U R;                  X25        g )NrJ   s   upgradeTF)ro   rb   rp   r   rS   r   methodprocess_client_switch_proposalr   r   rB   r   r"   r   process_eventri   ra   r   r   r   r   r@   rh   rE   process_keep_alive_disabledr   rj   r   r   r   )rk   r   r;   r   server_switch_events        r6   _process_eventConnection._process_event  s    $,,--.
6>d5kW4||z);;OLz::;;OL"6>"&";";E"B""4e6IJ ;'!#(<<D ??"tE{!7
 (

 w2GGH%PE&+&8&8D# ;7H--kw()517
 7
 LL446 ;'!&=e&D&D6:D3;0(;;6;D36>d5kdL-AA6;D3&&z9r5   io_dict.c                 
   U R                   R                  U   nU[        L aP  [        [	        [
        U R                  5      [	        [        [        [        4   U5      5      u  pVU[           U   " U6 $ UR                  X45      $ rz   )rb   rp   r!   rX   r   bytesri   r   r   r   get)rk   r   r;   r   stateframing_typeargss          r6   rc   Connection._get_io_object4  s}     ##D)I "/UD0014gx>O8PRW3X"L 9%l3T:: ;;}--r5   r   c                    U R                   XR                     :w  a&  U R                  U R                  U[        5      U l        U R
                  XR                     :w  a'  U R                  U R                  U[        5      U l        g g rz   )	rt   r[   rc   r'   rd   rw   ra   r   re   )rk   r   r;   s      r6   r   $Connection._respond_to_state_changesJ  se     >>Z66..t}}eWMDLz//::..twODL ;r5   c                 D    [        U R                  5      U R                  4$ )a:  Data that has been received, but not yet processed, represented as
a tuple with two elements, where the first is a byte-string containing
the unprocessed data itself, and the second is a bool that is True if
the receive connection was closed.

See :ref:`switching-protocols` for discussion of why you'd want this.
)r   rf   rg   rq   s    r6   trailing_dataConnection.trailing_dataU  s      d**+T-H-HIIr5   datac                     U(       a2  U R                   (       a  [        S5      eU =R                  U-  sl        gSU l         g)a  Add data to our internal receive buffer.

This does not actually do any processing on the data, just stores
it. To trigger processing, you have to call :meth:`next_event`.

Args:
    data (:term:`bytes-like object`):
        The new data that was just received.

        Special case: If *data* is an empty byte-string like ``b""``,
        then this indicates that the remote side has closed the
        connection (end of file). Normally this is convenient, because
        standard Python APIs like :meth:`file.read` or
        :meth:`socket.recv` use ``b""`` to indicate end-of-file, while
        other failures to read are indicated using other mechanisms
        like raising :exc:`TimeoutError`. When using such an API you
        can just blindly pass through whatever you get from ``read``
        to :meth:`receive_data`, and everything will work.

        But, if you have an API where reading an empty string is a
        valid non-EOF condition, then you need to be aware of this and
        make sure to check for such strings and avoid passing them to
        :meth:`receive_data`.

Returns:
    Nothing, but after calling this you should call :meth:`next_event`
    to parse the newly received data.

Raises:
    RuntimeError:
        Raised if you pass an empty *data*, indicating EOF, and then
        pass a non-empty *data*, indicating more data that somehow
        arrived after the EOF.

        (Calling ``receive_data(b"")`` multiple times is fine,
        and equivalent to calling it once.)

z(received close, then received more data?TN)rg   RuntimeErrorrf   )rk   r   s     r6   receive_dataConnection.receive_data`  s6    N **"#MNN  D( *.D'r5   c                    U R                   nU[        L a  U R                  (       a  [        $ U[        L d	  U[
        L a  [        $ U R                  c   eU R                  U R                  5      nUcb  U R                  (       dQ  U R                  (       a@  [        U R                  S5      (       a  U R                  R                  5       nO
[        5       nUc  [        nU$ )Nread_eof)rw   r   rf   r+   r    r#   re   rg   hasattrr   r   r*   )rk   r   r;   s      r6   _extract_next_receive_event&Connection._extract_next_receive_event  s       
 D=T11M))U6G-GM||'''T112=''D,G,G
 4<<44 LL113E,.E=Er5   c                 ,   U R                   [        L a  [        S5      e U R                  5       nU[        [
        4;  a*  U R                  U R                  [        [        U5      5        U[        L aI  [        U R                  5      U R                  :  a
  [        SSS9eU R                  (       a  [        S5      eU$ ! [         aK  nU R                  U R                  5        [!        U["        5      (       a  UR%                  5          SnAge SnAff = f)an  Parse the next event out of our receive buffer, update our internal
state, and return it.

This is a mutating operation -- think of it like calling :func:`next`
on an iterator.

Returns:
    : One of three things:

    1) An event object -- see :ref:`events`.

    2) The special constant :data:`NEED_DATA`, which indicates that
       you need to read more data from your socket and pass it to
       :meth:`receive_data` before this method will be able to return
       any more events.

    3) The special constant :data:`PAUSED`, which indicates that we
       are not in a state where we can process incoming data (usually
       because the peer has finished their part of the current
       request/response cycle, and you have not yet called
       :meth:`start_next_cycle`). See :ref:`flow-control` for details.

Raises:
    RemoteProtocolError:
        The peer has misbehaved. You should close the connection
        (possibly after sending some kind of 4xx response).

Once this method returns :class:`ConnectionClosed` once, then all
subsequent calls will also return :class:`ConnectionClosed`.

If this method raises any exception besides :exc:`RemoteProtocolError`
then that's a bug -- if it happens please file a bug report!

If this method raises any exception then it also sets
:attr:`Connection.their_state` to :data:`ERROR` -- see
:ref:`error-handling` for discussion.

z+Can't receive data when peer state is ERRORzReceive buffer too longi  )error_status_hintz#peer unexpectedly closed connectionN)rw   r   r%   r   r*   r+   r   ra   r   r   lenrf   r^   rg   BaseExceptionr   
isinstancer$   !_reraise_as_remote_protocol_error)rk   r;   excs      r6   
next_eventConnection.next_event  s    P u$%&STT	446EY//##DOOT%5GH	!t++,t/N/NN .1S  .. ..STTL 	0#1225577	s   BB> >
DA DDDc                 N    U R                  U5      nUc  gSR                  U5      $ )aC  Convert a high-level event into bytes that can be sent to the peer,
while updating our internal state machine.

Args:
    event: The :ref:`event <events>` to send.

Returns:
    If ``type(event) is ConnectionClosed``, then returns
    ``None``. Otherwise, returns a :term:`bytes-like object`.

Raises:
    LocalProtocolError:
        Sending this event at this time would violate our
        understanding of the HTTP/1.1 protocol.

If this method raises any exception then it also sets
:attr:`Connection.our_state` to :data:`ERROR` -- see
:ref:`error-handling` for discussion.

Nr5   )send_with_data_passthroughjoin)rk   r;   	data_lists      r6   sendConnection.send  s,    * 33E:	88I&&r5   c                 t   U R                   [        L a  [        S5      e [        U5      [        L a  U R                  U5      nU R                  nU R                  U R                  U5        [        U5      [        L a  gUc   e/ nU" XR                  5        U$ !   U R                  U R                  5        e = f)a@  Identical to :meth:`send`, except that in situations where
:meth:`send` returns a single :term:`bytes-like object`, this instead
returns a list of them -- and when sending a :class:`Data` event, this
list is guaranteed to contain the exact object you passed in as
:attr:`Data.data`. See :ref:`sendfile` for discussion.

z'Can't send data when our state is ERRORN)rt   r   r$   rS   r   &_clean_up_response_headers_for_sendingrd   r   r[   r   appendr   )rk   r;   writerr   s       r6   r   %Connection.send_with_data_passthrough  s     >>U"$%NOO	E{h&CCEJ \\Fu5E{.. ))))+	u../  	.s   AB >B B7c                 :    U R                  U R                  5        g)zNotify the state machine that we failed to send the data it gave
us.

This causes :attr:`Connection.our_state` to immediately become
:data:`ERROR` -- see :ref:`error-handling` for discussion.

N)r   r[   rq   s    r6   send_failedConnection.send_failed'  s     	DMM*r5   responsec                    [        U5      [        L d   eUR                  nSn[        [        U R
                  5      nUS:X  a  Sn[        XA5      u  pVUS;   aX  [        US/ 5      nU R                  b  U R                  S:  a   [        US/ 5      nU R
                  S:w  a  SnO[        USS	/5      nU R                  R                  (       a  U(       aM  [        [        US
5      5      nUR                  S5        UR                  S5        [        US
[        U5      5      n[        UUR                   UR"                  UR$                  S9$ )NFrI   s   GET)rP   rR   rQ   rA   rN   TrO   r>   s
   keep-aliver?   )rB   rT   r@   reason)rS   r   rB   r   r   ri   rX   r   rh   rb   
keep_alivesetr   discardaddsortedrT   r@   r   )rk   r   rB   
need_closemethod_for_choosing_headersr   _rD   s           r6   r   1Connection._clean_up_response_headers_for_sending@  s6   H~)))""
 '+5$2F2F&G#&'1*0''(CN22 'w0A2FG&&.$2I2IF2R
 +74H"M
 ''72!%J*74H:,W||&&*-g}EFJ}-NN8$&wvj?QRG ,,!..??	
 	
r5   )rb   r^   re   rf   rg   ri   rd   rj   r[   rh   ra   )r<   Nrz   )-r0   r1   r2   r3   __doc__!DEFAULT_MAX_INCOMPLETE_EVENT_SIZEr
   r&   rU   rl   propertyr   rp   rt   rw   boolr{   r~   r   r   r   r   r   r   r   r(   r   r   rc   r   r	   r   r   r   r*   r+   r   r   r   r   r   r   r   r   r4   r.   r5   r6   r)   r)      sg   $ *K%8x.%8 $'%8 
	%8N )T(^T(^;< ) ) 24> 2 2 4T(^ 4 4 U4 U U3(34> 3d 3
	% 	HT(^4L 	.:4> .:% .:D .:`.8n. . {K/0	.
 
(38$	%.2 "&	Phh78	P 	P 
		P JuUD[1 J J,/ ,/4 ,/\	ud9otF|3	48?E%i$v,"FG ?B'% 'HUO '6 (4;:O B+29
x 9
H 9
r5   r)   N)8typingr   r   r   r   r   r   r	   r
   r   _eventsr   r   r   r   r   r   r   _headersr   r   r   _readersr   r   _receivebufferr   _stater   r   r   r   r   r   r    r!   r"   r#   _utilr$   r%   r&   _writersr'   r(   __all__r*   r+   r   r   rE   r   strrU   rX   r)   r.   r5   r6   <module>r      s    Q P P   R Q * )   
 + 0	H 		X 	 %. !uWh./ D 0 0 "'(9":0 
3eBis+,,-0 tn
 n
r5   