o ?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< cCsz|j|jd|jid}|ddkr|j|d<|S|jr"|j|d<|S|jr6|dd}t|j||d<|S|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_codecontextr,bodyrzcontent-length) rrnamecontenthas_event_stream_outputrawhas_streaming_outputgetr ) http_responseoperation_model response_dictlengthrl/private/var/folders/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/botocore/endpoint.pyconvert_to_response_dict*s"    r!c@seZdZdZ  d#ddZddZddZd d Zd$d d Zd dZ ddZ ddZ ddZ d$ddZ ddZddZddZddZ  d#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. NcCsR||_||_||_t|_|durt}||_||_ |j dur't |_ dSdSN) _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|jdSr#)r+closer3rrr r5nszEndpoint.closecCstd|||||S)Nz%Making request for %s with params: %s)loggerdebug _send_request)r,r request_dictrrr make_requestqs  zEndpoint.make_requestcCs\t|}|r't|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_modelr; hyphenizeformatrr%emitprepare_request)r,paramsrr<r; event_nameprepared_requestrrr create_requestys$  zEndpoint.create_requestcCs.|D]\}}t|tr|d||<qdS)Nzutf-8)items isinstancestrencode)r,rkeyvaluerrr _encode_headerss  zEndpoint._encode_headerscCs||j|Sr#)rMrpreparer,r<rrr rBs 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_ttlcCsp|djd}|d}|r4|s6ztj}|||||d<WdSty3tjdddYdSwdSdS)NrDatehas_streaming_inputrXz9Exception received when updating retries context with TTLTexc_info)rrrQrRrY Exceptionr6r7)r,retries_contextrWsuccess_responseZresponse_date_headerr[rVrrr _set_ttls"    zEndpoint._set_ttlcCsP|di}||d<d|vrtt|d<|r&|dj}||||dSdS)Nretriesattemptz invocation-idZ client_config) setdefaultrIuuiduuid4rWra)r,rrcr`r_rWrrr _update_retries_contexts  z Endpoint._update_retries_contextc Csd}|d}||||||}||||\}}||||||rK|d7}||||||||}||||\}}||||||s$|durad|dvra|d}||ddd<|durg||S)NrZResponseMetadataZ RetryAttempts)rgrF _get_response _needs_retryZ reset_stream) r,r9rattemptsrr<r` exceptionZ total_retriesrrr r8sP     zEndpoint._send_requestc Cs|||||\}}dd||d}|dur#|\}}||d<t|||d<|jj} |jjd| d|jfi|||fS)N)rparsed_responserrlrmrzresponse-received..)_do_get_responser!r>r;r?r%rAr) r,r<rrr`rlZkwargs_to_emitrrmr;rrr ris* zEndpoint._get_responsec Cslz=td|td|j|j|j|j|jd|j j }d|d|j }|j j||d}t|}|dur<||}Wn2tyS}z d|fWYd}~Sd}~wtyo}ztjddd d|fWYd}~Sd}~wwt||} t|| ||| } |j| d <td | |jd } |j| } | | |j} |jd kr|| | || td| || fdfS)NzSending http request: %sZ HTTP_REQUEST)methodr streamingurlrz before-send.rn)r<z-Exception received when sending HTTP request.Tr\rqZ HTTP_RESPONSEprotocolrZPARSED_RESPONSE)r6r7history_recorderrecordrprr[rrrr>r;r?rr%rAr_sendrr^r!rcopyrmetadatar*Z create_parserparseZ output_shaper_add_modeled_error_fields)r,r<rrr;rD responsesrerZhttp_response_record_dictrsparserrmrrr rosr         zEndpoint._do_get_responsec CsT|did}|durdS|j}||}|durdS|||}||dS)NErrorZCode)rr>Zshape_for_error_coderyupdate) r,rrmrr}Z error_coder>Z error_shapeZ modeled_parserrr rzFs  z"Endpoint._add_modeled_error_fieldsc Csf|jj}d|d|j}|jj|||||||d}t|} | dur&dStd| t | dS)Nz needs-retry.rn)responseZendpointZ operationrkcaught_exceptionr9Fz3Response received to retry, sleeping for %s secondsT) r>r;r?rr%rArr6r7timesleep) r,rkrr9rrr;rDr{Zhandler_responserrr rjXs(   zEndpoint._needs_retrycCs |j|Sr#)r+sendrOrrr rvxs zEndpoint._send)NNr#)__name__ __module__ __qualname____doc__r0r4r5r:rFrMrBrYrargr8rirorzrjrvrrrr r"Ms,    )? r"c @s@eZdZddZddeeeddddf ddZddZdd Z dS) EndpointCreatorcCs ||_dSr#)r%)r,r.rrr r0}s zEndpointCreator.__init__Nc  Csrt|st|std|| dur||} |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-r6r7_get_verify_valuer"r%)r,r>Z region_nameZ endpoint_urlrr/rrZhttp_session_clsrrrrr-r+rrr create_endpoints4   zEndpointCreator.create_endpointcCst|Sr#)r )r,rrrrr rszEndpointCreator._get_proxiescCs|dur|StjddS)NREQUESTS_CA_BUNDLET)osenvironr)r,rrrr rsz!EndpointCreator._get_verify_value) rrrr0DEFAULT_TIMEOUTMAX_POOL_CONNECTIONSrrrrrrrr r|s + r)#rQloggingrr'rreZbotocorerZbotocore.awsrequestrZbotocore.exceptionsrZbotocore.historyrZbotocore.hooksrZbotocore.httpchecksumrZbotocore.httpsessionrZbotocore.responser Zbotocore.utilsr r r getLoggerrr6rtrrr!r"rrrrr s0         #1