o
    tBh@                     @   s   d dl Z d dlZd dlZd dlZd dlZd dl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 d dlmZ d dlmZ d d	lmZ d d
lmZmZmZ eeZe ZdZdZdd Z G dd dZ!G dd dZ"dS )    N)parsers)create_request_object)HTTPClientError)get_global_history_recorder)first_non_none_response)handle_checksum_body)URLLib3Session)StreamingBody)get_environ_proxiesis_valid_endpoint_urlis_valid_ipv6_endpoint_url<   
   c                 C   sz   | j | jd|jid}|d dkr| j|d< |S |jr"| j|d< |S |jr6|d d}t| j||d< |S | j|d< |S )a  Convert an HTTP response object to a request dict.

    This converts the requests library's HTTP response object to
    a dictionary.

    :type http_response: botocore.vendored.requests.model.Response
    :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   ,  bodyr   zcontent-length)	r   r   namecontenthas_event_stream_outputrawhas_streaming_outputgetr	   )http_responseoperation_modelresponse_dictlength r   h/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/botocore/endpoint.pyconvert_to_response_dict*   s"   


r!   c                   @   s   e Zd ZdZ		d!ddZ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dd Zdd Zdd Z		d!ddZdd  ZdS )#Endpointa,  
    Represents an endpoint for a particular service in a specific
    region.  Only an endpoint can make requests.

    :ivar service: The Service object that describes this endpoints
        service.
    :ivar host: The fully qualified endpoint hostname.
    :ivar session: The session object.
    Nc                 C   sR   || _ || _|| _t | _|d u rt }|| _|| _	| j	d u r't
 | _	d S d S N)_endpoint_prefix_event_emitterhost	threadingLock_lockr   ResponseParserFactory_response_parser_factoryhttp_sessionr   )selfr&   endpoint_prefixevent_emitterresponse_parser_factoryr,   r   r   r    __init__X   s   

zEndpoint.__init__c                 C   s   | j  d| j dS )N())r$   r&   )r-   r   r   r    __repr__k   s   zEndpoint.__repr__c                 C   s   t d|| | ||S )Nz%Making request for %s with params: %s)loggerdebug_send_request)r-   r   request_dictr   r   r    make_requestn   s   zEndpoint.make_requestc                 C   s\   t |}|r't|j|jg|_|jj }dj||j	d}| j
j|||j	d | |}|S )Nz&request-created.{service_id}.{op_name})
service_idop_name)requestr   )r   anyr   r   stream_outputservice_modelr:   	hyphenizeformatr   r%   emitprepare_request)r-   paramsr   r<   r:   
event_nameprepared_requestr   r   r    create_requestv   s$   
zEndpoint.create_requestc                 C   s.   |  D ]\}}t|tr|d||< qd S )Nzutf-8)items
isinstancestrencode)r-   r   keyvaluer   r   r    _encode_headers   s
   
zEndpoint._encode_headersc                 C   s   |  |j | S r#   )rN   r   preparer-   r<   r   r   r    rC      s   zEndpoint.prepare_requestc                 C   s>   t j  }t j |d}|| }|t j|d | }|dS )Nz%a, %d %b %Y %H:%M:%S %Z)secondsz%Y%m%dT%H%M%SZ)datetimeutcnowstrptime	timedeltastrftime)r-   response_received_timestampdate_headerread_timeoutlocal_timestampdate_conversionestimated_skewttlr   r   r    _calculate_ttl   s   


zEndpoint._calculate_ttlc                 C   sp   |d j d}|d}|r4|s6ztj }| ||||d< W d S  ty3   tjddd Y d S w d S d S )Nr   Datehas_streaming_inputr]   z9Exception received when updating retries context with TTLTexc_info)r   r   rR   rS   r^   	Exceptionr5   r6   )r-   retries_contextrY   success_responseresponse_date_headerr`   rW   r   r   r    _set_ttl   s"   

zEndpoint._set_ttlc                 C   sP   | di }||d< d|vrtt |d< |r&|d j}| ||| d S d S )Nretriesattemptzinvocation-idclient_config)
setdefaultrJ   uuiduuid4rY   rg   )r-   r   ri   re   rd   rY   r   r   r    _update_retries_context   s   
z Endpoint._update_retries_contextc           	      C   s   d}|d }|  || | ||}| |||\}}| |||||rK|d7 }|  ||| |  | ||}| |||\}}| |||||s$|d urad|d v ra|d }||d d d< |d urg||S )N   r   ResponseMetadataRetryAttempts)rn   rG   _get_response_needs_retryreset_stream)	r-   r8   r   attemptsr   r<   re   	exceptiontotal_retriesr   r   r    r7      sL   
zEndpoint._send_requestc           
      C   s|   |  |||\}}d d ||d}|d ur#|\}}||d< t|||d< |jj }	| jjd|	 d|j fi | ||fS )N)r   parsed_responser   rv   rx   r   zresponse-received..)_do_get_responser!   r?   r:   r@   r%   rB   r   )
r-   r<   r   r   re   rv   kwargs_to_emitr   rx   r:   r   r   r    rr      s*   zEndpoint._get_responsec              
   C   sl  z=t d| td|j|j|j|j|jd |j	j
 }d| d|j }| jj||d}t|}|d u r<| |}W n2 tyS } z
d |fW  Y d }~S d }~w tyo } zt jddd	 d |fW  Y d }~S d }~ww t||}	t||	|| |	 }
|j|
d
< td|
 |jd }| j|}||	|j}|jdkr| |	||| td| ||fd fS )NzSending http request: %sHTTP_REQUEST)methodr   	streamingurlr   zbefore-send.ry   )r<   z-Exception received when sending HTTP request.Tra   r~   HTTP_RESPONSEprotocolr   PARSED_RESPONSE)r5   r6   history_recorderrecordr}   r   r`   r   r   r?   r:   r@   r   r%   rB   r   _sendr   rc   r!   r   copyr   metadatar+   create_parserparseoutput_shaper   _add_modeled_error_fields)r-   r<   r   r   r:   rE   	responsesr   er   http_response_record_dictr   parserrx   r   r   r    rz     sr   



zEndpoint._do_get_responsec           	      C   sT   | di  d}|d u rd S |j}||}|d u rd S |||}|| d S )NErrorCode)r   r?   shape_for_error_coder   update)	r-   r   rx   r   r   
error_coder?   error_shapemodeled_parser   r   r    r   C  s   
z"Endpoint._add_modeled_error_fieldsc           
   	   C   sf   |j j }d| d|j }| jj||| ||||d}t|}	|	d u r&dS td|	 t	
|	 dS )Nzneeds-retry.ry   )responseendpoint	operationru   caught_exceptionr8   Fz3Response received to retry, sleeping for %s secondsT)r?   r:   r@   r   r%   rB   r   r5   r6   timesleep)
r-   ru   r   r8   r   r   r:   rE   r   handler_responser   r   r    rs   U  s(   	
zEndpoint._needs_retryc                 C   s   | j |S r#   )r,   sendrP   r   r   r    r   u  s   zEndpoint._send)NNr#   )__name__
__module____qualname____doc__r1   r4   r9   rG   rN   rC   r^   rg   rn   r7   rr   rz   r   rs   r   r   r   r   r    r"   M   s*    



)?
 r"   c                	   @   s@   e Zd Zdd Zddeeeddddf	ddZdd Zdd	 Z	dS )
EndpointCreatorc                 C   s
   || _ d S r#   )r%   )r-   r/   r   r   r    r1   z  s   
zEndpointCreator.__init__Nc              	   C   sr   t |st|std| |	d u r| |}	|j}td|| |||	| |||
||d}t||| j	||dS )NzInvalid endpoint: %szSetting %s timeout as %s)timeoutproxiesverifymax_pool_connectionssocket_optionsclient_certproxies_config)r.   r/   r0   r,   )
r   r   
ValueError_get_proxiesr.   r5   r6   _get_verify_valuer"   r%   )r-   r?   region_nameendpoint_urlr   r0   r   r   http_session_clsr   r   r   r   r.   r,   r   r   r    create_endpoint}  s4   

zEndpointCreator.create_endpointc                 C   s   t |S r#   )r
   )r-   r   r   r   r    r     s   zEndpointCreator._get_proxiesc                 C   s   |d ur|S t jddS )NREQUESTS_CA_BUNDLET)osenvironr   )r-   r   r   r   r    r     s   z!EndpointCreator._get_verify_value)
r   r   r   r1   DEFAULT_TIMEOUTMAX_POOL_CONNECTIONSr   r   r   r   r   r   r   r    r   y  s    
+r   )#rR   loggingr   r'   r   rl   botocorer   botocore.awsrequestr   botocore.exceptionsr   botocore.historyr   botocore.hooksr   botocore.httpchecksumr   botocore.httpsessionr   botocore.responser	   botocore.utilsr
   r   r   	getLoggerr   r5   r   r   r   r!   r"   r   r   r   r   r    <module>   s0   
#  .