o YZa5@sddlZddlZddlZddlZddlZddlmZddlmZddl m Z ddl m Z m Z mZddlmZddlmZddlmZdd lmZeeZeZd Zd Zd d ZGdddeZGdddeZ dS)N)create_request_object)HTTPClientError)URLLib3Session)is_valid_endpoint_urlis_valid_ipv6_endpoint_urlget_environ_proxies)first_non_none_response)get_global_history_recorder) StreamingBody)parsers< 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_dictlengthr3/usr/lib/python3/dist-packages/botocore/endpoint.pyconvert_to_response_dict(s"    r c@szeZdZdZ dddZddZddZdd d Zd d Zd dZ ddZ ddZ ddZ ddZ dddZddZdS)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_lockr ResponseParserFactory_response_parser_factory http_sessionr)selfr%endpoint_prefix event_emitterresponse_parser_factoryr+rrr__init__Us   zEndpoint.__init__cCsd|j|jfS)Nz%s(%s))r#r%)r,rrr__repr__bszEndpoint.__repr__cCstd|||||S)Nz%Making request for %s with params: %s)loggerdebug _send_request)r,r request_dictrrr make_requestes 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_idop_name)requestr) ranyrr stream_output service_modelr7 hyphenizeformatrr$emitprepare_request)r,paramsrr9r7 event_nameprepared_requestrrrcreate_requestjs    zEndpoint.create_requestcCs0|D]\}}t|tjr|d||<qdS)Nzutf-8)items isinstancesix text_typeencode)r,rkeyvaluerrr_encode_headerszs  zEndpoint._encode_headerscCs||j|Sr")rLrpreparer,r9rrrr@s zEndpoint.prepare_requestc Csd}|||}|d}||||\}}||||||r>|d7}||||}||||\}}||||||s|durTd|dvrT|d}||ddd<|durZ||S)NrResponseMetadata RetryAttempts)rD _get_response _needs_retry reset_stream) r,r5rattemptsr9rsuccess_response exception total_retriesrrrr4s6    zEndpoint._send_requestc Csv|||\}}dd||d}|dur"|\}}||d<t|||d<|jj} |jjd| |jffi|||fS)N)rparsed_responserrWrYrzresponse-received.%s.%s)_do_get_responser r<r7r=r$r?r) r,r9rrrVrWkwargs_to_emitrrYr7rrrrRs. zEndpoint._get_responsec CsZz;td|td|j|j|j|j|jd|j j }d||j f}|j j||d}t|}|dur:||}Wn2tyQ}z d|fWYd}~Sd}~wtym}ztjdddd|fWYd}~Sd}~wwt||}|} |j| d <td | |jd } |j| } | ||j} |jd kr||| || td | || fdfS)NzSending http request: %s HTTP_REQUEST)methodr streamingurlrzbefore-send.%s.%s)r9z-Exception received when sending HTTP request.T)exc_infor^ HTTP_RESPONSEprotocolrPARSED_RESPONSE)r2r3history_recorderrecordr]rhas_streaming_inputr_rr<r7r=rr$r?r_sendr Exceptionr copyrmetadatar* create_parserparse output_shaper_add_modeled_error_fields) r,r9rr7rB responsesrerhttp_response_record_dictrbparserrYrrrrZsV          zEndpoint._do_get_responsec CsT|did}|durdS|j}||}|durdS|||}||dS)NErrorCode)rr<shape_for_error_coderlupdate) r,rrYrrr error_coder< error_shape modeled_parserrrrns  z"Endpoint._add_modeled_error_fieldsc Csb|jj}d||jf}|jj|||||||d}t|} | dur$dStd| t | dS)Nzneeds-retry.%s.%s)responseendpoint operationrUcaught_exceptionr5Fz3Response received to retry, sleeping for %s secondsT) r<r7r=rr$r?rr2r3timesleep) r,rUrr5rzr}r7rBrohandler_responserrrrSs$  zEndpoint._needs_retrycCs |j|Sr")r+sendrNrrrrg s zEndpoint._send)NNr")__name__ __module__ __qualname____doc__r0r1r6rDrLr@r4rRrZrnrSrgrrrrr!Ks    / r!c @s@eZdZddZddeeeddddf ddZddZdd Z dS) EndpointCreatorcCs ||_dSr")r$)r,r.rrrr0s 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+) rr ValueError _get_proxiesr-r2r3_get_verify_valuer!r$)r,r< region_name endpoint_urlrr/rrhttp_session_clsrrrrr-r+rrrcreate_endpoints2   zEndpointCreator.create_endpointcCst|Sr")r)r,r_rrrr9szEndpointCreator._get_proxiescCs|dur|StjddS)NREQUESTS_CA_BUNDLET)osenvironr)r,rrrrr>sz!EndpointCreator._get_verify_value) rrrr0DEFAULT_TIMEOUTMAX_POOL_CONNECTIONSrrrrrrrrrs $ r)!rloggingr~r&rGbotocore.awsrequestrbotocore.exceptionsrbotocore.httpsessionrbotocore.utilsrrrbotocore.hooksrbotocore.historyr botocore.responser botocorer getLoggerrr2rdrrr objectr!rrrrrs*        #G