o
    .j&                     @  s"  d dl mZ d dlZd dlmZmZ d dlmZ ejr!d dlm	Z	 ddl
mZ ddlmZ G d	d
 d
edZG dd deedZG dd deedZG dd deZG dd dedZG dd deeedZG dd deeedZG dd deedZG dd deedZG dd deedZdS )    )annotationsN)ABCMetaabstractmethod)Any)Literal   )HeadersType)Eventc                   @  sR   e Zd ZdZedddZeddd	Zedd
dZ	ddddZdddZ	dS )BaseProtocolz7Sans-IO common methods whenever it is TCP, UDP or QUIC.databytesreturnNonec                 C     t )z4
        Called when some data is received.
        NotImplementedError)selfr    r   f/home/thesage/.local/lib/python3.10/site-packages/urllib3_future/contrib/hface/protocols/_protocols.pybytes_received!      zBaseProtocol.bytes_receivedc                 C  r   )zK
        Returns data for sending out of the internal data buffer.
        r   r   r   r   r   bytes_to_send*   r   zBaseProtocol.bytes_to_sendc                 C  r   )z?
        Called when the connection is lost or closed.
        r   r   r   r   r   connection_lost1   r   zBaseProtocol.connection_lostN	stream_idintamt
int | Nonebool | Nonec                 C  r   )zx
        Verify if the client should listen network incoming data for
        the flow control update purposes.
        r   r   r   r   r   r   r   should_wait_remote_flow_control8      z,BaseProtocol.should_wait_remote_flow_controlc                 C  r   )zQ
        Determine if the remote set a limited size for each data frame.
        r   r   r   r   r   max_frame_sizeA      zBaseProtocol.max_frame_size)r   r   r   r   )r   r   r   r   Nr   r   r   r   r   r   r   r   )
__name__
__module____qualname____doc__r   r   r   r   r    r"   r   r   r   r   r
      s    	r
   )	metaclassc                   @     e Zd ZdZedddZdS )OverTCPProtocolz5
    Interface for sans-IO protocols on top TCP.
    r   r   c                 C  r   )uR   
        Called when the other end signals it won’t send any more data.
        r   r   r   r   r   eof_receivedM   r   zOverTCPProtocol.eof_receivedNr$   )r(   r)   r*   r+   r   r/   r   r   r   r   r.   H   s    r.   c                   @     e Zd ZdZdS )OverUDPProtocolz5
    Interface for sans-IO protocols on top UDP.
    Nr(   r)   r*   r+   r   r   r   r   r1   U       r1   c                   @  s   e Zd Zd#ddZeed$ddZejd%ddZ	ejddd&ddZ	eddd'ddZ	ejd(ddZ
ejddd)ddZ
eddd*ddZ
ed+ddZed,d d!Zd"S )-OverQUICProtocolr   float | Nonec                 C  r   )zReturn the absolute monotonic time of the next QUIC timer event.
        Returns None when no timer is currently scheduled.
        r   r   r   r   r   
next_timer\   r#   zOverQUICProtocol.next_timer
Any | Nonec                 C  r   r%   r   r   r   r   r   session_ticketb      zOverQUICProtocol.session_ticketbinary_formLiteral[True]r   c                C     d S r%   r   r   r:   r   r   r   getpeercertg      zOverQUICProtocol.getpeercert.)r:   Literal[False]dict[str, Any]c                C  r<   r%   r   r=   r   r   r   r>   j   r?   Fboolbytes | dict[str, Any]c                C  r   r%   r   r=   r   r   r   r>   m      bytes | Nonec                C  r<   r%   r   r=   r   r   r   getissuercertq   r?   zOverQUICProtocol.getissuercertdict[str, Any] | Nonec                C  r<   r%   r   r=   r   r   r   rF   t   r9   bytes | dict[str, Any] | Nonec                C  r   r%   r   r=   r   r   r   rF   y   r#   
str | Nonec                 C  r   r%   r   r   r   r   r   cipher   rD   zOverQUICProtocol.cipherc                 C  r   r%   r   r   r   r   r   ech_accepted   rD   zOverQUICProtocol.ech_acceptedN)r   r5   )r   r7   )r:   r;   r   r   )r:   r@   r   rA   )r:   rB   r   rC   )r:   r;   r   rE   )r:   r@   r   rG   )r:   rB   r   rH   )r   rI   r   rB   )r(   r)   r*   r6   propertyr   r8   typingoverloadr>   rF   rJ   rK   r   r   r   r   r4   [   s.    
r4   c                   @  s  e Zd ZU dZded< eed;ddZeed<d	d
Z	ed<ddZ
ed<ddZed<ddZed=ddZe	d>d?ddZe	d>d@ddZedAdBd"d#ZedAdCd$d%ZedDdEd)d*ZdDdFd,d-Zed&d&d.dGd1d2ZedHd5d6ZedId7d8Zed<d9d:Zd&S )JHTTPProtocolz6
    Sans-IO representation of an HTTP connection
    strimplementationr   tuple[type[BaseException], ...]c                   C  r   )zBReturn exception types that should be handled in your application.r   r   r   r   r   
exceptions   r#   zHTTPProtocol.exceptionsrB   c                 C  r   )z
        Whether this connection supports multiple parallel streams.

        Returns ``True`` for HTTP/2 and HTTP/3 connections.
        r   r   r   r   r   multiplexed      zHTTPProtocol.multiplexedc                 C  r   )zZ
        Return True if this connection is BOTH available and not doing anything.
        r   r   r   r   r   is_idle   r   zHTTPProtocol.is_idlec                 C  r   )zP
        Return whether this connection is capable to open new streams.
        r   r   r   r   r   is_available   r   zHTTPProtocol.is_availablec                 C  r   )zO
        Return whether this connection is closed or should be closed.
        r   r   r   r   r   has_expired   r   zHTTPProtocol.has_expiredr   c                 C  r   )a  
        Return an ID that can be used to create a new stream.

        Use the returned ID with :meth:`.submit_headers` to create the stream.
        This method may or may not return one value until that method is called.

        :return: stream ID
        r   r   r   r   r   get_available_stream_id   s   
z$HTTPProtocol.get_available_stream_idFr   headersr   
end_streamr   c                 C  r   )aQ  
        Submit a frame with HTTP headers.

        If this is a client connection, this method starts an HTTP request.
        If this is a server connection, it starts an HTTP response.

        :param stream_id: stream ID
        :param headers: HTTP headers
        :param end_stream: whether to close the stream for sending
        r   )r   r   r[   r\   r   r   r   submit_headers   s   zHTTPProtocol.submit_headersr   r   c                 C  r   )z
        Submit a frame with HTTP data.

        :param stream_id: stream ID
        :param data: payload
        :param end_stream: whether to close the stream for sending
        r   )r   r   r   r\   r   r   r   submit_data   s   zHTTPProtocol.submit_datar   
error_codec                 C  r   )ai  
        Immediate terminate a stream.

        Stream reset is used to request cancellation of a stream
        or to indicate that an error condition has occurred.

        Use :attr:`.error_codes` to obtain error codes for common problems.

        :param stream_id: stream ID
        :param error_code:  indicates why the stream is being terminated
        r   )r   r   r_   r   r   r   submit_stream_reset   s   z HTTPProtocol.submit_stream_resetc                 C  r   )z
        Submit graceful close the connection.

        Use :attr:`.error_codes` to obtain error codes for common problems.

        :param error_code:  indicates why the connections is being closed
        r   )r   r_   r   r   r   submit_close   s   	zHTTPProtocol.submit_closeNr   Event | Nonec                 C  r   )zN
        Consume next HTTP event.

        :return: an event instance
        r   )r   r   r   r   r   
next_event   r!   zHTTPProtocol.next_eventtyping.Iterator[Event]c                 c  s$    	 | j |d}|du rdS |V  q)zx
        Consume available HTTP events.

        :return: an iterator that unpack "next_event" until exhausted.
        T)r   N)rc   )r   r   evr   r   r   events   s   zHTTPProtocol.events)r   
excl_eventrg   tuple[type[Event], ...] | Nonec                C  r   )z7Verify if there is queued event waiting to be consumed.r   )r   r   rg   r   r   r   has_pending_event  rV   zHTTPProtocol.has_pending_eventrf   r	   c                 G  r   )zPut back events into the deque.r   )r   rf   r   r   r   reshelve  r9   zHTTPProtocol.reshelvec                 C  r   )zHSend a PING frame to the remote peer. Thus keeping the connection alive.r   r   r   r   r   ping  r9   zHTTPProtocol.pingc                 C  r   )zITell if we should expect a ping ack frame to confirm connection liveness.r   r   r   r   r   expect_pong"  r9   zHTTPProtocol.expect_pong)r   rS   rL   r'   )F)r   r   r[   r   r\   rB   r   r   )r   r   r   r   r\   rB   r   r   )r   )r   r   r_   r   r   r   )r_   r   r   r   r%   )r   r   r   rb   )r   r   r   rd   )r   r   rg   rh   r   rB   )rf   r	   r   r   r$   )r(   r)   r*   r+   __annotations__staticmethodr   rT   rM   rU   rW   rX   rY   rZ   r]   r^   r`   ra   rc   rf   ri   rj   rk   rl   r   r   r   r   rP      sP   
 
	rP   c                   @  r0   )HTTPOverTCPProtocolz
    :class:`HTTPProtocol` over a TCP connection

    An interface for HTTP/1 and HTTP/2 protocols.
    Extends :class:`.HTTPProtocol`.
    Nr2   r   r   r   r   ro   (  r3   ro   c                   @  r0   )HTTPOverQUICProtocolz
    :class:`HTTPProtocol` over a QUIC connection

    Abstract base class for HTTP/3 protocols.
    Extends :class:`.HTTPProtocol`.
    Nr2   r   r   r   r   rp   1  r3   rp   c                   @  s,   e Zd ZdZedddZ	ddddZdS )HTTP1Protocolz
    Sans-IO representation of an HTTP/1 connection

    An interface for HTTP/1 implementations.
    Extends :class:`.HTTPOverTCPProtocol`.
    r   rB   c                 C     dS )NFr   r   r   r   r   rU   B  rD   zHTTP1Protocol.multiplexedNr   r   r   r   r   c                 C  s   t S r%   )NotImplementedr   r   r   r   r    F  r9   z-HTTP1Protocol.should_wait_remote_flow_controlrL   r%   r&   )r(   r)   r*   r+   rM   rU   r    r   r   r   r   rq   :  s    rq   c                   @  r-   )HTTP2Protocolz
    Sans-IO representation of an HTTP/2 connection

    An abstract base class for HTTP/2 implementations.
    Extends :class:`.HTTPOverTCPProtocol`.
    r   rB   c                 C  rr   NTr   r   r   r   r   rU   T  rD   zHTTP2Protocol.multiplexedNrL   r(   r)   r*   r+   rM   rU   r   r   r   r   rt   L      rt   c                   @  r-   )HTTP3Protocolz
    Sans-IO representation of an HTTP/2 connection

    An abstract base class for HTTP/3 implementations.
    Extends :class:`.HTTPOverQUICProtocol`
    r   rB   c                 C  rr   ru   r   r   r   r   r   rU   a  rD   zHTTP3Protocol.multiplexedNrL   rv   r   r   r   r   rx   Y  rw   rx   )
__future__r   rN   abcr   r   r   TYPE_CHECKINGtyping_extensionsr   _typingr   rf   r	   r
   r.   r1   r4   rP   ro   rp   rq   rt   rx   r   r   r   r   <module>   s&   *- !		