
    5i'                        d Z ddlZddlmZ ddlmZ ddlZddlmZm	Z	m
Z
mZ ddlmZ ddlmZmZmZmZmZmZmZmZ  G d d	e      Z G d
 de      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)      Z' G d* d+      Z(y),zA
HTTP

All network operations in `awscrt.http` are asynchronous.
    N)Future)NativeResource)ClientBootstrapInputStreamTlsConnectionOptionsSocketOptions)IntEnum)ListTupleDictOptionalUnionIteratorCallableAnyc                        e Zd ZdZdZdZdZdZy)HttpVersionz!HTTP protocol version enumerationr            N)__name__
__module____qualname____doc__UnknownHttp1_0Http1_1Http2     m/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/awscrt/http.pyr   r      s    +GGGEr    r   c                   (    e Zd ZdZdZdZdZdZdZdZ	y)	Http2SettingIDz+HTTP/2 Predefined settings(RFC-9113 6.5.2).r   r   r            N)
r   r   r   r   HEADER_TABLE_SIZEENABLE_PUSHMAX_CONCURRENT_STREAMSINITIAL_WINDOW_SIZEMAX_FRAME_SIZEMAX_HEADER_LIST_SIZEr   r    r!   r#   r#      s'    5KNr    r#   c                       e Zd ZU dZej
                  dej                  dej                  dej                  dej                  dej                  diZeeeeef   f   ed<   deded	d
fdZdeded	d
fdZd	efdZy
)Http2Settinga  HTTP/2 Setting.
    Settings are very complicated in HTTP/2.
    Each end has its own settings, and the local settings cannot be applied
    until the remote end acknowledges it.
    Each end can change its settings at any time, while the order of the settings
    changed may also result in different behavior.

    Each setting has its boundary and initial values defined in RFC-9113 6.5.2:
    Initial values are listed below, while the range can be found in VALID_RANGES:
    HEADER_TABLE_SIZE: 4096
    ENABLE_PUSH: 1
    MAX_CONCURRENT_STREAMS: 2^32-1
    INITIAL_WINDOW_SIZE: 2^16-1
    MAX_FRAME_SIZE: 2^14
    MAX_HEADER_LIST_SIZE: 2^32-1

    Args:
        id (Http2SettingID): Setting ID.
        value (int): Setting value.
    )r   l    )r   r   )r   i)i @  i VALID_RANGESidvaluereturnNc                     t        |t              sJ t        |t              sJ || _        | j	                  ||       || _        y N)
isinstancer#   intr0   _validate_setting_valuer1   )selfr0   r1   s      r!   __init__zHttp2Setting.__init__C   sB    "n---%%%% 	$$R/
r    c           	          | j                   |   \  }}||cxk  r|k  s$n |j                  }t        | d| d| d|       y)zTValidate that setting value is within its allowed range according to RFC-9113 6.5.2.z must be between z and z, got N)r/   name
ValueError)r8   r0   r1   	min_value	max_valuesetting_names         r!   r7   z$Http2Setting._validate_setting_valueL   sX    #004	9E.Y.77L~->ykykY_`e_fghh /r    c                 ~    | j                   j                  d| j                  j                   d| j                   dz   S )N(=))	__class__r   r0   r;   r1   r8   s    r!   __str__zHttp2Setting.__str__S   s2    ~~&&1TWW\\N!DJJ<q)IIIr    )r   r   r   r   r#   r'   r(   r)   r*   r+   r,   r/   r   r   r6   __annotations__r9   r7   strrF   r   r    r!   r.   r.   %   s    * 	((.""F--~**N%%'9++^;L$~uS#X67 > # $ i. i i iJ Jr    r.   c                   \     e Zd ZdZdZd fdZed	d       Zedefd       Z	de
fdZ xZS )
HttpConnectionBasez!Base for HTTP connection classes.)_shutdown_future_versionr2   c                 @    t         |           t               | _        y r4   )superr9   r   rK   )r8   rD   s    r!   r9   zHttpConnectionBase.__init__\   s     &r    c                     | j                   S )a&  
        concurrent.futures.Future: Completes when this connection has finished shutting down.
        Future will contain a result of None, or an exception indicating why shutdown occurred.
        Note that the connection may have been garbage-collected before this future completes.
        )rK   rE   s    r!   shutdown_futurez"HttpConnectionBase.shutdown_future`   s     $$$r    c                     | j                   S )z-HttpVersion: Protocol used by this connectionrL   rE   s    r!   versionzHttpConnectionBase.versioni        }}r    c                 @    t        j                  | j                        S )z
        Returns:
            bool: True if this connection is open and usable, False otherwise.
            Check :attr:`shutdown_future` to know when the connection is completely
            finished shutting down.
        )_awscrthttp_connection_is_open_bindingrE   s    r!   is_openzHttpConnectionBase.is_openn   s     ..t}}==r    r2   Nr2   concurrent.futures.Future)r   r   r   r   	__slots__r9   propertyrP   r   rS   boolrY   __classcell__rD   s   @r!   rJ   rJ   W   sK    +0I) % %   > >r    rJ   c            "          e Zd ZdZe	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddededee   dee	   dee
   ded	   d
ee   deee      deeee   gdf      dedee   dee   dedee   dee   ddf d       Zedefd       Zedefd       Zy)HttpClientConnectionBase
_host_name_portN	host_nameport	bootstrapsocket_optionstls_connection_optionsproxy_optionsHttpProxyOptionsexpected_versioninitial_settingson_remote_settings_changedmanual_window_managementinitial_window_sizeread_buffer_capacityconn_manual_window_managementconn_window_size_thresholdstream_window_size_thresholdr2   r\   c                    t        |t              s|J t        | t              sJ t        |t              sJ t        |t              s|J t        |t
              s|J t        |t              s|J |
r|J t               }	 |s
t               }|st        j                         }t        | |||||||	      }t        j                  || ||||||||
|||||       |S # t        $ r}|j                  |       Y d}~|S d}~ww xY w)zP
        Initialize the generic part of the HttpClientConnection class.
        N)ri   rk   connect_futurern   rp   asyncio_connection)r5   r   rH   r6   r   r   rm   r   get_or_create_static_default_HttpClientConnectionCorerV   http_client_connection_new	Exceptionset_exception)rg   rh   ri   rj   rk   rl   rn   ro   rp   ry   rq   rr   rs   rt   ru   rv   futureconnection_corees                      r!   _generic_newz%HttpClientConnectionBase._generic_new{   s@   * )_59JJJ)S)))$$$$02FGKaKiii.-8N<RRR-)9:m>SSS+/B/NNN#	$!!.+HHJ	7#'=%!1+E#57O ..& *(#$-*,.(   	$  ##	$s   AC   	D)D  Dc                     | j                   S )zRemote hostname)re   rE   s    r!   rg   z"HttpClientConnectionBase.host_name   s     r    c                     | j                   S )zRemote port)rf   rE   s    r!   rh   zHttpClientConnectionBase.port   s     zzr    )NNNNNNNFFNNFNN)r   r   r   r]   staticmethodrH   r6   r   r   r   r   r   r
   r.   r   r_   r   r^   rg   rh   r   r    r!   rc   rc   x   sy   'I 486:EI:>6:=AY]$-21526278<:>!CCC  0C %]3	C
 %--A$BC $$67C '{3C 'tL'9:C )14;M:NPT:T1U(VC '+C "*#C #+3-C ,0C )1C  +33-!C  D_!C CJ 3   c  r    rc   c                       e Zd ZdZdZe	 	 	 	 	 	 	 ddededee	   dee
   dee   d	ed
   dedee   dee   ddfd       Z	 	 ddddeed      deed      ddfdZddZy)HttpClientConnectionzo
    An HTTP client connection.

    Use :meth:`HttpClientConnection.new()` to establish a new connection.
    rd   Nrg   rh   ri   rj   rk   rl   rm   rq   rr   rs   r2   r\   c
                 6    | j                  |||||||||		      S )a
  
        Asynchronously establish a new HttpClientConnection.

        Args:
            host_name (str): Connect to host.

            port (int): Connect to port.

            bootstrap (Optional [ClientBootstrap]): Client bootstrap to use when initiating socket connection.
                If None is provided, the default singleton is used.

            socket_options (Optional[SocketOptions]): Optional socket options.
                If None is provided, then default options are used.

            tls_connection_options (Optional[TlsConnectionOptions]): Optional TLS
                connection options. If None is provided, then the connection will
                be attempted over plain-text.

            proxy_options (Optional[HttpProxyOptions]): Optional proxy options.
                If None is provided then a proxy is not used.

            manual_window_management (bool): Set to True to manually manage the flow-control window
                of each stream. If False, the connection maintains flow-control windows such that
                no back-pressure is applied and data arrives as fast as possible. If True, the
                flow-control window of each stream shrinks as body data is received (headers,
                padding, and other metadata do not affect the window). `initial_window_size`
                determines the starting size of each stream's window. When a stream's window
                reaches 0, no further data is received until `update_window()` is called.
                Default is False.

            initial_window_size (Optional[int]): The starting size of each stream's flow-control
                window. Required if `manual_window_management` is True, ignored otherwise.
                Must be <= 2^31-1 or connection fails. If set to 0 with `manual_window_management`
                True, streams start with zero window.
                Required if manual_window_management is True, ignored otherwise.

            read_buffer_capacity (Optional[int]): Capacity in bytes of the HTTP/1.1 connection's
                read buffer. The buffer grows when the flow-control window of the incoming stream
                reaches zero. Ignored if `manual_window_management` is False. A capacity that is
                too small may hinder throughput. A capacity that is too large may waste memory
                without improving throughput. If None or zero, a default value is used.

        Returns:
            concurrent.futures.Future: A Future which completes when connection succeeds or fails.
            If successful, the Future will contain a new :class:`HttpClientConnection`.
            Otherwise, it will contain an exception.
        )rq   rr   rs   )r   )
clsrg   rh   ri   rj   rk   rl   rq   rr   rs   s
             r!   newzHttpClientConnection.new   s8    t "%= 3!5   	7 		7r    requestHttpRequeston_response.Non_bodyHttpClientStreamc                     t        | |||      S )an  Create :class:`HttpClientStream` to carry out the request/response exchange.

        NOTE: The HTTP stream sends no data until :meth:`HttpClientStream.activate()`
        is called. Call activate() when you're ready for callbacks and events to fire.

        Args:
            request (HttpRequest): Definition for outgoing request.

            on_response: Optional callback invoked once main response headers are received.
                The function should take the following arguments and return nothing:

                    *   `http_stream` (:class:`HttpClientStream`): HTTP stream carrying
                        out this request/response exchange.

                    *   `status_code` (int): Response status code.

                    *   `headers` (List[Tuple[str, str]]): Response headers as a
                        list of (name,value) pairs.

                    *   `**kwargs` (dict): Forward compatibility kwargs.

                An exception raise by this function will cause the HTTP stream to end in error.
                This callback is always invoked on the connection's event-loop thread.

            on_body: Optional callback invoked 0+ times as response body data is received.
                The function should take the following arguments and return nothing:

                    *   `http_stream` (:class:`HttpClientStream`): HTTP stream carrying
                        out this request/response exchange.

                    *   `chunk` (buffer): Response body data (not necessarily
                        a whole "chunk" of chunked encoding).

                    *   `**kwargs` (dict): Forward-compatibility kwargs.

                An exception raise by this function will cause the HTTP stream to end in error.
                This callback is always invoked on the connection's event-loop thread.

        Returns:
            HttpClientStream:
        )r   )r8   r   r   r   s       r!   r   zHttpClientConnection.request  s    Z  g{GDDr    c                 X    t        j                  | j                         | j                  S a#  Close the connection.

        Shutdown is asynchronous. This call has no effect if the connection is already
        closing.

        Returns:
            concurrent.futures.Future: This connection's :attr:`shutdown_future`,
            which completes when shutdown has finished.
        rV   http_connection_closerX   rP   rE   s    r!   closezHttpClientConnection.closeH  "     	%%dmm4###r    )NNNNFNNNNr[   )r   r   r   r   r]   classmethodrH   r6   r   r   r   r   r_   r   r   r   r   r   r    r!   r   r      s   
 (I 486:EI:>-21526B7B7B7  0B7 %]3	B7
 %--A$BB7 $$67B7 '+B7 "*#B7 #+3-B7 <WB7 B7L >B9=-E&-E%hy&9:-E "(9"56-E CU-E^$r    r   c                      e Zd Ze	 	 	 	 	 	 	 	 	 	 	 ddededee   dee   dee	   ded   d	ee
e      d
eee
e   gdf      dedee   dedee   dee   ddfd       Z	 	 	 ddddeed      deed      deddf
dZd dZdeddfdZy)!Http2ClientConnectionNrg   rh   ri   rj   rk   rl   rm   ro   rp   rq   rr   rt   ru   rv   r2   r\   c                 \    | j                  ||||||t        j                  |||	|
|||      S )a	  
        Asynchronously establish an HTTP/2 client connection.
        Notes: to set up the connection, the server must support HTTP/2 and TlsConnectionOptions

        This class extends HttpClientConnection with HTTP/2 specific functionality.

        HTTP/2 specific args:
            initial_settings (List[Http2Setting]): The initial settings to change for the connection.

            on_remote_settings_changed: Optional callback invoked once the remote peer changes its settings.
                And the settings are acknowledged by the local connection.
                The function should take the following arguments and return nothing:

                    *   `settings` (List[Http2Setting]): List of settings that were changed.

            manual_window_management (bool): If True, enables manual flow control window management.
                Default is False.

            initial_window_size (Optional[int]): Initial window size for flow control.
                Required if manual_window_management is True, ignored otherwise.

            conn_manual_window_management (bool): If True, enables manual connection-level flow control
                for the entire HTTP/2 connection. When enabled, the connection's flow-control window
                shrinks as body data is received across all streams. The initial connection window is
                65,535 bytes. When the window reaches 0, all streams stop receiving data until
                `update_window()` is called to increment the connection's window.
                Note: Padding in DATA frames counts against the window, but window updates for padding
                are sent automatically even in manual mode. Default is False.

            conn_window_size_threshold (Optional[int]): Threshold for sending connection-level WINDOW_UPDATE
                frames. Ignored if `conn_manual_window_management` is False. When the connection's window
                is above this threshold, WINDOW_UPDATE frames are batched. When it drops below, the update
                is sent. Default is 32,767 (half of the initial 65,535 window).

            stream_window_size_threshold (Optional[int]): Threshold for sending stream-level WINDOW_UPDATE
                frames. Ignored if `manual_window_management` is False. When a stream's window is above
                this threshold, WINDOW_UPDATE frames are batched. When it drops below, the update is sent.
                Default is half of `initial_window_size`.
        )rq   rr   rt   ru   rv   )r   r   r   )r   rg   rh   ri   rj   rk   rl   ro   rp   rq   rr   rt   ru   rv   s                 r!   r   zHttp2ClientConnection.newX  sO    n "&%= 3*G'A)E   G 	Gr    r   r   r   r   r   manual_writeHttp2ClientStreamc                      t        | ||||      S )a(  Create `Http2ClientStream` to carry out the request/response exchange.

        NOTE: The HTTP stream sends no data until `Http2ClientStream.activate()`
        is called. Call activate() when you're ready for callbacks and events to fire.

        Args:
            request (HttpRequest): Definition for outgoing request.

            on_response: Optional callback invoked once main response headers are received.
                The function should take the following arguments and return nothing:

                    *   `http_stream` (`Http2ClientStream`): HTTP/2 stream carrying
                        out this request/response exchange.

                    *   `status_code` (int): Response status code.

                    *   `headers` (List[Tuple[str, str]]): Response headers as a
                        list of (name,value) pairs.

                    *   `**kwargs` (dict): Forward compatibility kwargs.

            on_body: Optional callback invoked 0+ times as response body data is received.
                The function should take the following arguments and return nothing:

                    *   `http_stream` (`Http2ClientStream`): HTTP/2 stream carrying
                        out this request/response exchange.

                    *   `chunk` (buffer): Response body data (not necessarily
                        a whole "chunk" of chunked encoding).

                    *   `**kwargs` (dict): Forward-compatibility kwargs.

            manual_write (bool): If True, enables manual data writing on the stream.
                This allows calling `write_data()` to stream the request body in chunks.
                Note: In the asyncio version, this is replaced by the async_body parameter.

        Returns:
            Http2ClientStream: Stream for the HTTP/2 request/response exchange.
        )r   )r8   r   r   r   r   s        r!   r   zHttp2ClientConnection.request  s    X !wWlSSr    c                 X    t        j                  | j                         | j                  S r   r   rE   s    r!   r   zHttp2ClientConnection.close  r   r    increment_sizec                 D    t        j                  | j                  |       y)z
        Update the connection's flow control window.

        Args:
            increment_size (int): Number of bytes to increment the window by.
        N)rV   http2_connection_update_windowrX   r8   r   s     r!   update_windowz#Http2ClientConnection.update_window  s     	..t}}nMr    )NNNNNNFNFNNNNFr[   )r   r   r   r   rH   r6   r   r   r   r   r
   r.   r   r_   r   r   r   r   r   r    r!   r   r   V  s    486:EI:>=ACG-215278<:>DGDGDG  0DG %]3	DG
 %--A$BDG $$67DG 'tL'9:DG )14;M:N:>;? 2@ )ADG '+DG "*#DG ,0DG )1DG +33-DG D_DG DGP >B9=%*	,T&,T%hy&9:,T "(9"56,T #	,T 0C	,T\$NC ND Nr    r   c                   v     e Zd ZdZdZddeed      ddf fdZede	fd       Z
edd	       Zd
eddfdZ xZS )HttpStreamBasezBase for HTTP stream classes.

    Attributes:
        connection: The HTTP connection this stream belongs to.
        completion_future: Future that completes when the operation finishes.
    )_connection_completion_future_on_body_cbNr   r   r2   c                 \    t         |           || _        t               | _        || _        y r4   )rN   r9   r   r   r   r   )r8   
connectionr   rD   s      r!   r9   zHttpStreamBase.__init__  s(    %"((:Ar    c                     | j                   S r4   )r   rE   s    r!   r   zHttpStreamBase.connection  s    r    c                     | j                   S r4   )r   rE   s    r!   completion_futurez HttpStreamBase.completion_future  s    &&&r    chunkc                 D    | j                   r| j                  | |       y y )N)http_streamr   )r   )r8   r   s     r!   _on_bodyzHttpStreamBase._on_body  s#    U; r    r4   r[   )r   r   r   r   r]   r   r   r9   r^   rJ   r   r   bytesr   r`   ra   s   @r!   r   r     st     EIBHXi5H,I BUY B  .     ' '<e < <r    r   c                        e Zd ZdZdZ	 	 	 ddedddeed      d	eed      d
eddf fdZ	e
defd       Ze
dee   fd       Zdedeeeef      ddfdZdeddfdZddZdeddfdZ xZS )HttpClientStreamBasezBase for HTTP client stream classes.

    Attributes:
        connection: This stream's connection.

        completion_future: Future that completes when
            the request/response exchange is finished.
    )_response_status_code_on_response_cbr   _requestrL   Nr   r   r   r   r   r   http2_manual_writer2   c                 0   t        |t              sJ t        |t              sJ t        |      s|J t        |      s|J t        |   ||       || _        d | _        || _        |j                  | _
        t        j                  | |||      | _        y r4   )r5   rc   r   callablerN   r9   r   r   r   rS   rL   rV   http_client_stream_newrX   )r8   r   r   r   r   r   rD   s         r!   _init_commonz!HttpClientStreamBase._init_common  s     *&>???';///$(;;; GO33W->I48"  "**66tZRder    c                     | j                   S )z)HttpVersion: Protocol used by this streamrR   rE   s    r!   rS   zHttpClientStreamBase.version!  rT   r    c                     | j                   S )zNint: The response status code.

        This is None until a response arrives.)r   rE   s    r!   response_status_codez)HttpClientStreamBase.response_status_code&  s    
 )))r    status_codename_value_pairsc                 T    || _         | j                  r| j                  | ||       y y )N)r   r   headers)r   r   )r8   r   r   s      r!   _on_responsez!HttpClientStreamBase._on_response-  s.    %0"  T{Td e  r    
error_codec                     d | _         |dk(  r&| j                  j                  | j                         y | j                  j	                  t
        j                  j                  |             y )Nr   )r   r   
set_resultr   r~   awscrt
exceptions	from_coder8   r   s     r!   _on_completez!HttpClientStreamBase._on_complete3  sO    ?##..t/I/IJ##11&2C2C2M2Mj2YZr    c                      y)zCalled when remote peer sends END_STREAM (HTTP/2 only).

        This callback is only invoked for HTTP/2 connections. HTTP/1.x streams
        will never receive this callback. Base implementation does nothing.
        Nr   rE   s    r!   _on_h2_remote_end_streamz-HttpClientStreamBase._on_h2_remote_end_stream<  s     	r    r   c                 0    t        j                  | |       y)z
        Update the stream's flow control window.

        Args:
            increment_size (int): Number of bytes to increment the window by.
        N)rV   http_stream_update_windowr   s     r!   r   z"HttpClientStreamBase.update_windowD  s     	))$?r    r   rZ   )r   r   r   r   r]   rc   r   r   r_   r   r^   r   rS   r6   r   r
   r   rH   r   r   r   r   r`   ra   s   @r!   r   r      s    dI
 CG>B05f!9f+f #+8I+>"?f 'x	':;	f
 *.f
 ;?f*    *hsm * *f ftE#s(O?T fY] f[s [t [@C @D @r    r   c                   R    e Zd ZdZ	 	 ddedddeed      deed      d	df
d
ZddZy)r   a  HTTP stream that sends a request and receives a response.

    Create an HttpClientStream with :meth:`HttpClientConnection.request()`.

    NOTE: The HTTP stream sends no data until :meth:`HttpClientStream.activate()`
    is called. Call activate() when you're ready for callbacks and events to fire.

    Attributes:
        connection (HttpClientConnection): This stream's connection.

        completion_future (concurrent.futures.Future): Future that will contain
            the response status code (int) when the request/response exchange
            completes. If the exchange fails to complete, the Future will
            contain an exception indicating why it failed.
    Nr   r   r   r   r   r   r2   c                 ,    | j                  ||||       y r4   )r   )r8   r   r   r   r   s        r!   r9   zHttpClientStream.__init___  s    
 	*g{GDr    c                 .    t        j                  |        yzBegin sending the request.

        The HTTP stream does nothing until this is called. Call activate() when you
        are ready for its callbacks and events to fire.
        NrV   http_client_stream_activaterE   s    r!   activatezHttpClientStream.activatef       	++D1r    r   rZ   )	r   r   r   r   r   r   r   r9   r   r   r    r!   r   r   N  sd    & ?C:>	E1E'E 'x	':;E #8I#67	E DH	E2r    r   c                       e Zd ZdZ	 	 	 ddedddeed      deed      d	ed
dfdZe	dd       Z
ddZded
dfdZddZ	 ddeeef   ded
dfdZy)r   _remote_end_stream_futureNr   r   r   r   r   r   r   r2   c                 L    t               | _        | j                  |||||       y r4   )r   r   r   )r8   r   r   r   r   r   s         r!   r9   zHttp2ClientStream.__init__r  s$     *0&*g{G\Rr    r\   c                     | j                   S )a  
        concurrent.futures.Future: Future that completes when the remote peer has finished
        sending (HTTP/2 only). This occurs when the server sends an END_STREAM flag.

        The future will contain a result of None on success, or an exception if the stream
        encounters an error before END_STREAM is received (e.g., RST_STREAM).

        This is different from `completion_future` which completes when both the
        client and server have finished (bidirectional stream closure).

        Note: This future only applies to HTTP/2 connections. It will complete when the
        server sends END_STREAM, which may occur before the client finishes sending.
        In case of stream completed without END_STREAM received, this future will complete
        with exception.
        r   rE   s    r!   remote_end_stream_futurez*Http2ClientStream.remote_end_stream_future{  s    " ---r    c                 p    | j                   j                         s| j                   j                  d       yy)zBInternal callback when remote peer sends END_STREAM (HTTP/2 only).N)r   doner   rE   s    r!   r   z*Http2ClientStream._on_h2_remote_end_stream  s-    --224**55d; 5r    r   c                 T   d | _         | j                  j                         s$| j                  j                  t	        d             |dk(  r&| j
                  j                  | j                         y | j
                  j                  t        j                  j                  |             y )Nz4Stream completed without receiving remote END_STREAMr   )r   r   r   r~   RuntimeErrorr   r   r   r   r   r   r   s     r!   r   zHttp2ClientStream._on_complete  s     --224 **88STV ?##..t/I/IJ##11&2C2C2M2Mj2YZr    c                 .    t        j                  |        yr   r   rE   s    r!   r   zHttp2ClientStream.activate  r   r    data_stream
end_streamc                     t               t        j                  |d      }dt        ddffd}t	        j
                  | |||       S )an  Write a chunk of data to the request body stream.

        This method is only available when the stream was created with
        manual_write=True. This allows incremental writing of request data.

        Note: In the asyncio version, this is replaced by the request_body_generator parameter
        which accepts an async generator.

        Args:
            data_stream (Union[InputStream, Any]): Data to write. If not an InputStream,
                it will be wrapped in one. Can be None to send an empty chunk.

            end_stream (bool): True to indicate this is the last chunk and no more data
                will be sent. False if more chunks will follow.

        Returns:
            concurrent.futures.Future: Future that completes when the write operation
                is done. The future will contain None on success, or an exception on failure.
        T)
allow_noner   r2   Nc                     j                         ry | r/j                  t        j                  j	                  |              y j                  d        y r4   )	cancelledr~   r   r   r   r   )r   r   s    r!   on_write_completez7Http2ClientStream.write_data.<locals>.on_write_complete  sB    !$$V%6%6%@%@%LM!!$'r    )r   r   wrapr6   rV   http2_client_stream_write_data)r8   r   r   body_streamr   r   s        @r!   
write_datazHttp2ClientStream.write_data  sM    , !&&{tD	(# 	($ 	( 	..t[*N_`r    r   r[   rZ   )F)r   r   r   r]   r   r   r   r_   r9   r^   r   r   r6   r   r   r   r   r   r   r   r    r!   r   r   o  s    .I
 ?C:>&+S1S'S 'x	':;S #8I#67	S
  $S
 15S . .$<
[s [t [ 2 ',# %k3&6 7###0K#r    r   c            
            e Zd ZdZdZ	 ddedddeeeef      ddf fd	Z	e
dd
       Ze
dee   fd       Zej                  deeef   ddfd       Z xZS )HttpMessageBasez8
    Base for HttpRequest and HttpResponse classes.
    )_headers_body_streamNbindingr   HttpHeadersr   r2   c                     t        |t              sJ t        |           || _        || _        d | _        |r|| _        y y r4   )r5   r   rN   r9   rX   r   r   r   )r8   r   r   r   rD   s       r!   r9   zHttpMessageBase.__init__  sD    ';///37*D r    c                     | j                   S )zHttpHeaders: Headers to send.)r   rE   s    r!   r   zHttpMessageBase.headers  rT   r    c                     | j                   S r4   )r   rE   s    r!   r   zHttpMessageBase.body_stream  s       r    streamc                     t        j                  |      | _        t        j                  | j
                  | j                         y r4   )r   r   r   rV   http_message_set_body_streamrX   )r8   r   s     r!   r   zHttpMessageBase.body_stream  s/    ',,V4,,T]]D<M<MNr    r4   )r2   r   )r   r   r   r   r]   r   r   r   r   r9   r^   r   r   setterr`   ra   s   @r!   r   r     s     -I CG
+ 
+m 
+&u[#-='>?
+KO
+   !Xk2 ! ! O%S(8"9 Od O Or    r   c                       e Zd ZdZdZ	 	 	 	 ddededed   deeee	f      d	df
 fd
Z
ede	de	d	d f fd       Zed	efd       Zej                  ded	dfd       Zed	efd       Zej                  ded	dfd       Z xZS )r   a  
    Definition for an outgoing HTTP request.

    The request may be transformed (ex: signing the request) before its data is eventually sent.

    Args:
        method (str): HTTP request method (verb). Default value is "GET".
        path (str): HTTP path-and-query value. Default value is "/".
        headers (Optional[HttpHeaders]): Optional headers. If None specified,
            an empty :class:`HttpHeaders` is created.
        body_stream(Optional[Union[InputStream, io.IOBase]]): Optional body as binary stream.
    r   Nmethodpathr   r   r   r2   c                     t        |t              s|J |
t               }t        j                  |      }t        |   |||       || _        || _        y r4   )r5   r   rV   http_message_new_requestrN   r9   r   r  )r8   r   r  r   r   r   rD   s         r!   r9   zHttpRequest.__init__  sT    
 ';/7?BB?!mG227;';7	r    request_bindingheaders_bindingc                 t    | j                  |       }t        j                  |      }t        | |  ||       |S )zJConstruct HttpRequest and its HttpHeaders from pre-existing native objects)__new__r   _from_bindingrN   r9   )r   r  r  r   r   rD   s        r!   _from_bindingszHttpRequest._from_bindings  s9     ++c"++O<c7$_g>r    c                 @    t        j                  | j                        S )z str: HTTP request method (verb).)rV   http_message_get_request_methodrX   rE   s    r!   r   zHttpRequest.method  s     66t}}EEr    c                 D    t        j                  | j                  |       y r4   )rV   http_message_set_request_methodrX   )r8   r   s     r!   r   zHttpRequest.method!  s    //vFr    c                 @    t        j                  | j                        S )zstr: HTTP path-and-query value.)rV   http_message_get_request_pathrX   rE   s    r!   r  zHttpRequest.path%  s     44T]]CCr    c                 B    t        j                  | j                  |      S r4   )rV   http_message_set_request_pathrX   )r8   r  s     r!   r  zHttpRequest.path*  s    44T]]DIIr    )GET/NN)r   r   r   r   r]   rH   r   r   r   r   r9   r   r	  r^   r   r   r  r`   ra   s   @r!   r   r     s    I  % 48BF	 #=1 'u[#-='>?	 LP	 S 3 =   F F F ]]GS GT G G Dc D D 
[[J J J Jr    r   c                   :    e Zd ZdZdZddeeeeef         ddf fdZ	e
dedd f fd       Zd	ed
eddfdZdeeeef      ddfdZd	ed
eddfdZd	edee   fdZdd	edee   dee   fdZd	eddfdZd	ed
eddfdZddZdeeeef      fdZdefdZ xZS )r   a\  
    Collection of HTTP headers.

    A given header name may have multiple values.
    Header names are always treated in a case-insensitive manner.
    HttpHeaders can be iterated over as (name,value) pairs.

    Args:
        name_value_pairs (Optional[List[Tuple[str, str]]]): Construct from a
            collection of (name,value) pairs.
    r   Nr   r2   c                 |    t         |           t        j                         | _        |r| j                  |       y y r4   )rN   r9   rV   http_headers_newrX   	add_pairs)r8   r   rD   s     r!   r9   zHttpHeaders.__init__>  s3    002NN+, r    r   c                 T    | j                  |       }t        | |          ||_        |S )z+Construct from a pre-existing native object)r  rN   r9   rX   )r   r   r   rD   s      r!   r  zHttpHeaders._from_bindingD  s-     ++c"c7$&"r    r;   r1   c                     t        |t              sJ t        |t              sJ t        j                  | j                  ||       y)zu
        Add a name-value pair.

        Args:
            name (str): Name.
            value (str): Value.
        N)r5   rH   rV   http_headers_addrX   r8   r;   r1   s      r!   addzHttpHeaders.addL  :     $$$$%%%%  e<r    c                 D    t        j                  | j                  |       y)z
        Add list of (name,value) pairs.

        Args:
            name_value_pairs (List[Tuple[str, str]]): List of (name,value) pairs.
        N)rV   http_headers_add_pairsrX   )r8   r   s     r!   r  zHttpHeaders.add_pairsX  s     	&&t}}6FGr    c                     t        |t              sJ t        |t              sJ t        j                  | j                  ||       y)z
        Set a name-value pair, any existing values for the name are removed.

        Args:
            name (str): Name.
            value (str): Value.
        N)r5   rH   rV   http_headers_setrX   r  s      r!   setzHttpHeaders.seta  r  r    c              #      K   t        |t              sJ |j                         }t        t	        j
                  | j                              D ]=  }t	        j                  | j                  |      \  }}|j                         |k(  s:| ? yw)z
        Return an iterator over the values for this name.

        Args:
            name (str): Name.

        Returns:
            Iterator[str]: Iterator over values for this header name
        N)r5   rH   lowerrangerV   http_headers_countrX   http_headers_get_index)r8   r;   iname_ivalue_is        r!   
get_valueszHttpHeaders.get_valuesm  ss      $$$$zz|w11$--@A 	A%<<T]]ANOFG||~%	s   BBBdefaultc                 h    t        |t              sJ t        j                  | j                  ||      S )ag  
        Get the first value for this name, ignoring any additional values.
        Returns `default` if no values exist.

        Args:
            name (str): Name.
            default (Optional[str]): If `name` not found, this value is returned.
                Defaults to None.
        Returns:
            Optional[str]: Header value or default
        )r5   rH   rV   http_headers_getrX   )r8   r;   r,  s      r!   getzHttpHeaders.get~  s-     $$$$''tWEEr    c                 h    t        |t              sJ t        j                  | j                  |       y)z
        Remove all values for this name.
        Raises a KeyError if name not found.

        Args:
            name (str): Header name.
        N)r5   rH   rV   http_headers_removerX   )r8   r;   s     r!   removezHttpHeaders.remove  s(     $$$$##DMM48r    c                     t        |t              sJ t        |t              sJ t        j                  | j                  ||       y)z
        Remove a specific value for this name.
        Raises a ValueError if value not found.

        Args:
            name (str): Name.
            value (str): Value.
        N)r5   rH   rV   http_headers_remove_valuerX   r  s      r!   remove_valuezHttpHeaders.remove_value  s:     $$$$%%%%))$--uEr    c                 B    t        j                  | j                         y)z$
        Clear all headers.
        N)rV   http_headers_clearrX   rE   s    r!   clearzHttpHeaders.clear  s     	""4==1r    c              #      K   t        t        j                  | j                              D ]$  }t        j                  | j                  |       & yw)z6
        Iterate over all (name,value) pairs.
        N)r%  rV   r&  rX   r'  )r8   r(  s     r!   __iter__zHttpHeaders.__iter__  sD      w11$--@A 	CA00BB	Cs   AAc                 x    | j                   j                  dz   t        | D cg c]  }| c}      z   dz   S c c}w )NrA   rC   )rD   r   rH   )r8   pairs     r!   rF   zHttpHeaders.__str__  s4    ~~&&,sT3JTD3J/KKcQQ3Js   	7
r4   rZ   )r   r   r   r   r]   r   r
   r   rH   r9   r   r   r  r  r  r"  r   r+  r/  r2  r5  r8  r:  rF   r`   ra   s   @r!   r   r   /  sJ   
 I-$uS#X2G)H -TX - C M  
= 
=C 
=D 
=H$uS#X*? HD H
= 
=C 
=D 
=s x} "F Fhsm Fx} F	93 	94 	9F FS FT F2C(5c?3 CR Rr    r   c                        e Zd ZdZdZ	 dZ	 dZy)HttpProxyConnectionTypez!Proxy connection type enumerationr   r   r   N)r   r   r   r   Legacy
Forwarding	Tunnelingr   r    r!   r>  r>    s%    +F J IVr    r>  c                       e Zd ZdZdZ	 dZy)HttpProxyAuthenticationTypez&Proxy authentication type enumeration.r   r   N)r   r   r   r   NothingBasicr   r    r!   rC  rC    s    0GEr    rC  c                   ~    e Zd ZdZdej
                  ddej                  fdede	de
e   dede
e   de
e   d	ed
dfdZy)rm   aS  
    Proxy options for HTTP clients.

    Args:
        host_name (str): Name of the proxy server to connect through.

        port (int): Port number of the proxy server to connect through.

        tls_connection_options (Optional[TlsConnectionOptions]): Optional
            `TlsConnectionOptions` for the Local to Proxy connection.
            Must be distinct from the `TlsConnectionOptions`
            provided to the HTTP connection.

        auth_type (HttpProxyAuthenticationType): Type of proxy authentication to use.
            Default is :const:`HttpProxyAuthenticationType.Nothing`.

        auth_username (Optional[str]): Username to use when `auth_type` is
            :const:`HttpProxyAuthenticationType.Basic`.

        auth_password (Optional[str]): Username to use when `auth_type` is
            :const:`HttpProxyAuthenticationType.Basic`.

        connection_type (Optional[HttpProxyConnectionType): Type of proxy connection to make.
            Default is :const:`HttpProxyConnectionType.Legacy`.


    Attributes:
        host_name (str): Name of the proxy server to connect through.

        port (int): Port number of the proxy server to connect through.

        tls_connection_options (Optional[TlsConnectionOptions]): Optional
            `TlsConnectionOptions` for the Local to Proxy connection.
            Must be distinct from the `TlsConnectionOptions`
            provided to the HTTP connection.

        auth_type (HttpProxyAuthenticationType): Type of proxy authentication to use.

        auth_username (Optional[str]): Username to use when `auth_type` is
            :const:`HttpProxyAuthenticationType.Basic`.

        auth_password (Optional[str]): Username to use when `auth_type` is
            :const:`HttpProxyAuthenticationType.Basic`.

        connection_type (HttpProxyConnectionType): Type of proxy connection to make.

    Nrg   rh   rk   	auth_typeauth_usernameauth_passwordconnection_typer2   c                 f    || _         || _        || _        || _        || _        || _        || _        y r4   )rg   rh   rk   rG  rH  rI  rJ  )r8   rg   rh   rk   rG  rH  rI  rJ  s           r!   r9   zHttpProxyOptions.__init__  s9     #	&<#"**.r    )r   r   r   r   rC  rD  r>  r?  rH   r6   r   r   r9   r   r    r!   rm   rm     s    .f KO:U:]:]0404<S<Z<Z/// *22F)G/ 8	/
 !)/ !)/ #:/ `d/r    rm   c                       e Zd ZdZ	 	 	 	 	 	 ddededee   dee   dee	   dee
   d	eeee   gdf      d
dfdZdedede
d
dfdZded
dfdZdeeeef      d
dfdZy)r{   zr
    Private class to keep all the related Python object alive until C land clean up for HttpClientConnection
    Nrg   rh   ri   rk   rx   rn   rp   r2   c	                     d | _         || _        || _        || _        || _        || _        || _        || _        || _        y r4   )	rK   re   rf   
_bootstrap_tls_connection_options_connect_future_expected_version%_on_remote_settings_changed_from_user_asyncio_connection)	r8   rg   rh   ri   rk   rx   rn   rp   ry   s	            r!   r9   z"_HttpClientConnectionCore.__init__  sI     !%#
#'=$-!15O2#5 r    r   r   http_versionc                    | j                   y |dk7  r9| j                   j                  t        j                  j	                  |             y | j
                  rH| j
                  |k7  r9| j                   j                  t        j                  j	                  d             y | j                  r+ddlm}m	} |t        j                  k(  r |       }n0 |       }n(|t        j                  k(  rt               }n
t               }| j                  |_        | j                  |_        ||_        t        |      |_        |j$                  | _        | j                   j)                  |       d | _         y )Nr   i  )AIOHttpClientConnectionAIOHttp2ClientConnection)rP  r~   r   r   r   rQ  rS  awscrt.aio.httprV  rW  r   r   r   r   re   rf   rX   rL   rP   rK   r   )r8   r   r   rT  rV  rW  r   s          r!   _on_connection_setupz._HttpClientConnectionCore._on_connection_setup/  s   '?  ..v/@/@/J/J:/VW!!d&<&<&L   ..v/@/@/J/J4/PQ##Y{00057
46
{00024
13
 $
::
%
),7
 * : :''
3#r    c                     | j                   y |r9| j                   j                  t        j                  j	                  |             y | j                   j                  d        y r4   )rK   r~   r   r   r   r   r   s     r!   _on_shutdownz&_HttpClientConnectionCore._on_shutdownQ  sM      (!!//0A0A0K0KJ0WX!!,,T2r    native_settingsc           	          | j                   r9|D cg c]  \  }}t        t        |      |       }}}| j                  |       y y c c}}w r4   )rR  r.   r#   )r8   r\  r0   r1   settingss        r!   _on_remote_settings_changedz5_HttpClientConnectionCore._on_remote_settings_changedZ  sD    55Q`aIB^B%7?aHa66x@ 6as   A)NNNNNF)r   r   r   r   rH   r6   r   r   r   r   r   r   r
   r.   r9   r   rY  r[  r   r_  r   r    r!   r{   r{     s     48EI/36:Y]$66 6  0	6
 %--A$B6 %V,6 '{36 )14;M:NPT:T1U(V6 *.6( $C  $S  $P[  $`d  $D3s 3t 3A4c3h;P AUY Ar    r{   ))r   rV   concurrent.futuresr   r   r   awscrt.exceptions	awscrt.ior   r   r   r   enumr	   typingr
   r   r   r   r   r   r   r   r   r#   r.   rJ   rc   r   r   r   r   r   r   r   r   r   r>  rC  rm   r{   r   r    r!   <module>re     s+    % !  W W  N N N' W /J /Jd> >BQ1 QhG$3 G$TKN4 KN\<^ <8K@> K@\2+ 2B_, _DOn OB:J/ :JzDR. DRNWg W* '  ?/ ?/DHA HAr    