B ㊇c9@@sddlZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z ddlmZddlmZddlmZdd lmZdd lmZmZmZeeZe Zd Zd Zd dZ GdddZ!GdddZ"dS)N)parsers)create_request_object)HTTPClientError)get_global_history_recorder)first_non_none_response)handle_checksum_body)URLLib3Session) StreamingBody)get_environ_proxiesis_valid_endpoint_urlis_valid_ipv6_endpoint_url< cCst|j|jd|jid}|ddkr.|j|d<nB|jr@|j|d<n0|jrf|dd}t|j||d<n |j|d<|S)aConvert 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_codecontextri,bodyrzcontent-length) rrnamecontenthas_event_stream_outputrawhas_streaming_outputgetr ) http_responseoperation_model response_dictlengthrl/private/var/folders/8c/hx9_v10d5x38qmnzt13b7b8j1k3n5b/T/pip-target-x6xd5gna/lib/python/botocore/endpoint.pyconvert_to_response_dict*s    r c@seZdZdZd#ddZddZddZd d Zd$d d Zd dZ ddZ ddZ ddZ d%ddZ ddZddZddZddZd&dd Zd!d"ZdS)'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. NcCsN||_||_||_t|_|dkr,t}||_||_ |j dkrJt |_ dS)N) _endpoint_prefix_event_emitterhost threadingLock_lockrZResponseParserFactory_response_parser_factory http_sessionr)selfr$endpoint_prefix event_emitterresponse_parser_factoryr)rrr__init__Xs  zEndpoint.__init__cCs|jd|jdS)N())r"r$)r*rrr__repr__kszEndpoint.__repr__cCs|jdS)N)r)close)r*rrrr2nszEndpoint.closecCstd|||||S)Nz%Making request for %s with params: %s)loggerdebug _send_request)r*r request_dictrrr make_requestqs zEndpoint.make_requestcCs\t|}|rNt|j|jg|_|jj}dj||j d}|j j |||j d| |}|S)Nz&request-created.{service_id}.{op_name}) service_idZop_name)requestr) ranyrrZ stream_output service_modelr8 hyphenizeformatrr#emitprepare_request)r*paramsrr9r8 event_nameprepared_requestrrrcreate_requestys     zEndpoint.create_requestcCs2x,|D] \}}t|tr |d||<q WdS)Nzutf-8)items isinstancestrencode)r*rkeyvaluerrr_encode_headerss zEndpoint._encode_headerscCs||j|S)N)rJrprepare)r*r9rrrr?s zEndpoint.prepare_requestcCs>tj}tj|d}||}|tj|d|}|dS)Nz%a, %d %b %Y %H:%M:%S %Z)secondsz%Y%m%dT%H%M%SZ)datetimeutcnowstrptime timedeltastrftime)r*response_received_timestampZ date_header read_timeoutZlocal_timestampZdate_conversionZestimated_skewttlrrr_calculate_ttls  zEndpoint._calculate_ttlcCsj|djd}|d}|rf|sfy tj}|||||d<Wn"tk rdtjdddYnXdS)NrDatehas_streaming_inputrTz9Exception received when updating retries context with TTLT)exc_info)rrrMrNrU Exceptionr3r4)r*retries_contextrSsuccess_responseZresponse_date_headerrWrRrrr_set_ttls  zEndpoint._set_ttlcCsL|di}||d<d|kr,tt|d<|rH|dj}||||dS)Nretriesattemptz invocation-idZ client_config) setdefaultrFuuiduuid4rSr\)r*rr^r[rZrSrrr_update_retries_contexts  z Endpoint._update_retries_contextc Csd}|d}||||||}||||\}}xR||||||r|d7}||||||||}||||\}}q8W|dk rd|dkr|d}||ddd<|dk r|n|SdS)NrZResponseMetadataZ RetryAttempts)rbrC _get_response _needs_retryZ reset_stream) r*r6rattemptsrr9r[ exceptionZ total_retriesrrrr5s2    zEndpoint._send_requestc Csx||||\}}dd||d}|dk rF|\}}||d<t|||d<|jj} |jjd| d|jf|||fS)N)rparsed_responserrgrhrzresponse-received..)_do_get_responser r;r8r<r#r>r) r*r9rrr[rgZkwargs_to_emitrrhr8rrrrds   zEndpoint._get_responsec Csbyztd|td|j|j|j|j|jd|j j }d|d|j }|j j||d}t|}|dkrx||}WnXtk r}zd|fSd}~XYn4tk r}ztjddd d|fSd}~XYnXt||} t|| ||| } |j| d <td | |jd } |j| } | | |j} |jd krJ|| | || td| || fdfS)NzSending http request: %sZ HTTP_REQUEST)methodr streamingurlrz before-send.ri)r9z-Exception received when sending HTTP request.T)rXrlZ HTTP_RESPONSEprotocoli,ZPARSED_RESPONSE)r3r4history_recorderrecordrkrrWrmrr;r8r<rr#r>r_sendrrYr rcopyrmetadatar(Z create_parserparseZ output_shaper_add_modeled_error_fields)r*r9rrr8rA responsesrerZhttp_response_record_dictrnparserrhrrrrjsV           zEndpoint._do_get_responsec CsT|did}|dkrdS|j}||}|dkr:dS|||}||dS)NErrorZCode)rr;Zshape_for_error_codertupdate) r*rrhrrxZ error_coder;Z error_shapeZ modeled_parserrrruFs  z"Endpoint._add_modeled_error_fieldsc Csj|jj}d|d|j}|jj|||||||d}t|} | dkrLdStd| t | dSdS)Nz needs-retry.ri)responseZendpointZ operationrfcaught_exceptionr6Fz3Response received to retry, sleeping for %s secondsT) r;r8r<rr#r>rr3r4timesleep) r*rfrr6r{r|r8rArvZhandler_responserrrreXs$  zEndpoint._needs_retrycCs |j|S)N)r)send)r*r9rrrrqxszEndpoint._send)NN)N)N)NN)__name__ __module__ __qualname____doc__r.r1r2r7rCrJr?rUr\rbr5rdrjrurerqrrrrr!Ms&    )? r!c @s@eZdZddZddeeeddddf ddZddZdd Z dS) EndpointCreatorcCs ||_dS)N)r#)r*r,rrrr.}szEndpointCreator.__init__Nc  Csrt|st|std|| dkr.||} |j} td| |||| |||| | | d}t|| |j ||dS)NzInvalid endpoint: %szSetting %s timeout as %s)timeoutproxiesverifymax_pool_connectionssocket_options client_certproxies_config)r+r,r-r)) r r ValueError _get_proxiesr+r3r4_get_verify_valuer!r#)r*r;Z region_nameZ endpoint_urlrr-rrZhttp_session_clsrrrrr+r)rrrcreate_endpoints,  zEndpointCreator.create_endpointcCst|S)N)r )r*rmrrrrszEndpointCreator._get_proxiescCs|dk r |StjddS)NREQUESTS_CA_BUNDLET)osenvironr)r*rrrrrsz!EndpointCreator._get_verify_value) rrrr.DEFAULT_TIMEOUTMAX_POOL_CONNECTIONSrrrrrrrrr|s r)#rMloggingrr%r}r`ZbotocorerZbotocore.awsrequestrZbotocore.exceptionsrZbotocore.historyrZbotocore.hooksrZbotocore.httpchecksumrZbotocore.httpsessionrZbotocore.responser Zbotocore.utilsr r r getLoggerrr3rorrr r!rrrrrs.         #1