
    "hjC                         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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j:                  e      Z e       Z dZ!dZ"d Z# G d d      Z$ G d d      Z%y)    N)parsers)create_request_object)get_current_datetime)HTTPClientErrorInvalidConfigError)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                 R   | j                   | j                  d|j                  id}|d   dk\  r| j                  |d<   |S |j                  r| j
                  |d<   |S |j                  r/|d   j                  d      }t        | j
                  |      |d<   |S | j                  |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   ,  bodyr   zcontent-length)	r   r   namecontenthas_event_stream_outputrawhas_streaming_outputgetr   )http_responseoperation_modelresponse_dictlengths       O/root/.hermes/SkillClaw/.venv/lib/python3.12/site-packages/botocore/endpoint.pyconvert_to_response_dictr$   +   s      !(($00o22
M ]#s* - 5 5f  
	0	0 - 1 1f  
	-	-y)--.>? -m.?.? Hf  !. 5 5f    c                       e Zd ZdZ	 	 ddZd Zd Zd ZddZd Z	d	 Z
d
 Zd ZddZd Zd Zd Zd Z	 	 ddZd Zy)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                     || _         || _        || _        t        j                         | _        |t        j                         }|| _        || _	        | j                  t               | _	        y y N)_endpoint_prefix_event_emitterhost	threadingLock_lockr   ResponseParserFactory_response_parser_factoryhttp_sessionr   )selfr,   endpoint_prefixevent_emitterresponse_parser_factoryr2   s         r#   __init__zEndpoint.__init__X   sj     !0+	^^%
"*&-&C&C&E#(?%($ . 0D %r%   c                 :    | j                    d| j                   dS )N())r*   r,   r3   s    r#   __repr__zEndpoint.__repr__k   s     ''($))A66r%   c                 8    | j                   j                          y r)   )r2   closer;   s    r#   r>   zEndpoint.closen   s    !r%   c                 T    t         j                  d||       | j                  ||      S )Nz%Making request for %s with params: %s)loggerdebug_send_request)r3   r    request_dicts      r#   make_requestzEndpoint.make_requestq   s,    3	

 !!,@@r%   c                 J   t        |      }|rt        |j                  |j                  g      |_        |j
                  j                  j                         }d| d|j                   }| j                  j                  |||j                         | j                  |      }|S )Nzrequest-created..)requestr   )r   anyr   r   stream_outputservice_model
service_id	hyphenizer   r+   emitprepare_request)r3   paramsr    rG   rK   
event_nameprepared_requests          r#   create_requestzEndpoint.create_requesty   s    '/$'#88#;;%G! )66AAKKMJ+J<q9M9M8NOJ$$.33 % 
  //8r%   c                 ~    |j                         D ]*  \  }}t        |t              s|j                  d      ||<   , y )Nzutf-8)items
isinstancestrencode)r3   r   keyvalues       r#   _encode_headerszEndpoint._encode_headers   s7    !--/ 	5JC%%$||G4	5r%   c                 X    | j                  |j                         |j                         S r)   )rZ   r   preparer3   rG   s     r#   rN   zEndpoint.prepare_request   s!    W__-  r%   c                     t               }t        j                  j                  |d      }||z
  }|t        j                  |      z   |z   }|j	                  d      S )Nz%a, %d %b %Y %H:%M:%S %Z)secondsz%Y%m%dT%H%M%SZ)r   datetimestrptime	timedeltastrftime)r3   response_received_timestampdate_headerread_timeoutlocal_timestampdate_conversionestimated_skewttls           r#   _calculate_ttlzEndpoint._calculate_ttl   sj     /0"++443
 )+FF  67 	
 ||,--r%   c                     |d   j                   j                  d      }|j                  d      }|r%|s"	 t               }| j                  |||      |d<   y y y # t        $ r t
        j                  dd       Y y w xY w)Nr   Datehas_streaming_inputrj   z9Exception received when updating retries context with TTLTexc_info)r   r   r   rk   	Exceptionr@   rA   )r3   retries_contextrf   success_responseresponse_date_headerrn   rd   s          r#   _set_ttlzEndpoint._set_ttl   s    /2::>>vF-112GH(;.B.D+)-)<)</( *& )<  O!  s    A  A;:A;c                     |j                  di       }||d<   d|vr t        t        j                               |d<   |r#|d   j                  }| j                  |||       y y )Nretriesattemptzinvocation-idclient_config)
setdefaultrV   uuiduuid4rf   ru   )r3   r   rx   rs   rr   rf   s         r#   _update_retries_contextz Endpoint._update_retries_context   sd    !,,Y;%,	"/1/24::</@OO,"?3@@LMM/<9IJ r%   c                    d}|d   }| j                  ||       | j                  ||      }| j                  |||      \  }}| j                  |||||      rf|dz  }| j                  |||       |j	                          | j                  ||      }| j                  |||      \  }}| j                  |||||      rf|d|d   v r|dz
  }||d   d   d<   |||S )N   r   ResponseMetadataRetryAttempts)r}   rR   _get_response_needs_retryreset_stream)	r3   rC   r    attemptsr   rG   rs   	exceptiontotal_retriess	            r#   rB   zEndpoint._send_request   s5   y)$$Wh7%%lOD&*&8&8_g'
#) 
 MH(((<LM
   ")),HG*.*<*<'+'i! 
( ("&6q&99 %qLM Q 23OD  O##r%   c                    | j                  |||      \  }}d d ||d}||\  }}||d<   t        ||      |d<   |j                  j                  j	                         }	 | j
                  j                  d|	 d|j                   fi | ||fS )N)r!   parsed_responser   r   r   r!   zresponse-received.rF   )_do_get_responser$   rJ   rK   rL   r+   rM   r   )
r3   rG   r    r   rs   r   kwargs_to_emitr   r   rK   s
             r#   r   zEndpoint._get_response   s     '+&;&;_g'
#) "#"	
 '-=*M?0?N,-.F/N?+ %22==GGI
    Ao.B.B-CD	
	
  **r%   c           	      t   	 t         j                  d|       t        j                  d|j                  |j
                  |j                  |j                  |j                  d       |j                  j                  j                         }d| d|j                   }| j                  j                  ||      }t        |      }|| j!                  |      }t'        ||      }	t)        ||	||       |	j+                         }
|j,                  |
d
<   t        j                  d|
       |j                  j.                  }i }| j                  j                  d| d|j                   ||	|       | j0                  j3                  |      }|j5                  |	|j6                        }|j9                  |       |j:                  dk\  r| j=                  |	|||       t        j                  d|       ||fd fS # t"        $ r}d |fcY d }~S d }~wt$        $ r%}t         j                  dd	       d |fcY d }~S d }~ww xY w)NzSending http request: %sHTTP_REQUEST)methodr   	streamingurlr   zbefore-send.rF   )rG   z-Exception received when sending HTTP request.Tro   r   HTTP_RESPONSEzbefore-parse.)r    r!   customized_response_dictr   PARSED_RESPONSE)r@   rA   history_recorderrecordr   r   rn   r   r   rJ   rK   rL   r   r+   rM   r	   _sendr   rq   r$   r
   copyr   resolved_protocolr1   create_parserparseoutput_shapeupdater   _add_modeled_error_fields)r3   rG   r    r   rK   rP   	responsesr   er!   http_response_record_dictprotocolr   parserr   s                  r#   r   zEndpoint._do_get_response  sD   	LL3W=##%nn&!0!D!D";;#LL	 )66AAKKMJ'
|1_5I5I4JKJ++00W0MI3I>M$ $

7 3 1?
 			
 %2$6$6$8!00 	"+. 	1JK"00BB#%   J<q)=)=(>?+'%=	 	! 	
 ..<<XF ,,?77
 	78 $$+**	 	 1?C/55e  	!9 	LL?$   !9		s0   CG4 4	H7=H H7H7H2,H72H7c                     |j                  di       j                  d      }|y |j                  }|j                  |      }|y |j                  ||      }|j	                  |       y )NErrorCode)r   rJ   shape_for_error_coder   r   )	r3   r!   r   r    r   
error_coderJ   error_shapemodeled_parses	            r#   r   z"Endpoint._add_modeled_error_fieldsL  sl     %(("599&A
'55#88D]K@}-r%   c           	      .   |j                   j                  j                         }d| d|j                   }| j                  j                  ||| ||||      }t        |      }	|	|	du ryt        j                  d|	       t        j                  |	       y)Nzneeds-retry.rF   )responseendpoint	operationr   caught_exceptionrC   Fz3Response received to retry, sleeping for %s secondsT)rJ   rK   rL   r   r+   rM   r	   r@   rA   timesleep)
r3   r   r    rC   r   r   rK   rP   r   handler_responses
             r#   r   zEndpoint._needs_retry^  s     %22==GGI
#J<q1E1E0FG
'',,%-% - 
	 39=#'75'@ LLE  JJ'(r%   c                 8    | j                   j                  |      S r)   )r2   sendr]   s     r#   r   zEndpoint._send~  s      %%g..r%   )NNr)   )__name__
__module____qualname____doc__r7   r<   r>   rD   rR   rZ   rN   rk   ru   r}   rB   r   r   r   r   r    r%   r#   r'   r'   M   sm     !%1&7"A &5!."K'$R+8E6N.. @/r%   r'   c            	       >    e Zd Zd Zddeeeddddf	dZd Zd Z	d Z
y)EndpointCreatorc                     || _         y r)   )r+   )r3   r5   s     r#   r7   zEndpointCreator.__init__  s
    +r%   Nc           	      &   t        |      st        |      st        d|       |	| j                  |      }	|j                  }t
        j                  d||        |||	| j                  |      ||
||      }t        ||| j                  ||      S )NzInvalid endpoint: zSetting %s timeout as %s)timeoutproxiesverifymax_pool_connectionssocket_optionsclient_certproxies_config)r4   r5   r6   r2   )
r   r   
ValueError_get_proxiesr4   r@   rA   _get_verify_valuer'   r+   )r3   rJ   region_nameendpoint_urlr   r6   r   r   http_session_clsr   r   r   r   r4   r2   s                  r#   create_endpointzEndpointCreator.create_endpoint  s     %
,\:1,@AA?''5G'77/'J'))&1!5)#)
 +--$;%
 	
r%   c                     t        |      S r)   )r   )r3   r   s     r#   r   zEndpointCreator._get_proxies  s     #3''r%   c                     || j                  |      S | j                  t        j                  j                  dd            S )NREQUESTS_CA_BUNDLET)_validate_verify_valueosenvironr   r3   r   s     r#   r   z!EndpointCreator._get_verify_value  sC     ..v66 **JJNN/6
 	
r%   c                 ^    t        |t              r|j                         st        d      |S )NzInvalid CA bundle: the configured value (ca_bundle, AWS_CA_BUNDLE, REQUESTS_CA_BUNDLE, or verify) resolved to an empty or whitespace-only string. Provide a valid path to a CA bundle file.)	error_msg)rU   rV   stripr   r   s     r#   r   z&EndpointCreator._validate_verify_value  s-    fc"6<<>$0  r%   )r   r   r   r7   DEFAULT_TIMEOUTMAX_POOL_CONNECTIONSr   r   r   r   r   r   r%   r#   r   r     s9    ,  $1')
V(


r%   r   )&r`   loggingr   r-   r   r{   botocorer   botocore.awsrequestr   botocore.compatr   botocore.exceptionsr   r   botocore.historyr   botocore.hooksr	   botocore.httpchecksumr
   botocore.httpsessionr   botocore.responser   botocore.utilsr   r   r   	getLoggerr   r@   r   r   r   r$   r'   r   r   r%   r#   <module>r      s      	     5 0 C 8 2 6 / +  
		8	$.0  Dr/ r/j	M Mr%   