B ݁[-@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_dictlengthrR/Users/kashii/Desktop/Projects/Workshops/worker-safety/lambda/botocore/endpoint.pyconvert_to_response_dict&s    rc@sfeZdZdZdddZddZddZdd d Zd d Zd dZ ddZ ddZ dddZ ddZ dS)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 ResponseParserFactory_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) ranyrr stream_output service_modelr5 hyphenizeformatrr"emitprepare_request)r*paramsrr6r5 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)rHrprepare)r*r6rrrr=~s zEndpoint.prepare_requestcCsd}|||}||||\}}xD||||||rf|d7}||||}||||\}}q$W|dk rd|dkr|d}||ddd<|dk r|n|SdS)NResponseMetadata RetryAttempts)rA _get_response _needs_retry reset_stream)r*r3rattemptsr6Zsuccess_response exceptionZ total_retriesrrrr2s&   zEndpoint._send_requestc 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)r6z-Exception received when sending HTTP request.T)exc_inforSZ HTTP_RESPONSEprotocolZPARSED_RESPONSE)r0r1history_recorderrecordrRrhas_streaming_inputrTrr9r5r:rr"r<r_sendr Exceptionrcopyrmetadatar( create_parserparse output_shape)r*r6rrPr5r? responsesrerZhttp_response_record_dictrVparserparsed_responserrrrMs<          zEndpoint._get_responsec Csf|jj}d||jf}|jj|||||||d}t|} | dkrHdStd| t | dSdS)Nzneeds-retry.%s.%s)responseendpoint operationrPcaught_exceptionr3Fz3Response received to retry, sleeping for %s secondsT) r9r5r:rr"r<rr0r1timesleep) r*rPrr3rerhr5r?raZhandler_responserrrrNs    zEndpoint._needs_retrycCs |j|S)N)r)send)r*r6rrrrZszEndpoint._send)NN)N)NN)__name__ __module__ __qualname____doc__r.r/r4rArHr=r2rMrNrZrrrrr 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+r0r1_get_verify_valuer r")r*r9 region_name endpoint_urlrsr-rqrtZhttp_session_clsrrrurvr+r)rrrcreate_endpoints&  zEndpointCreator.create_endpointcCst|S)N)r)r*rTrrrrxszEndpointCreator._get_proxiescCs|dk r |StjddS)NREQUESTS_CA_BUNDLET)osenvironr)r*rsrrrry sz!EndpointCreator._get_verify_value) rlrmrnr.DEFAULT_TIMEOUTMAX_POOL_CONNECTIONSrr|rxryrrrrrps rp)!r~loggingrir$botocore.vendoredrbotocore.awsrequestrbotocore.exceptionsrbotocore.httpsessionrbotocore.utilsrrbotocore.hooksrbotocore.historyr Zbotocore.responser botocorer getLoggerrlr0rWrrrobjectr rprrrrs(         #