o
    di1                     @   s   d dl Z d dlmZmZmZmZmZmZmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZmZ zd dlZW n eyM   dZY nw eZdd	 ZG d
d deZG dd deZdS )    N)
DEFAULT_TIMEOUTMAX_POOL_CONNECTIONSEndpointEndpointCreatorHTTPClientErrorcreate_request_objecthistory_recorderis_valid_endpoint_urlis_valid_ipv6_endpoint_urllogger)first_non_none_response)handle_checksum_body)AIOHTTPSession)AioResponseParserFactory)HttpxStreamingBodyStreamingBodyc                    s   | j | jd|jid}|d dkr| jI dH |d< |S |jr&| j|d< |S |jrLtr;t| jtj	r;t
| j|d< |S |d d}t| j||d< |S | jI dH |d< |S )	a  Convert an HTTP response object to a request dict.

    This converts the HTTP response object to a dictionary.

    :type http_response: botocore.awsrequest.AWSResponse
    :param http_response: The HTTP response from an AWS service request.

    :rtype: dict
    :return: A response dictionary which will contain the following keys:
        * headers (dict)
        * status_code (int)
        * body (string or file-like object)

    operation_name)headersstatus_codecontextr   ,  Nbodyr   zcontent-length)r   r   namecontenthas_event_stream_outputrawhas_streaming_outputhttpx
isinstanceResponser   getr   )http_responseoperation_modelresponse_dictlength r%   H/home/ubuntu/.local/lib/python3.10/site-packages/aiobotocore/endpoint.pyconvert_to_response_dict   s*   
	r'   c                       sj   e Zd Z		d fdd	Zdd ZdddZdd	 Zd
d Zdd Zdd Z			dddZ
dd Z  ZS )AioEndpointNc                    s8   |d u rt  }|d u rtdt j|||||d d S )Nzhttp_session must be provided)hostendpoint_prefixevent_emitterresponse_parser_factoryhttp_session)r   
ValueErrorsuper__init__)selfr)   r*   r+   r,   r-   	__class__r%   r&   r0   D   s   
zAioEndpoint.__init__c                    s   | j  I d H  d S N)r-   close)r1   r%   r%   r&   r5   Z   s   zAioEndpoint.closec                    sf   t |}|r,t|j|jg|_|jj }d| d|j }| j	j
|||jdI d H  | |}|S )Nzrequest-created..)requestr   )r   anyr   r   stream_outputservice_model
service_id	hyphenizer   _event_emitteremitprepare_request)r1   paramsr"   r7   r;   
event_nameprepared_requestr%   r%   r&   create_request]   s"   
zAioEndpoint.create_requestc           	         s   d}|d }|  || | ||I d H }| |||I d H \}}| |||||I d H r^|d7 }|  ||| |  | ||I d H }| |||I d H \}}| |||||I d H s.|d urtd|d v rt|d }||d d d< |d urz||S )N   r   ResponseMetadataRetryAttempts)_update_retries_contextrC   _get_response_needs_retryreset_stream)	r1   request_dictr"   attemptsr   r7   success_response	exceptiontotal_retriesr%   r%   r&   _send_requestp   sJ   

zAioEndpoint._send_requestc           
         s   |  |||I d H \}}d d ||d}|d ur*|\}}||d< t||I d H |d< |jj }	| jjd|	 d|j fi |I d H  ||fS )N)r#   parsed_responser   rN   rQ   r#   zresponse-received.r6   )_do_get_responser'   r:   r;   r<   r=   r>   r   )
r1   r7   r"   r   rM   rN   kwargs_to_emitr!   rQ   r;   r%   r%   r&   rH      s,   zAioEndpoint._get_responsec              
      s  zCt d| td|j|j|j|j|jd |j	j
 }d| d|j }| jj||dI d H }t|}|d u rC| |I d H }W n2 tyZ } z
d |fW  Y d }~S d }~w tyv } zt jddd	 d |fW  Y d }~S d }~ww t||I d H }	t||	||I d H  |	 }
|j|
d
< td|
 |j	j}i }| jjd| d|j ||	|dI d H  | j|}||	|jI d H }|| |jdkr| |	|||I d H  td| ||fd fS )NzSending http request: %sHTTP_REQUEST)methodr   	streamingurlr   zbefore-send.r6   )r7   z-Exception received when sending HTTP request.T)exc_inforV   HTTP_RESPONSEzbefore-parse.)r"   r#   customized_response_dictr   PARSED_RESPONSE)r   debugr   recordrU   r   has_streaming_inputrW   r   r:   r;   r<   r   r=   r>   r   _sendr   	Exceptionr'   r   copyr   resolved_protocol_response_parser_factorycreate_parserparseoutput_shapeupdater   _add_modeled_error_fields)r1   r7   r"   r   r;   rA   	responsesr!   er#   http_response_record_dictprotocolrZ   parserrQ   r%   r%   r&   rR      s   






zAioEndpoint._do_get_responsec           	         s\   | di  d}|d u rd S |j}||}|d u rd S |||I d H }|| d S )NErrorCode)r    r:   shape_for_error_codere   rg   )	r1   r#   rQ   r"   rm   
error_coder:   error_shapemodeled_parser%   r%   r&   rh      s   
z%AioEndpoint._add_modeled_error_fieldsc           
   	      st   |j j }d| d|j }| jj||| ||||dI d H }t|}	|	d u r*dS td|	 t	
|	I d H  dS )Nzneeds-retry.r6   )responseendpoint	operationrL   caught_exceptionrK   Fz3Response received to retry, sleeping for %s secondsT)r:   r;   r<   r   r=   r>   r   r   r\   asynciosleep)
r1   rL   r"   rK   rt   rw   r;   rA   ri   handler_responser%   r%   r&   rI     s*   	zAioEndpoint._needs_retryc                    s   | j |I d H S r4   )r-   send)r1   r7   r%   r%   r&   r_   .  s   zAioEndpoint._send)NNr4   )__name__
__module____qualname__r0   r5   rC   rP   rH   rR   rh   rI   r_   __classcell__r%   r%   r2   r&   r(   C   s    
)F
 r(   c                
   @   s*   e Zd Zddeeedddddf
ddZdS )AioEndpointCreatorNc              
   C   sv   t |st|std| |	d u r| |}	|j}td|| |||	| |||
|||d}t||| j	||dS )NzInvalid endpoint: zSetting %s timeout as %s)timeoutproxiesverifymax_pool_connectionssocket_optionsclient_certproxies_configconnector_args)r*   r+   r,   r-   )
r	   r
   r.   _get_proxiesr*   r   r\   _get_verify_valuer(   r=   )r1   r:   region_nameendpoint_urlr   r,   r   r   http_session_clsr   r   r   r   r   r*   r-   r%   r%   r&   create_endpoint3  s6   
z"AioEndpointCreator.create_endpoint)r|   r}   r~   r   r   DEFAULT_HTTP_SESSION_CLSr   r%   r%   r%   r&   r   2  s    r   )rx   botocore.endpointr   r   r   r   r   r   r   r	   r
   r   botocore.hooksr   aiobotocore.httpchecksumr   aiobotocore.httpsessionr   aiobotocore.parsersr   aiobotocore.responser   r   r   ImportErrorr   r'   r(   r   r%   r%   r%   r&   <module>   s"    0% p