U kY!_@sddlZddlZddlmZmZddlmZddlmZddl m Z ddl m Z ddl m Z mZddl mZdd l mZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&m'Z'ddl(m)Z)ddl(m*Z*e+e,Z-e#Z.Gddde/Z0Gddde/Z1Gddde/Z2Gdd d e/Z3d!d"Z4dS)#N)waiter xform_name)AUTH_TYPE_MAPS)prepare_request_dict)ClientMethodDocstring)PaginatorDocstring) ClientErrorDataNotFoundError)OperationNotPageableError)UnknownSignatureVersionError)first_non_none_response) ServiceModel) Paginator)CachedProperty)get_service_module_name)S3RegionRedirector)S3ArnParamHandler)S3EndpointSetter)ClientArgsCreator)UNSIGNED)Config)get_global_history_recorder)EndpointDiscoveryHandlerEndpointDiscoveryManager,block_endpoint_discovery_required_operations)standard)adaptivec@seZdZdZd*ddZd+ddZd,dd Zd d Zd-d d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)ZdS). 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_emitterZretry_handler_factoryZretry_config_translatorZresponse_parser_factoryexceptions_factory config_storer/g/private/var/folders/2d/2jcwkxfx4hj39rq32sgz27wh9m_5lk/T/pip-unpacked-wheel-59b8s650/botocore/client.py__init__4szClientCreator.__init__Tc  Cs|jjd|d} t| |d}|||} ||| } t|j|| | jdd} | | ||||||| | }| f|}| || || || || ||| |S)Nzchoose-service-name service_namedefaultZ signingNameservice_signing_name) r"emitr _load_service_model_create_client_classClientEndpointBridger metadataget_get_client_args_register_retries_register_s3_events_register_endpoint_discovery)r(r3 region_name is_secure endpoint_urlverify credentials scoped_config api_version client_config responses service_modelclsendpoint_bridgeZ client_argsZservice_clientr/r/r0 create_clientFsN      zClientCreator.create_clientcCs|||}|||Sr)r9r:)r(r3rHrKr/r/r0create_client_class`s 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"r8rtypestrtuple) r(r3rKrQZpy_name_to_operation_namebasesrU class_namerLr/r/r0r:ds   z"ClientCreator._create_client_classcCs"|jj|d|d}t||d}|S)Nz service-2)rHr2)rload_service_modelr )r(r3rHZ json_modelrKr/r/r0r9rs   z!ClientCreator._load_service_modelcCsV|jjjd}|dkr"||n0|dkr@||||n|dkrR||dS)Nmoderrlegacy)metaconfigretries_register_v2_standard_retries_register_v2_adaptive_retries_register_legacy_retries)r(client retry_moder/r/r0r?xs   zClientCreator._register_retriescCs8|jjjd}d|i}|dk r(||d<tjf|dS)Ntotal_max_attemptsre max_attempts)r_r`rar=rregister_retry_handler)r(rerhkwargsr/r/r0rbs z+ClientCreator._register_v2_standard_retriescCst|dSr)rri)r(rer/r/r0rcsz+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)r_rKendpoint_prefixrUrVrZ load_data_transform_legacy_retriesr`rar$Zbuild_retry_configr=loggerdebugr3r#Zcreate_retry_handlereventsregister) r(rermrUZservice_event_nameZoriginal_configraZ retry_confighandlerrlr/r/r0rds4     z&ClientCreator._register_legacy_retriescCs:|dkr dS|}d|kr6|}|dd|d<|S)Nrgrh)copypop)r(raZ copied_argsr/r/r0rns z'ClientCreator._transform_legacy_retriescCs6|jjj}|dk r(|ddk r(|dS|dp4dS)Nr]rfr^)r_r`rar=get_config_variable)r(rer.Zclient_retriesr/r/r0_get_retry_modes   zClientCreator._get_retry_modec Cs|dk r dS|jjjdkrdS|jj}|jjj}d}|rN|jdk rN|j}n|jr`|jd}|rt |}t |}| ||n | dt dS)NFendpoint_discovery_enabledzbefore-parameter-build) r_rKZendpoint_discovery_operationrqrUrVryr'rwrrrrr) r(rerDr`rqrUenabledmanagerrsr/r/r0rAs(z*ClientCreator._register_endpoint_discoverycCsp|jjjdkrdSt||t|jjt|j|jj |jj j ||jj d|jj| |j||dS)Ns3)r*regionZ s3_configrD partition)r_rKr3rrrrrqrr rBr`r|r~!_set_s3_presign_signature_version)r(rerMrDrIrGr/r/r0r@s$z!ClientCreator._register_s3_eventscCsxtd||}|dk rdS|jd|j}|jdkr@|j|kr@dS|jd|j}|d}d|krddS|jd|jdS)Nr| aws-globalsignatureVersionszchoose-signer.s3) !_get_configured_signature_versionr Zget_available_endpointsr~rBconstruct_endpointrqrr_default_s3_presign_to_sigv2)r(Z client_metarIrGZprovided_signature_versionZregionsendpointZsignature_versionsr/r/r0rs4 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-postr|N)endswith)r(signature_versionrjsuffixr/r/r0rs z*ClientCreator._default_s3_presign_to_sigv2c Cs:t|j|j|j|j|j|jd} | ||||||||| S)N)r.)rr"r!r%rr&r'Zget_client_args) r(rKrBrCrDrErFrGrIrMZ args_creatorr/r/r0r>s&zClientCreator._get_client_argscCs.i}|jD]}t|}||||||<q |Sr)operation_namesr_create_api_method)r(rKZop_dictoperation_namepy_operation_namer/r/r0rR!s  zClientCreator._create_methodscCs$i}|jD]}t|}|||<q |Sr)rr)r(rKmappingrrr/r/r0rS)s   z"ClientCreator._create_name_mappingcsHfdd}t|_|}t||j|jddd}||_|S)Ncs|rtd||S)Nz$%s() only accepts keyword arguments.) TypeError_make_api_call)r(argsrjrrr/r0 _api_call4s z3ClientCreator._create_api_method.._api_callzresponse = client.%sF)operation_model method_namer,Zmethod_descriptionZexample_prefixinclude_signature)rX__name__rrr"Z documentation__doc__)r(rrrKrrZ docstringr/rr0r2s  z ClientCreator._create_api_method)NNN)TNNNNNN)N)N)r __module__ __qualname__rr1rNrOr:r9r?rbrcrdrnrxrAr@rrr>rRrSrr/r/r/r0r2s<      $  rc@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.comr|z s3-controlNcCs(||_||_||_||_|p |j|_dSr)r7r*rGrIDEFAULT_ENDPOINTdefault_endpoint)r(r*rGrIrr7r/r/r0r1\s zClientEndpointBridge.__init__TcCsZ|||}|j||}|s0|jj||dd}|rF||||||S|||||SdS)NZaws)Zpartition_name)_check_default_regionr*r_create_endpoint_assume_endpoint)r(r3rBrDrCresolvedr/r/r0resolvees. zClientEndpointBridge.resolvecCs*|dk r |S|jr&|jjdk r&|jjSdSr)rIrB)r(r3rBr/r/r0rzsz*ClientEndpointBridge._check_default_regionc Cs|dk }||||\}}|dkrl||rD||||d||}n(|d|d}||||dg}|||} |||} |j|||| ||| dS)NZ dnsSuffixZ sslCommonNamehostnameZ protocols)r3rBsigning_region signing_namerDr<r)_pick_region_values_is_s3_dualstack_mode_create_dualstack_endpointr= _make_url_resolve_signature_version_resolve_signing_name_create_result) r(rr3rBrDrCexplicit_regionrrrrr/r/r0rsB   z%ClientEndpointBridge._create_endpointcCsn||jkrdS|j}|dk r:|jdk r:d|jkr:|jdS|jdkrHdS|jdidd}|dkrjdSdS)NFZuse_dualstack_endpointr|)TTruetrueT)_DUALSTACK_ENABLED_SERVICESrIr|rGr=)r(r3rIrzr/r/r0rs    z*ClientEndpointBridge._is_s3_dualstack_modecCs2|s|dkrd}dj|||d}|||ddgS)Nrz us-east-1z){service}.dualstack.{region}.{dns_suffix})servicer} dns_suffixhttphttps)formatr)r(r3rBrrCrrr/r/r0rs z/ClientEndpointBridge._create_dualstack_endpointc Csr|dkr*|jj||d}|||ddg}td|||||ddgi}|j|id}|j||||||idS) N)rr}rrz#Assuming an endpoint for %s, %s: %srv4)r)r3rBrrrrDr<)rrrrorprrr)r(r3rBrDrCrrrr/r/r0rs6z%ClientEndpointBridge._assume_endpointcCs|||||||dS)N)r3rBrrrDrr<r/)r(r3rBrrrDrr<r/r/r0rsz#ClientEndpointBridge._create_resultcCs"|rd|krd}nd}d||fS)Nrrz%s://%sr/)r(rrCZsupported_protocolsschemer/r/r0rs zClientEndpointBridge._make_urlcCs0d|kr d|dkr |ddS|jr,|jS|S)NcredentialScoperr6)r(r3rr/r/r0rs  z*ClientEndpointBridge._resolve_signing_namecCs@|}|dkr8|d}|}d|kr8d|dkr8|dd}||fS)NZ endpointNamerr}r/)r(rrBrDrr/r/r0rs   z(ClientEndpointBridge._pick_region_valuescCsrt||j|j}|dk r|Sd|kr^|d}|dkr8dSd|krDdS|D]}|tkrH|SqHt|dddS)Nrr|Zs3v4r)r)rrIrGrr r=)r(r3rZconfigured_versionZpotential_versionsZknownr/r/r0rs& z/ClientEndpointBridge._resolve_signature_version)NNNN)NNT)rrrrrrr1rrrrrrrrrrrr/r/r/r0r;Ns*     r;c@seZdZiZddZddZddZeddZd d Z d d Z d ddZ ddZ ddZ ddZddZddZeddZeddZddZd S)!rTc Cs\||_||_||_||_i|_||_||_t||j|j||j | |_ | |_ d|_ | dSr) _serializer _endpointZ_response_parser_request_signer_cacher_client_config ClientMetahostrPr_r& _exceptions_register_handlers) r( serializerrZresponse_parserr,request_signerrKr)rIr~r-r/r/r0r1"s zBaseClient.__init__cCsNd|jj|f}|jjj||d\}}|dk r6|Std|jj|fdS)Nz getattr.%s.%s)rez!'%s' object has no attribute '%s') _service_modelrUrVr_rqemit_until_responseAttributeError __class__r)r(item event_namersevent_responser/r/r0 __getattr__3s   zBaseClient.__getattr__cCs*|jjj}|jjd||jjdS)Nzrequest-created.%s)r_rKrUrVrqrrrrs)r(rUr/r/r0rBs zBaseClient._register_handlerscCs|jjSr)r_rKr(r/r/r0rJszBaseClient._service_modelcCs|j|}|jj}td|||d|jr.paginate page_configF)Zpaginator_namer,rKpaginator_configrz%s.Paginator.%srN) can_paginater rPrrr_rqrKrrXrrWrrrgetattr) r(ractual_operation_namerrZpaginator_class_nameZdocumented_paginator_clsrZ paginatorr/r/r0 get_paginators<      zBaseClient.get_paginatorcCsld|jkrTz*|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)rrr\rr3rHr rP)r(rrrr/r/r0rs  zBaseClient.can_paginatecCsZd|jkrPz&|j|jjd|jj}||jd<Wntk rNi|jd<YnX|jdS)N waiter_configz waiters-2)rrr\rr3rHr )r(rr/r/r0_get_waiter_configs zBaseClient._get_waiter_configcCsd|}|std|t|}i}|jD]}||t|<q,||krRtd|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_namer`rrrr/r/r0 get_waiters     zBaseClient.get_waitercCs*|}|sgSt|}dd|jDS)z(Returns a list of all available waiters.cSsg|] }t|qSr/)r).0rr/r/r0 1sz+BaseClient.waiter_names..)rrrr)r(r`rr/r/r0r(s  zBaseClient.waiter_namescCs|jdkr||_|jSr)r_load_exceptionsrr/r/r0r3s  zBaseClient.exceptionscCs|j|jSr)r&Zcreate_client_exceptionsrrr/r/r0r9szBaseClient._load_exceptions)N)rrrrPr1rrpropertyrrrrrrrrrrrrrr/r/r/r0rTs( 1 9   rTc@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)rqr _endpoint_urlr_method_to_api_mapping _partition)r(rqrIrDrKmethod_to_api_mappingr~r/r/r0r1Ks zClientMeta.__init__cCs|jSr)rrr/r/r0rKTszClientMeta.service_modelcCs|jjSr)rrBrr/r/r0rBXszClientMeta.region_namecCs|jSr)rrr/r/r0rD\szClientMeta.endpoint_urlcCs|jSr)rrr/r/r0r``szClientMeta.configcCs|jSr)rrr/r/r0rdsz ClientMeta.method_to_api_mappingcCs|jSr)rrr/r/r0r~hszClientMeta.partitionN) rrrrr1rrKrBrDr`rr~r/r/r/r0r>s       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= isinstancedictrorp)r3rIrGZservice_configversionr/r/r0rms   r)5logging functoolsZbotocorerrZ botocore.authrZbotocore.awsrequestrZbotocore.docs.docstringrrZbotocore.exceptionsrr r r Zbotocore.hooksr Zbotocore.modelr Zbotocore.paginaterZbotocore.utilsrrrrrZ botocore.argsrrZbotocore.configrZbotocore.historyrZbotocore.discoveryrrrZbotocore.retriesrr getLoggerrrorobjectrr;rTrrr/r/r/r0 sH                     K(/