B \ 1@sddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z mZddlmZddlmZdd lmZdd lmZeeZeZd Zd Zd dZGdddeZGdddeZ dS)N)six)create_request_object)HTTPClientError)URLLib3Session)is_valid_endpoint_urlget_environ_proxies)first_non_none_response)get_global_history_recorder) StreamingBody)parsers< 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_dictlengthr5/tmp/pip-build-uw_ogi45/botocore/botocore/endpoint.pyconvert_to_response_dict&s    rc@sneZdZdZdddZddZddZdd d Zd d Zd dZ ddZ ddZ ddZ dddZ ddZdS)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_lockr ZResponseParserFactory_response_parser_factory http_sessionr)selfr#endpoint_prefix event_emitterresponse_parser_factoryr(rrr__init__Ss  zEndpoint.__init__cCsd|j|jfS)Nz%s(%s))r!r#)r)rrr__repr__`szEndpoint.__repr__cCstd|||||S)Nz%Making request for %s with params: %s)loggerdebug _send_request)r)r request_dictrrr make_requestcszEndpoint.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_modelr4 hyphenizeformatrr"emitprepare_request)r)paramsrr5r4 event_nameprepared_requestrrrcreate_requesths      zEndpoint.create_requestcCs4x.|D]"\}}t|tjr |d||<q WdS)Nzutf-8)items isinstancer text_typeencode)r)rkeyvaluerrr_encode_headersxs zEndpoint._encode_headerscCs||j|S)N)rFrprepare)r)r5rrrr;~s zEndpoint.prepare_requestc Csd}|||}|d}||||\}}xD||||||rn|d7}||||}||||\}}q,W|dk rd|dkr|d}||ddd<|dk r|n|SdS)NrZResponseMetadataZ RetryAttempts)r? _get_response _needs_retryZ reset_stream) r)r2rattemptsr5rsuccess_response exceptionZ total_retriesrrrr1s(   zEndpoint._send_requestc Csr|||\}}dd||d}|dk rD|\}}||d<t|||d<|jj} |jjd| |jff|||fS)N)rparsed_responserrMrNrzresponse-received.%s.%s)_do_get_responserr7r4r8r"r:r) r)r5rrrLrMZkwargs_to_emitrrNr4rrrrIs    zEndpoint._get_responsec Cs4yvtd|td|j|j|j|j|jd|j j }d||j f}|j j||d}t|}|dkrt||}WnXtk r}zd|fSd}~XYn4tk r}ztjdddd|fSd}~XYnXt||}|} |j| d <td | |jd } |j| } | ||j} td | || fdfS) NzSending http request: %sZ HTTP_REQUEST)methodr streamingurlrzbefore-send.%s.%s)r5z-Exception received when sending HTTP request.T)exc_inforQZ HTTP_RESPONSEprotocolZPARSED_RESPONSE)r/r0history_recorderrecordrPrZhas_streaming_inputrRrr7r4r8rr"r:r_sendr Exceptionrcopyrmetadatar' create_parserparseZ output_shape) r)r5rr4r= responsesrerZhttp_response_record_dictrTparserrNrrrrOs<          zEndpoint._do_get_responsec Csf|jj}d||jf}|jj|||||||d}t|} | dkrHdStd| t | dSdS)Nzneeds-retry.%s.%s)responseZendpointZ operationrKcaught_exceptionr2Fz3Response received to retry, sleeping for %s secondsT) r7r4r8rr"r:rr/r0timesleep) r)rKrr2r`rar4r=r]Zhandler_responserrrrJs    zEndpoint._needs_retrycCs |j|S)N)r(send)r)r5rrrrWszEndpoint._send)NN)N)NN)__name__ __module__ __qualname____doc__r-r.r3r?rFr;r1rIrOrJrWrrrrr Is   & r c@s>eZdZddZddeeedddfddZddZdd Z dS) EndpointCreatorcCs ||_dS)N)r")r)r+rrrr-szEndpointCreator.__init__Nc Csht|std|| dkr&||} |j} td| |||| |||| | d} t|| |j|| dS)NzInvalid endpoint: %szSetting %s timeout as %s)timeoutproxiesverifymax_pool_connectionssocket_options client_cert)r*r+r,r() r ValueError _get_proxiesr*r/r0_get_verify_valuer r")r)r7Z region_nameZ endpoint_urlrlr,rjrmZhttp_session_clsrkrnror*r(rrrcreate_endpoints&  zEndpointCreator.create_endpointcCst|S)N)r)r)rRrrrrqszEndpointCreator._get_proxiescCs|dk r |StjddS)NREQUESTS_CA_BUNDLET)osenvironr)r)rlrrrrr!sz!EndpointCreator._get_verify_value) rerfrgr-DEFAULT_TIMEOUTMAX_POOL_CONNECTIONSrrsrqrrrrrrris ri)!ruloggingrbr$Zbotocore.vendoredrZbotocore.awsrequestrZbotocore.exceptionsrZbotocore.httpsessionrZbotocore.utilsrrZbotocore.hooksrZbotocore.historyr Zbotocore.responser Zbotocorer getLoggerrer/rUrwrxrobjectr rirrrrs(         #/