o <&a@s|ddlZddlmZmZddlmZddlmZddlm Z ddl m Z ddl m Z ddl mZmZmZmZdd lmZdd lmZdd lmZdd lmZmZmZmZmZmZmZm Z dd l!m"Z"ddl#m$Z$m%Z%m&Z&ddl'm(Z(ddl'm)Z)ddl*m+Z+ddl m,Z,ddlmZddlm-Z-e.e/Z0e"Z1Gddde2Z3Gddde2Z4Gddde2Z5Gddde2Z6ddZ7dS)N)waiter xform_name)ClientArgsCreator)AUTH_TYPE_MAPS)prepare_request_dict)ClientMethodDocstring)PaginatorDocstring)DataNotFoundErrorOperationNotPageableErrorUnknownSignatureVersionError*InvalidEndpointDiscoveryConfigurationError)first_non_none_response) ServiceModel) Paginator)CachedPropertyget_service_module_nameS3RegionRedirectorS3ArnParamHandlerS3EndpointSetterensure_booleanS3ControlArnParamHandlerS3ControlEndpointSetter)get_global_history_recorder)EndpointDiscoveryHandlerEndpointDiscoveryManager,block_endpoint_discovery_required_operations)standard)adaptive)Config) ClientError)UNSIGNEDc@seZdZdZ  d2ddZ     d3ddZd4dd Zd d Zd d Zd4ddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1ZdS)5 ClientCreatorz%Creates client objects for a service.Nc Cs:||_||_||_||_||_||_||_||_| |_dSN) _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_emitterretry_handler_factoryretry_config_translatorresponse_parser_factoryexceptions_factory config_storer61/usr/lib/python3/dist-packages/botocore/client.py__init__9s zClientCreator.__init__Tc  Cs|jjd|d} t| |d}|||} ||| } ||| \}} t|j|| | j d|j d} | | ||||||| | }| di|}| || || || |||| || ||||| |S)Nzchoose-service-name service_namedefault signingName)service_signing_namer5r6)r&emitr _load_service_model_create_client_class_normalize_fips_regionClientEndpointBridger$metadatagetr+_get_client_args_register_retries_register_s3_events_register_s3_control_events_register_endpoint_discovery)r,r: region_name is_secure endpoint_urlverify credentials scoped_config api_version client_config responses service_modelclsendpoint_bridge client_argsservice_clientr6r6r7 create_clientKs@      zClientCreator.create_clientcCs|||}|||Sr")r@rA)r,r:rQrTr6r6r7create_client_classks  z!ClientCreator.create_client_classc Csb||}||}||d<tg}|j}|jjd|||dt|}tt |t ||}|S)N_PY_TO_OP_NAMEzcreating-client-class.%s)class_attributes base_classes) _create_methods_create_name_mapping BaseClient service_id hyphenizer&r?rtypestrtuple) r,r:rTr\py_name_to_operation_namebasesra class_namerUr6r6r7rAos   z"ClientCreator._create_client_classcCs`|dur,|dddd}||kr,tdd}|r||}n|}td||f|}||fS)Nzfips-z-fipsT)use_fips_endpointztransforming region from %s to %s and setting use_fips_endpoint to true. client should not be configured with a fips psuedo region.)replacermergeloggerwarning)r,rKrRnormalized_region_nameconfig_use_fips_endpointr6r6r7rB}s* z$ClientCreator._normalize_fips_regioncCs"|jj|d|d}t||d}|S)Nz service-2)rQr9)r#load_service_modelr)r,r:rQ json_modelrTr6r6r7r@s  z!ClientCreator._load_service_modelcCs^|jjjd}|dkr||dS|dkr"||||dS|dkr-||dSdS)Nmoderrlegacy)metaconfigretries_register_v2_standard_retries_register_v2_adaptive_retries_register_legacy_retries)r,client retry_moder6r6r7rGs zClientCreator._register_retriescCs<|jjjd}d|i}|dur||d<tjdi|dS)Ntotal_max_attemptsr{ max_attemptsr6)rurvrwrErregister_retry_handler)r,r{r~kwargsr6r6r7rxs z+ClientCreator._register_v2_standard_retriescCst|dSr")rr)r,r{r6r6r7rysz+ClientCreator._register_v2_adaptive_retriesc Cs|jjj}|jjj}|}|jd}|sdS||jjj }|j || di| di|}t d|jjj|j||}d|} |jjjd||| ddS)N_retryretry definitionsz*Registering retry handlers for service: %szretry-config-%szneeds-retry.%s) unique_id)rurTendpoint_prefixrarbr# load_data_transform_legacy_retriesrvrwr(build_retry_configrErmdebugr:r'create_retry_handlereventsregister) r,r{rraservice_event_nameoriginal_configrw retry_confighandlerrr6r6r7rzs.      z&ClientCreator._register_legacy_retriescCs:|durdS|}d|vr|}|dd|d<|S)Nr}r~)copypop)r,rw copied_argsr6r6r7rs z'ClientCreator._transform_legacy_retriescCs6|jjj}|dur|ddur|dS|dpdS)Nrsr|rt)rurvrwrEget_config_variable)r,r{r5client_retriesr6r6r7_get_retry_modes zClientCreator._get_retry_modec Cs|durdS|jjjdurdS|jj}|jjj}d}|r'|jdur'|j}n |jr0|jd}| |}|rS| ||rS|du}t ||d}t |} | ||dS| dtdS)NFendpoint_discovery_enabledT)always_discoverzbefore-parameter-build)rurTendpoint_discovery_operationrrarbrr+r$_normalize_endpoint_discovery_config_requires_endpoint_discoveryrrrr) r,r{rMrvrraenableddiscovermanagerrr6r6r7rJs,  z*ClientCreator._register_endpoint_discoverycCsLt|tr|}|dkr|S|dvrt|Snt|tr!|St|d)z?Config must either be a boolean-string or string-literal 'auto'auto)truefalse) config_value) isinstancerdlowerstriprboolr )r,rr6r6r7rs    z2ClientCreator._normalize_endpoint_discovery_configcCs|dkr |jjjS|S)Nr)rurTendpoint_discovery_required)r,r{rr6r6r7rs z*ClientCreator._requires_endpoint_discoverycCs||jjjdkr dSt||t|jj|jjj}t |j |jj |jjj ||jj |d|jj||j||dS)Ns3r.region s3_configrM partitionrj)rurTr:rrrrrvrjrr$rKrr!_set_s3_presign_signature_versionr,r{rVrMrRrPrjr6r6r7rHs"  z!ClientCreator._register_s3_eventscCs^|jjjdkr dS|jjj}t|jjt|j |jj |jjj ||jj |d|jjdS)N s3controlr) rurTr:rvrjrrrrr$rKrrrr6r6r7rIs z)ClientCreator._register_s3_control_eventscCsxtd||}|dur dS|jd|j}|jdkr |j|vr dS|jd|j}|d}d|vr2dS|jd|jdS)Nrz aws-globalsignatureVersionszchoose-signer.s3) !_get_configured_signature_versionr$get_available_endpointsrrKconstruct_endpointrr_default_s3_presign_to_sigv2)r, client_metarRrPprovided_signature_versionregionsendpointsignature_versionsr6r6r7r+s(  z/ClientCreator._set_s3_presign_signature_versioncKs$dD] }||rd|SqdS)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_versionrsuffixr6r6r7rOs   z*ClientCreator._default_s3_presign_to_sigv2c Cs:t|j|j|j|j|j|jd} | ||||||||| S)N)r5)rr&r%r)r#r*r+get_client_args) r,rTrKrLrMrNrOrPrRrV args_creatorr6r6r7rFas zClientCreator._get_client_argscCs.i}|jD]}t|}||||||<q|Sr")operation_namesr_create_api_method)r,rTop_dictoperation_namepy_operation_namer6r6r7r^ls  zClientCreator._create_methodscCs$i}|jD] }t|}|||<q|Sr")rr)r,rTmappingrrr6r6r7r_ts   z"ClientCreator._create_name_mappingcsHfdd}t|_|}t||j|jddd}||_|S)Ncs|rtd||S)Nz$%s() only accepts keyword arguments.) TypeError_make_api_call)r,argsrrrr6r7 _api_calls  z3ClientCreator._create_api_method.._api_callzresponse = client.%sF)operation_model method_namer0method_descriptionexample_prefixinclude_signature)rd__name__rrr& documentation__doc__)r,rrrTrr docstringr6rr7r}s z ClientCreator._create_api_method)NNN)TNNNNNNr")r __module__ __qualname__rr8rYrZrArBr@rGrxryrzrrrJrrrHrIrrrFr^r_rr6r6r6r7r!7s@      $  r!c@seZdZdZdZddgZ   d!ddZ  d"d d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd ZdS)#rCaBridges 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|_||_dSr")r>r.rPrRDEFAULT_ENDPOINTdefault_endpointr5)r,r.rPrRrr>r5r6r6r7r8s   zClientEndpointBridge.__init__TcCst|||}||}|d}|jj||||d}|s'|jj||d||d}|r2||||||S|||||S)Nrj)use_dualstack_endpointrjaws)partition_namerrj)_check_default_region_resolve_use_dualstack_endpoint$_resolve_endpoint_variant_config_varr.r_create_endpoint_assume_endpoint)r,r:rKrMrLrrjresolvedr6r6r7resolves2  zClientEndpointBridge.resolvecCs.|dur|S|jr|jjdur|jjSdSdSr")rRrK)r,r:rKr6r6r7rs z*ClientEndpointBridge._check_default_regionc Csr||||\}}|dur!|d|d}||||dg}|||}|||} |j|||| |||dS)N sslCommonNamehostname protocols)r:rKsigning_region signing_namerMrDr)_pick_region_valuesrE _make_url_resolve_signature_version_resolve_signing_name_create_result) r,rr:rKrMrLrrrrr6r6r7rs$  z%ClientEndpointBridge._create_endpointcCs@|j}d}|rt||durt||S|jdur|j|}|S)NF)rRgetattrr5r)r, config_varrR config_valr6r6r7rs   z9ClientEndpointBridge._resolve_endpoint_variant_config_varcCs ||}|dur |S|dS)Nr)_is_s3_dualstack_moder)r,r:s3_dualstack_moder6r6r7rs z4ClientEndpointBridge._resolve_use_dualstack_endpointcCsl||jvrdS|j}|dur|jdurd|jvr|jdS|jdur2|jdid}|dvr4dSdSdS)Nrr)TTruerT)_DUALSTACK_CUSTOMIZED_SERVICESrRrrPrE)r,r:rRrr6r6r7rs    z*ClientEndpointBridge._is_s3_dualstack_modec Csr|dur|jj||d}|||ddg}td|||||ddgi}|j|id}|j||||||idS) N)servicerhttphttpsz#Assuming an endpoint for %s, %s: %srv4)r)r:rKrrrrMrD)rformatrrmrrrr)r,r:rKrMrLrrrr6r6r7rs( z%ClientEndpointBridge._assume_endpointcCs|||||||dS)N)r:rKrrrMrrDr6)r,r:rKrrrMrrDr6r6r7r#sz#ClientEndpointBridge._create_resultcCs"|r d|vr d}nd}d||fS)Nrrz%s://%sr6)r,rrLsupported_protocolsschemer6r6r7r0s  zClientEndpointBridge._make_urlcCs0d|vrd|dvr|ddS|jr|jS|S)NcredentialScoper)r>)r,r:rr6r6r7r7s   z*ClientEndpointBridge._resolve_signing_namecCs@|}|dur|d}|}d|vrd|dvr|dd}||fS)N endpointNamerrr6)r,rrKrMrr6r6r7rBs   z(ClientEndpointBridge._pick_region_valuescCsnt||j|j}|dur|Sd|vr/|d}|dkrdSd|vr"dS|D] }|tvr.|Sq$t|dd)Nrrs3v4r)r)rrRrPrr rE)r,r:rconfigured_versionpotential_versionsknownr6r6r7rVs$ z/ClientEndpointBridge._resolve_signature_version)NNNNN)NNT)rrrrrrr8rrrrrrrrrrrrr6r6r6r7rCs,        rCc@seZdZiZddZddZddZeddZd d Z d d Z d ddZ ddZ ddZ ddZddZddZeddZeddZddZd S)!r`c Cs\||_||_||_||_i|_||_||_t||j|j||j | |_ | |_ d|_ | dSr") _serializer _endpoint_response_parser_request_signer_cacher#_client_config ClientMetahostr[rur* _exceptions_register_handlers) r, serializerrresponse_parserr0request_signerrTr-rRrr4r6r6r7r8vs zBaseClient.__init__cCsJd|jj|f}|jjj||d\}}|dur|Std|jj|f)Nz getattr.%s.%s)r{z!'%s' object has no attribute '%s') _service_modelrarbruremit_until_responseAttributeError __class__r)r,item event_namerevent_responser6r6r7 __getattr__s  zBaseClient.__getattr__cCs*|jjj}|jjd||jjdS)Nzrequest-created.%s)rurTrarbrrrr)r,rar6r6r7r s zBaseClient._register_handlerscC|jjSr")rurTr,r6r6r7r zBaseClient._service_modelcCs|j|}|jj}td|||d|jrtd|||jj |jj |j |j d}|j |||d}|jj}|jjjdj||d|||j|d\}} | durV| \} } n ||||\} } |jjjd j||d| | ||d | jd kr| d id } |j| } | | || S)NAPI_CALL)r operationparamszWarning: %s.%s() is deprecated) client_regionrRhas_streaming_input auth_type)contextz)before-call.{service_id}.{operation_name}rar)modelrr rz(after-call.{service_id}.{operation_name}) http_responseparsedr ri,ErrorCode)r rr:history_recorderrecord deprecatedrmrrurKrvrr_convert_to_request_dictrarbrrrr _make_requestr? status_coderE exceptions from_code)r,r api_paramsrr:request_context request_dictrarrrparsed_response error_code error_classr6r6r7rs\       zBaseClient._make_api_callc CsTz|j||WSty)}z|jjjdj|jj |j d||dd}~ww)Nz.after-call-error.{service_id}.{operation_name}r) exceptionr) r make_request Exceptionrurr?rr rarbname)r,rr/r.er6r6r7r)s zBaseClient._make_requestNcCsL||||}|j||}|jjs|ddt||jj|jj |d|S)N host_prefix)rMr/r) _emit_api_paramsrserialize_to_requestrinject_host_prefixrrrrr/)r,r-rrr/r6r6r7r(s  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}r)rr rr;z4before-parameter-build.{service_id}.{operation_name}) r6r rarbrurr?rr )r,r-rrrrarSrr6r6r7r9s(  zBaseClient._emit_api_paramsc Cs||s t|d|j|}dd}|jd|}t||jj|jj|dd|_t dt |jj|f}t |t fd|i}|j |}|t||||}|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|fi|Sr")rpaginate)r,rr6r6r7r< sz*BaseClient.get_paginator..paginate page_configF)paginator_namer0rTpaginator_configrz%s.Paginator.%sr<) can_paginater r[rrrurrTrrdrrcrr rr) r,ractual_operation_namer<r?paginator_class_namedocumented_paginator_clsr paginatorr6r6r7 get_paginators8      zBaseClient.get_paginatorcCsjd|jvr)z|j|jjd|jjd}||jd<Wnty(i|jd<Ynw|j|}||jdvS)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. r=z paginators-1 pagination)rr#rqr r:rQr r[)r,rr=rAr6r6r7r@>s   zBaseClient.can_paginatecCsXd|jvr'z|j|jjd|jj}||jd<Wnty&i|jd<Ynw|jdS)N waiter_configz waiters-2)rr#rqr r:rQr )r,rGr6r6r7_get_waiter_configYs   zBaseClient._get_waiter_configcCsd|}|s td|t|}i}|jD]}||t|<q||vr)td|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)rH ValueErrorr WaiterModel waiter_namesrcreate_waiter_with_client)r, waiter_namervr rr6r6r6r7 get_waiteres      zBaseClient.get_waitercCs*|}|sgSt|}dd|jDS)z(Returns a list of all available waiters.cSsg|]}t|qSr6)r).0r6r6r6r7 sz+BaseClient.waiter_names..)rHrrJrK)r,rvr r6r6r7rK|s  zBaseClient.waiter_namescCs|jdur ||_|jSr")r_load_exceptionsrr6r6r7r+s  zBaseClient.exceptionscCs|j|jSr")r*create_client_exceptionsr rr6r6r7rQszBaseClient._load_exceptionsr")rrrr[r8rr propertyr rr)r(r9rEr@rHrNrrKr+rQr6r6r6r7r`ls* 1  9    r`c@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(||_||_||_||_||_||_dSr")rr _endpoint_urlr _method_to_api_mapping _partition)r,rrRrMrTmethod_to_api_mappingrr6r6r7r8s  zClientMeta.__init__cC|jSr")r rr6r6r7rTzClientMeta.service_modelcCrr")rrKrr6r6r7rKrzClientMeta.region_namecCrXr")rTrr6r6r7rMrYzClientMeta.endpoint_urlcCrXr")rrr6r6r7rvrYzClientMeta.configcCrXr")rUrr6r6r7rWrYz ClientMeta.method_to_api_mappingcCrXr")rVrr6r6r7rrYzClientMeta.partitionN) rrrrr8rSrTrKrMrvrWrr6r6r6r7rs      rcCs\|r |jdur |jS|dur,||}|dur,t|tr,|d}|r,td|||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.)rrErdictrmr)r:rRrPservice_configversionr6r6r7rs   r)8loggingbotocorerr botocore.argsr botocore.authrbotocore.awsrequestrbotocore.docs.docstringrrbotocore.exceptionsr r r r botocore.hooksr botocore.modelrbotocore.paginaterbotocore.utilsrrrrrrrrbotocore.historyrbotocore.discoveryrrrbotocore.retriesrrbotocore.configrrr getLoggerrrmr%objectr!rCr`rrr6r6r6r7s@         (        dT( /