B =@Sa@sddlZddlZddlmZmZddlmZddlmZddl m Z ddl m Z ddl m Z ddlmZmZmZmZmZmZdd lmZdd lmZdd lmZdd lmZmZmZmZm Z m!Z!m"Z"m#Z#ddlmZdd lm$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*m+Z+m,Z,ddl-m.Z.ddl-m/Z/e0e1Z2e(Z3Gddde4Z5Gddde4Z6Gddde4Z7Gddde4Z8ddZ9dS)N)waiter xform_name)ClientArgsCreator)AUTH_TYPE_MAPS)prepare_request_dict)ClientMethodDocstring)PaginatorDocstring) ClientErrorDataNotFoundErrorOperationNotPageableErrorUnknownSignatureVersionError*InvalidEndpointDiscoveryConfigurationErrorUnknownFIPSEndpointError)first_non_none_response) ServiceModel) Paginator)CachedPropertyget_service_module_nameS3RegionRedirectorS3ArnParamHandlerS3EndpointSetterensure_booleanS3ControlArnParamHandlerS3ControlEndpointSetter)UNSIGNED)Config)get_global_history_recorder)EndpointDiscoveryHandlerEndpointDiscoveryManager,block_endpoint_discovery_required_operations)standard)adaptivec@seZdZdZd2ddZd3ddZd4dd Zd d Zd5d d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1ZdS)6 ClientCreatorz%Creates client objects for a service.Nc Cs:||_||_||_||_||_||_||_||_| |_dS)N) _loader_endpoint_resolver _user_agent_event_emitter_retry_handler_factory_retry_config_translator_response_parser_factory_exceptions_factory _config_store) selfloaderendpoint_resolver user_agent event_emitterZretry_handler_factoryZretry_config_translatorZresponse_parser_factoryexceptions_factory config_storer3g/private/var/folders/fg/1jzmct0d7d72tjkvm_1nhqc5sw67yj/T/pip-unpacked-wheel-ef76ia09/botocore/client.py__init__7szClientCreator.__init__Tc  Cs|jjd|d} t| |d}|||} ||| } t|j|| | jdd} | | ||||||| | }| f|}| || || || || || || || ||| |||S)Nzchoose-service-name) service_name)defaultZ signingName)service_signing_name)r&emitr_load_service_model_create_client_classClientEndpointBridger$metadataget_get_client_args_register_retries_register_s3_events_register_s3_control_events_register_endpoint_discovery0_register_lazy_block_unknown_fips_pseudo_regions)r,r6 region_name is_secure endpoint_urlverify credentials scoped_config api_version client_config responses service_modelclsendpoint_bridgeZ client_argsZservice_clientr3r3r4 create_clientIs.        zClientCreator.create_clientcCs|||}|||S)N)r:r;)r,r6rKrNr3r3r4create_client_classgs z!ClientCreator.create_client_classc Csb||}||}||d<tg}|j}|jjd|||dt|}tt |t ||}|S)N_PY_TO_OP_NAMEzcreating-client-class.%s)class_attributesZ base_classes) _create_methods_create_name_mapping BaseClient service_id hyphenizer&r9rtypestrtuple) r,r6rNrTZpy_name_to_operation_namebasesrX class_namerOr3r3r4r;ks   z"ClientCreator._create_client_classcCs"|jj|d|d}t||d}|S)Nz service-2)rK)r6)r#load_service_modelr)r,r6rKZ json_modelrNr3r3r4r:ys  z!ClientCreator._load_service_modelcCsV|jjjd}|dkr"||n0|dkr@||||n|dkrR||dS)Nmoder r!legacy)metaconfigretries_register_v2_standard_retries_register_v2_adaptive_retries_register_legacy_retries)r,client retry_moder3r3r4r@s   zClientCreator._register_retriescCs8|jjjd}d|i}|dk r(||d<tjf|dS)Ntotal_max_attemptsrh max_attempts)rbrcrdr>r register_retry_handler)r,rhrkkwargsr3r3r4res z+ClientCreator._register_v2_standard_retriescCst|dS)N)r!rl)r,rhr3r3r4rfsz+ClientCreator._register_v2_adaptive_retriesc Cs|jjj}|jjj}|}|jd}|s0dS||jjj }|j || di| di|}t d|jjj|j||}d|} |jjjd||| ddS)NZ_retryretryZ definitionsz*Registering retry handlers for service: %szretry-config-%szneeds-retry.%s) unique_id)rbrNendpoint_prefixrXrYr#Z load_data_transform_legacy_retriesrcrdr(Zbuild_retry_configr>loggerdebugr6r'Zcreate_retry_handlereventsregister) r,rhrprXZservice_event_nameZoriginal_configrdZ retry_confighandlerror3r3r4rgs&      z&ClientCreator._register_legacy_retriescCs:|dkr dS|}d|kr6|}|dd|d<|S)Nrjrk)copypop)r,rdZ copied_argsr3r3r4rqsz'ClientCreator._transform_legacy_retriescCs6|jjj}|dk r(|ddk r(|dS|dp4dS)Nr`rira)rbrcrdr>get_config_variable)r,rhr2Zclient_retriesr3r3r4_get_retry_modes  zClientCreator._get_retry_modec Cs|dk r dS|jjjdkrdS|jj}|jjj}d}|rN|jdk rN|j}n|jr`|jd}| |}|r| ||r|dk}t ||d}t |} | ||n | dtdS)NFendpoint_discovery_enabledT)Zalways_discoverzbefore-parameter-build)rbrNZendpoint_discovery_operationrtrXrYr|r+rz$_normalize_endpoint_discovery_config_requires_endpoint_discoveryrrrur) r,rhrGrcrtrXenabledZdiscovermanagerrvr3r3r4rCs(  z*ClientCreator._register_endpoint_discoverycCsPt|tr4|}|dkr"|S|dkrBt|Snt|trB|St|ddS)z?Config must either be a boolean-string or string-literal 'auto'auto)truefalse)Z config_valueN) isinstancer[lowerstriprboolr )r,rr3r3r4r}s    z2ClientCreator._normalize_endpoint_discovery_configcCs|dkr|jjjS|S)Nr)rbrNZendpoint_discovery_required)r,rhrr3r3r4r~s z*ClientCreator._requires_endpoint_discoverycsjjjrdkrdSjj}jjj}|jj||dd}|krffdd}jj d|dS)NZfipsT)Zallow_non_regionalcsjjj}t|ddS)N)rEr6)rbrNr6r)rmr6)rhrEr3r4_lazy_fips_exceptions z\ClientCreator._register_lazy_block_unknown_fips_pseudo_regions.._lazy_fips_exceptionz before-sign) rbrEr partitionrNrpr$get_available_endpointsrtru)r,rhrrpZ known_regionsrr3)rhrEr4rDs z>ClientCreator._register_lazy_block_unknown_fips_pseudo_regionscCsp|jjjdkrdSt||t|jjt|j|jj |jj j ||jj d|jj| |j||dS)Ns3)r.region s3_configrGr)rbrNr6rrurrtrr$rErcrr!_set_s3_presign_signature_version)r,rhrPrGrLrJr3r3r4rAs  z!ClientCreator._register_s3_eventscCsR|jjjdkrdSt|jjt|j|jj|jj j ||jj d|jjdS)NZ s3control)r.rrrGr) rbrNr6rrurtrr$rErcrr)r,rhrPrGrLrJr3r3r4rBs z)ClientCreator._register_s3_control_eventscCsxtd||}|dk rdS|jd|j}|jdkr@|j|kr@dS|jd|j}|d}d|krddS|jd|jdS)Nrz aws-globalsignatureVersionszchoose-signer.s3) !_get_configured_signature_versionr$rrrEconstruct_endpointrtru_default_s3_presign_to_sigv2)r,Z client_metarLrJZprovided_signature_versionZregionsendpointZsignature_versionsr3r3r4r&s      z/ClientCreator._set_s3_presign_signature_versioncKs$xdD]}||rd|SqWdS)a Returns the 's3' (sigv2) signer if presigning an s3 request. This is intended to be used to set the default signature version for the signer to sigv2. :type signature_version: str :param signature_version: The current client signature version. :type signing_name: str :param signing_name: The signing name of the service. :return: 's3' if the request is an s3 presign request, None otherwise )z-queryz -presign-postrN)endswith)r,signature_versionrmsuffixr3r3r4rJs  z*ClientCreator._default_s3_presign_to_sigv2c Cs:t|j|j|j|j|j|jd} | ||||||||| S)N)r2)rr&r%r)r#r*r+Zget_client_args) r,rNrErFrGrHrIrJrLrPZ args_creatorr3r3r4r?\szClientCreator._get_client_argscCs2i}x(|jD]}t|}||||||<q W|S)N)operation_namesr_create_api_method)r,rNZop_dictoperation_namepy_operation_namer3r3r4rUgs  zClientCreator._create_methodscCs(i}x|jD]}t|}|||<q W|S)N)rr)r,rNmappingrrr3r3r4rVos   z"ClientCreator._create_name_mappingcsHfdd}t|_|}t||j|jddd}||_|S)Ncs|rtd||S)Nz$%s() only accepts keyword arguments.) TypeError_make_api_call)r,argsrm)rrr3r4 _api_callzs z3ClientCreator._create_api_method.._api_callzresponse = client.%sF)operation_model method_namer0Zmethod_descriptionZexample_prefixinclude_signature)r[__name__rrr&Z documentation__doc__)r,rrrNrrZ docstringr3)rrr4rxs  z ClientCreator._create_api_method)NNN)TNNNNNN)N)N)r __module__ __qualname__rr5rQrRr;r:r@rerfrgrqr{rCr}r~rDrArBrrr?rUrVrr3r3r3r4r"5s:       $  r"c@seZdZdZdZddgZdddZd d d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdS)!r<aBridges endpoint data and client creation This class handles taking out the relevant arguments from the endpoint resolver and determining which values to use, taking into account any client configuration options and scope configuration options. This class also handles determining what, if any, region to use if no explicit region setting is provided. For example, Amazon S3 client will utilize "us-east-1" by default if no region can be resolved.z {service}.{region}.amazonaws.comrz s3-controlNcCs(||_||_||_||_|p |j|_dS)N)r8r.rJrLDEFAULT_ENDPOINTdefault_endpoint)r,r.rJrLrr8r3r3r4r5s zClientEndpointBridge.__init__TcCsZ|||}|j||}|s0|jj||dd}|rF||||||S|||||SdS)NZaws)Zpartition_name)_check_default_regionr.r_create_endpoint_assume_endpoint)r,r6rErGrFresolvedr3r3r4resolves  zClientEndpointBridge.resolvecCs*|dk r |S|jr&|jjdk r&|jjSdS)N)rLrE)r,r6rEr3r3r4rsz*ClientEndpointBridge._check_default_regionc Cs|dk }||||\}}|dkrl||rD||||d||}n(|d|d}||||dg}|||} |||} |j|||| ||| dS)NZ dnsSuffixZ sslCommonNamehostnameZ protocols)r6rEsigning_region signing_namerGr=r)_pick_region_values_is_s3_dualstack_mode_create_dualstack_endpointr> _make_url_resolve_signature_version_resolve_signing_name_create_result) r,rr6rErGrFexplicit_regionrrrrr3r3r4rs&  z%ClientEndpointBridge._create_endpointcCsn||jkrdS|j}|dk r:|jdk r:d|jkr:|jdS|jdkrHdS|jdidd}|dkrjdSdS)NFZuse_dualstack_endpointr)TTruerT)_DUALSTACK_ENABLED_SERVICESrLrrJr>)r,r6rLrr3r3r4rs    z*ClientEndpointBridge._is_s3_dualstack_modecCs2|s|dkrd}dj|||d}|||ddgS)Nz aws-globalz us-east-1z){service}.dualstack.{region}.{dns_suffix})servicer dns_suffixhttphttps)formatr)r,r6rErrFrrr3r3r4rs  z/ClientEndpointBridge._create_dualstack_endpointc Csr|dkr*|jj||d}|||ddg}td|||||ddgi}|j|id}|j||||||idS) N)rrrrz#Assuming an endpoint for %s, %s: %srv4)r)r6rErrrrGr=)rrrrrrsrrr)r,r6rErGrFrrrr3r3r4rs   z%ClientEndpointBridge._assume_endpointcCs|||||||dS)N)r6rErrrGrr=r3)r,r6rErrrGrr=r3r3r4rsz#ClientEndpointBridge._create_resultcCs"|rd|krd}nd}d||fS)Nrrz%s://%sr3)r,rrFZsupported_protocolsschemer3r3r4r"s zClientEndpointBridge._make_urlcCs0d|kr d|dkr |ddS|jr,|jS|S)NcredentialScoper)r8)r,r6rr3r3r4r)s   z*ClientEndpointBridge._resolve_signing_namecCs@|}|dkr8|d}|}d|kr8d|dkr8|dd}||fS)NZ endpointNamerrr3)r,rrErGrr3r3r4r4s   z(ClientEndpointBridge._pick_region_valuescCsrt||j|j}|dk r|Sd|kr^|d}|dkr8dSd|krDdSx|D]}|tkrJ|SqJWt|dddS)NrrZs3v4r)r)rrLrJrr r>)r,r6rZconfigured_versionZpotential_versionsZknownr3r3r4rHs z/ClientEndpointBridge._resolve_signature_version)NNNN)NNT)rrrrrrr5rrrrrrrrrrrr3r3r3r4r<s$     r<c@seZdZiZddZddZddZeddZd d Z d d Z d ddZ ddZ ddZ ddZddZddZeddZeddZddZd S)!rWc Cs\||_||_||_||_i|_||_||_t||j|j||j | |_ | |_ d|_ | dS)N) _serializer _endpointZ_response_parser_request_signer_cacher#_client_config ClientMetahostrSrbr* _exceptions_register_handlers) r, serializerrZresponse_parserr0request_signerrNr-rLrr1r3r3r4r5hs zBaseClient.__init__cCsNd|jj|f}|jjj||d\}}|dk r6|Std|jj|fdS)Nz getattr.%s.%s)rhz!'%s' object has no attribute '%s') _service_modelrXrYrbrtemit_until_responseAttributeError __class__r)r,item event_namervevent_responser3r3r4 __getattr__yszBaseClient.__getattr__cCs*|jjj}|jjd||jjdS)Nzrequest-created.%s)rbrNrXrYrtrurrv)r,rXr3r3r4rszBaseClient._register_handlerscCs|jjS)N)rbrN)r,r3r3r4rszBaseClient._service_modelcCs|j|}|jj}td|||d|jr exceptionsZ from_code)r,r api_paramsrr6request_context request_dictrXrvrrZparsed_responseZ error_codeZ error_classr3r3r4rsJ          zBaseClient._make_api_callc Cs`y|j||Stk rZ}z.|jjjdj|jj |j d||dWdd}~XYnXdS)Nz.after-call-error.{service_id}.{operation_name})rXr) exceptionr) rZ make_request Exceptionrbrtr9rrrXrYname)r,rrrer3r3r4rs  zBaseClient._make_requestNcCsL||||}|j||}|jjs0|ddt||jj|jj |d|S)N host_prefix)rGr/r) _emit_api_paramsrZserialize_to_requestrZinject_host_prefixryrrrr/)r,rrrrr3r3r4rs   z#BaseClient._convert_to_request_dictcCsf|j}|jj}|jjjdj||d|||d}t||d}d}|jjj|j||d|||d|S)Nz3provide-client-params.{service_id}.{operation_name})rXr)rrr)r7z4before-parameter-build.{service_id}.{operation_name}) rrrXrYrbrtr9rr)r,rrrrrXrMrr3r3r4rs    zBaseClient._emit_api_paramsc Cs||st|dn|j|}dd}|jd|}t||jj|jj|dd|_t dt |jj|f}t |t fd|i}|j |}|t||||}|Sd S) aCreate a paginator for an operation. :type operation_name: string :param operation_name: The operation name. This is the same name as the method name on the client. For example, if the method name is ``create_foo``, and you'd normally invoke the operation as ``client.create_foo(**kwargs)``, if the ``create_foo`` operation can be paginated, you can use the call ``client.get_paginator("create_foo")``. :raise OperationNotPageableError: Raised if the operation is not pageable. You can use the ``client.can_paginate`` method to check if an operation is pageable. :rtype: L{botocore.paginate.Paginator} :return: A paginator object. )rc[stj|f|S)N)rpaginate)r,rmr3r3r4rsz*BaseClient.get_paginator..paginate page_configF)Zpaginator_namer0rNpaginator_configrz%s.Paginator.%srN) can_paginater rSrrrbrtrNrr[rrZrrrgetattr) r,ractual_operation_namerrZpaginator_class_nameZdocumented_paginator_clsrZ paginatorr3r3r4 get_paginators.       zBaseClient.get_paginatorcCsld|jkrTy*|j|jjd|jjd}||jd<Wntk rRi|jd<YnX|j|}||jdkS)aMCheck if an operation can be paginated. :type operation_name: string :param operation_name: The operation name. This is the same name as the method name on the client. For example, if the method name is ``create_foo``, and you'd normally invoke the operation as ``client.create_foo(**kwargs)``, if the ``create_foo`` operation can be paginated, you can use the call ``client.get_paginator("create_foo")``. :return: ``True`` if the operation can be paginated, ``False`` otherwise. rz paginators-1Z pagination)rr#r_rr6rKr rS)r,rrrr3r3r4r0s  zBaseClient.can_paginatecCsZd|jkrPy&|j|jjd|jj}||jd<Wntk rNi|jd<YnX|jdS)N waiter_configz waiters-2)rr#r_rr6rKr )r,rr3r3r4_get_waiter_configKs  zBaseClient._get_waiter_configcCsh|}|std|t|}i}x|jD]}||t|<q.W||krVtd|t||||S)aGReturns an object that can wait for some condition. :type waiter_name: str :param waiter_name: The name of the waiter to get. See the waiters section of the service docs for a list of available waiters. :returns: The specified waiter object. :rtype: botocore.waiter.Waiter zWaiter does not exist: %s)r ValueErrorr WaiterModel waiter_namesrZcreate_waiter_with_client)r,Z waiter_namercrrrr3r3r4 get_waiterWs     zBaseClient.get_waitercCs*|}|sgSt|}dd|jDS)z(Returns a list of all available waiters.cSsg|] }t|qSr3)r).0rr3r3r4 wsz+BaseClient.waiter_names..)rrrr)r,rcrr3r3r4rns  zBaseClient.waiter_namescCs|jdkr||_|jS)N)r_load_exceptions)r,r3r3r4rys  zBaseClient.exceptionscCs|j|jS)N)r*Zcreate_client_exceptionsr)r,r3r3r4rszBaseClient._load_exceptions)N)rrrrSr5rrpropertyrrrrrrrrrrrrrr3r3r3r4rW^s  1 9  rWc@s`eZdZdZddZeddZeddZedd Zed d Z ed d Z eddZ dS)ra~Holds additional client methods. This class holds additional information for clients. It exists for two reasons: * To give advanced functionality to clients * To namespace additional client attributes from the operation names which are mapped to methods at runtime. This avoids ever running into collisions with operation names. cCs(||_||_||_||_||_||_dS)N)rtr _endpoint_urlr_method_to_api_mapping _partition)r,rtrLrGrNmethod_to_api_mappingrr3r3r4r5s zClientMeta.__init__cCs|jS)N)r)r,r3r3r4rNszClientMeta.service_modelcCs|jjS)N)rrE)r,r3r3r4rEszClientMeta.region_namecCs|jS)N)r)r,r3r3r4rGszClientMeta.endpoint_urlcCs|jS)N)r)r,r3r3r4rcszClientMeta.configcCs|jS)N)r)r,r3r3r4rsz ClientMeta.method_to_api_mappingcCs|jS)N)r)r,r3r3r4rszClientMeta.partitionN) rrrrr5rrNrErGrcrrr3r3r3r4rs      rcCs\|r|jdk r|jS|dk rX||}|dk rXt|trX|d}|rXtd|||SdS)z Gets the manually configured signature version. :returns: the customer configured signature version, or None if no signature version was configured. NrzWSwitching signature version for service %s to version %s based on config file override.)rr>rdictrrrs)r6rLrJZservice_configversionr3r3r4rs   r):logging functoolsZbotocorerrZ botocore.argsrZ botocore.authrZbotocore.awsrequestrZbotocore.docs.docstringrrZbotocore.exceptionsr r r r r rZbotocore.hooksrZbotocore.modelrZbotocore.paginaterZbotocore.utilsrrrrrrrrrZbotocore.configrZbotocore.historyrZbotocore.discoveryrrrZbotocore.retriesr r! getLoggerrrrrobjectr"r<rWrrr3r3r3r4 s>         (       aK(/