
    Pe9@                        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j4                  e      Z e       ZdZdZd Z  G d d      Z! G d d      Z"y)    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                 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 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lengths       3/usr/lib/python3/dist-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_factoryr0   s         r!   __init__zEndpoint.__init__X   sj     !0+	^^%
"*&-&C&C&E#(?%($ . 0D %r#   c                 :    | j                    d| j                   dS )N())r(   r*   r1   s    r!   __repr__zEndpoint.__repr__k   s     ''($))A66r#   c                 8    | j                   j                          y r'   )r0   closer9   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)r1   r   request_dicts      r!   make_requestzEndpoint.make_requestq   s,    3	

 !!,@@r#   c                 `   t        |      }|rt        |j                  |j                  g      |_        |j
                  j                  j                         }dj                  ||j                        }| j                  j                  |||j                         | j                  |      }|S )Nz&request-created.{service_id}.{op_name})
service_idop_name)requestr   )r   anyr   r   stream_outputservice_modelrD   	hyphenizeformatr   r)   emitprepare_request)r1   paramsr   rF   rD   
event_nameprepared_requests          r!   create_requestzEndpoint.create_requesty   s    '/$'#88#;;%G! )66AAKKMJAHH%/C/C I J $$.33 % 
  //8r#   c                 ~    |j                         D ]*  \  }}t        |t              s|j                  d      ||<   , y )Nzutf-8)items
isinstancestrencode)r1   r   keyvalues       r!   _encode_headerszEndpoint._encode_headers   s7    !--/ 	5JC%%$||G4	5r#   c                 X    | j                  |j                         |j                         S r'   )rY   r   preparer1   rF   s     r!   rM   zEndpoint.prepare_request   s!    W__-  r#   c                     t         j                   j                         }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)datetimeutcnowstrptime	timedeltastrftime)r1   response_received_timestampdate_headerread_timeoutlocal_timestampdate_conversionestimated_skewttls           r!   _calculate_ttlzEndpoint._calculate_ttl   sv     #++224"++443
 )+FF  67 	
 ||,--r#   c                 $   |d   j                   j                  d      }|j                  d      }|r9|s6	 t        j                  j                         }| 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_   r`   rk   	Exceptionr>   r?   )r1   retries_contextrf   success_responseresponse_date_headerrn   rd   s          r!   _set_ttlzEndpoint._set_ttl   s    /2::>>vF-112GH(;.6.?.?.F.F.H+)-)<)</( *& )<  O!  s   4A, , BB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)
setdefaultrU   uuiduuid4rf   ru   )r1   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}   rQ   _get_response_needs_retryreset_stream)	r1   rA   r   attemptsr   rF   rs   	exceptiontotal_retriess	            r!   r@   zEndpoint._send_request   s:   y)$$Wh7%%lOD&*&8&8_g'
#) 
 MH(((<LM
   ")),HG*.*<*<'+'i! 
( ("&6q&99 %qLM  Q 23  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..)_do_get_responser"   rI   rD   rJ   r)   rL   r   )
r1   rF   r   r   rs   r   kwargs_to_emitr   r   rD   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         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.                  d   }| j0                  j3                  |      }|j5                  |	|j6                        }|j8                  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.r   )rF   z-Exception received when sending HTTP request.Tro   r   HTTP_RESPONSEprotocolr   PARSED_RESPONSE)r>   r?   history_recorderrecordr   r   rn   r   r   rI   rD   rJ   r   r)   rL   r   _sendr   rq   r"   r   copyr   metadatar/   create_parserparseoutput_shaper   _add_modeled_error_fields)r1   rF   r   r   rD   rO   	responsesr   er   http_response_record_dictr   parserr   s                 r!   r   zEndpoint._do_get_response  s   	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"++J7..<<XF ,,?77
 $$+**	 	 1?C/55U  	!9 	LL?$   !9		s0   CF+ +	G.4F=7G.=G.	G)#G.)G.c                     |j                  di       j                  d      }|y |j                  }|j                  |      }|y |j                  ||      }|j	                  |       y )NErrorCode)r   rI   shape_for_error_coder   update)	r1   r   r   r   r   
error_coderI   error_shapemodeled_parses	            r!   r   z"Endpoint._add_modeled_error_fieldsF  sl     %(("599&A
'55#88D]K@}-r#   c           	      &   |j                   j                  j                         }d| d|j                   }| j                  j                  ||| ||||      }t        |      }	|	yt        j                  d|	       t        j                  |	       y)Nzneeds-retry.r   )responseendpoint	operationr   caught_exceptionrA   Fz3Response received to retry, sleeping for %s secondsT)rI   rD   rJ   r   r)   rL   r   r>   r?   timesleep)
r1   r   r   rA   r   r   rD   rO   r   handler_responses
             r!   r   zEndpoint._needs_retryX  s     %22==GGI
#J<q1E1E0FG
'',,%-% - 
	 39=# LLE  JJ'(r#   c                 8    | j                   j                  |      S r'   )r0   sendr\   s     r!   r   zEndpoint._sendx  s      %%g..r#   )NNr'   )__name__
__module____qualname____doc__r5   r:   r<   rB   rQ   rY   rM   rk   ru   r}   r@   r   r   r   r   r    r#   r!   r%   r%   M   sl     !%1&7"A *5!."K'$R+8=6~.. @/r#   r%   c            	       8    e Zd Zd Zddeeeddddf	dZd Zd Z	y)EndpointCreatorc                     || _         y r'   )r)   )r1   r3   s     r!   r5   zEndpointCreator.__init__}  s
    +r#   Nc           	      &   t        |      st        |      st        d|z        |	| j                  |      }	|j                  }t
        j                  d||        |||	| j                  |      ||
||      }t        ||| j                  ||      S )NzInvalid endpoint: %szSetting %s timeout as %s)timeoutproxiesverifymax_pool_connectionssocket_optionsclient_certproxies_config)r2   r3   r4   r0   )
r   r   
ValueError_get_proxiesr2   r>   r?   _get_verify_valuer%   r)   )r1   rI   region_nameendpoint_urlr   r4   r   r   http_session_clsr   r   r   r   r2   r0   s                  r!   create_endpointzEndpointCreator.create_endpoint  s     %
,\:3lBCC?''5G'77/'J'))&1!5)#)
 +--$;%
 	
r#   c                     t        |      S r'   )r   )r1   r   s     r!   r   zEndpointCreator._get_proxies  s     #3''r#   c                 J    ||S t         j                  j                  dd      S )NREQUESTS_CA_BUNDLET)osenvironr   )r1   r   s     r!   r   z!EndpointCreator._get_verify_value  s'     M zz~~2D99r#   )
r   r   r   r5   DEFAULT_TIMEOUTMAX_POOL_CONNECTIONSr	   r   r   r   r   r#   r!   r   r   |  s4    ,  $1')
V(
:r#   r   )#r_   loggingr   r+   r   r{   botocorer   botocore.awsrequestr   botocore.exceptionsr   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 / 8 2 6 / +  
		8	$.0   Fl/ l/^	?: ?:r#   