B \|@sddlZddlZddlmZmZddlmZddlmZddl m Z ddl m Z ddl m Z mZddl mZdd l mZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddl!m"Z"ddlm#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)m*Z*m+Z+e,e-Z.e'Z/Gddde0Z1Gddde0Z2Gddde0Z3Gd d!d!e0Z4d"d#Z5dS)$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)switch_host_s3_accelerate)S3RegionRedirector) fix_s3_host)switch_to_virtual_host_style)S3_ACCELERATE_WHITELIST)ClientArgsCreator)urlsplit)UNSIGNED)Config)get_global_history_recorder)EndpointDiscoveryHandlerEndpointDiscoveryManager,block_endpoint_discovery_required_operationsc@seZdZdZd(ddZd)ddZd*dd Zd d Zd+d d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'ZdS), 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_factoryZ config_storer.3/tmp/pip-build-uw_ogi45/botocore/botocore/client.py__init__5szClientCreator.__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_endpoint_discovery)r(r1 region_name is_secure endpoint_urlverify credentials scoped_config api_version client_config responses service_modelclsendpoint_bridgeZ client_argsZservice_clientr.r.r/ create_clientGs&       zClientCreator.create_clientcCs|||}|||S)N)r5r6)r(r1rDrGr.r.r/create_client_classas 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"r4rtypestrtuple) r(r1rGrMZpy_name_to_operation_namebasesrQ class_namerHr.r.r/r6es   z"ClientCreator._create_client_classcCs"|jj|d|d}t||d}|S)Nz service-2)rD)r1)rload_service_modelr )r(r1rDZ json_modelrGr.r.r/r5ss  z!ClientCreator._load_service_modelc Cs|jjj}|jjj}|}|jd}|s0dS|j|| di| di|jj j }t d|jjj|j||}d|}|jjjd|||ddS)NZ_retryretryZ definitionsz*Registering retry handlers for service: %szretry-config-%szneeds-retry.%s) unique_id)metarGendpoint_prefixrQrRrZ load_datar$Zbuild_retry_configr9configretriesloggerdebugr1r#Zcreate_retry_handlereventsregister) r(clientr\rQZservice_event_nameZoriginal_configZ retry_confighandlerrZr.r.r/r;ys$       zClientCreator._register_retriesc 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[rGZendpoint_discovery_operationrarQrRrer'Zget_config_variablerrrbr) r(rcr@r]rarQenabledmanagerrdr.r.r/r=s$z*ClientCreator._register_endpoint_discoverycCst|jjjdkrdSt|||||jjj|jj|jj | ||jjjr`|jj dt | |j||dS)Ns3zbefore-sign.s3)r[rGr1rrb_set_s3_addressing_styler]rhra partition_is_s3_accelerateZregister_firstr!_set_s3_presign_signature_version)r(rcrIr@rErCr.r.r/r<s z!ClientCreator._register_s3_eventscCs@|dkr i}|||}|||||}|dk r<|d|dS)Nzbefore-sign.s3)_get_s3_addressing_style_get_s3_addressing_handlerrb)r(r@ s3_configr,rjaddressing_stylerdr.r.r/ris z&ClientCreator._set_s3_addressing_stylecCs6|dd}|s|||r dS|d}|r2|SdS)Nuse_accelerate_endpointFvirtualrp)r9rk)r(r@roZ accelerateZconfigured_addressing_styler.r.r/rms   z&ClientCreator._get_s3_addressing_stylecCsB|dkrtdtS|dks&|dk r4tddStdtS)Nrrz'Using S3 virtual host style addressing.pathzUsing S3 path style addressing.zSDefaulting to S3 virtual host style addressing with path style addressing fallback.)r_r`rr)r(r@rorprjr.r.r/rns   z(ClientCreator._get_s3_addressing_handlercCs|dk r|drdS|dkr"dSt|j}|ds:dS|d}|ddkrTdS|dd }t|tt|krxdStd d |DS) NrqTFz amazonaws.com.rz s3-acceleratecss|]}|tkVqdS)N)r).0pr.r.r/ sz2ClientCreator._is_s3_accelerate..)r9rnetlocendswithsplitlensetall)r(r@rorzpartsZ feature_partsr.r.r/rks     zClientCreator._is_s3_acceleratecCsntd||}|dk rdS|jd|j}|j|kr6dS|jd|j}|d}d|krZdS|jd|jdS)NrhsignatureVersionszchoose-signer.s3) !_get_configured_signature_versionr Zget_available_endpointsrjr>construct_endpointrarb_default_s3_presign_to_sigv2)r(Z client_metarErCZprovided_signature_versionZregionsendpointZsignature_versionsr.r.r/rl 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-postrhN)r{)r(signature_versionkwargssuffixr.r.r/r-s  z*ClientCreator._default_s3_presign_to_sigv2c Cs4t|j|j|j|j|j} | ||||||||| S)N)rr"r!r%rr&Zget_client_args) r(rGr>r?r@rArBrCrErIZ args_creatorr.r.r/r:?szClientCreator._get_client_argscCs2i}x(|jD]}t|}||||||<q W|S)N)operation_namesr_create_api_method)r(rGZop_dictoperation_namepy_operation_namer.r.r/rNJs  zClientCreator._create_methodscCs(i}x|jD]}t|}|||<q W|S)N)rr)r(rGmappingrrr.r.r/rORs   z"ClientCreator._create_name_mappingcsHfdd}t|_|}t||j|jddd}||_|S)Ncs|rtd||S)Nz$%s() only accepts keyword arguments.) TypeError_make_api_call)r(argsr)rrr.r/ _api_call]s z3ClientCreator._create_api_method.._api_callzresponse = client.%sF)operation_model method_namer,Zmethod_descriptionZexample_prefixinclude_signature)rT__name__rrr"Z documentation__doc__)r(rrrGrrZ docstringr.)rrr/r[s  z ClientCreator._create_api_method)NNN)TNNNNNN)N)N)r __module__ __qualname__rr0rJrKr6r5r;r=r<rirmrnrkrlrr:rNrOrr.r.r.r/r3s0         rc@seZdZdZdZddgZdddZd d d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdS)!r7aBridges 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.comrhz s3-controlNcCs(||_||_||_||_|p |j|_dS)N)r3r*rCrEDEFAULT_ENDPOINTdefault_endpoint)r(r*rCrErr3r.r.r/r0s zClientEndpointBridge.__init__TcCsD|||}|j||}|r0||||||S|||||SdS)N)_check_default_regionr*r_create_endpoint_assume_endpoint)r(r1r>r@r?resolvedr.r.r/resolves zClientEndpointBridge.resolvecCs*|dk r |S|jr&|jjdk r&|jjSdS)N)rEr>)r(r1r>r.r.r/rsz*ClientEndpointBridge._check_default_regionc Cs||||\}}|dkrb||r:||||d|}n(|d|d}||||dg}|||}|||} |j|||| |||dS)NZ dnsSuffixZ sslCommonNamehostnameZ protocols)r1r>signing_region signing_namer@r8r)_pick_region_values_is_s3_dualstack_mode_create_dualstack_endpointr9 _make_url_resolve_signature_version_resolve_signing_name_create_result) r(rr1r>r@r?rrrrr.r.r/rs$  z%ClientEndpointBridge._create_endpointcCsn||jkrdS|j}|dk r:|jdk r:d|jkr:|jdS|jdkrHdS|jdidd}|dkrjdSdS)NFZuse_dualstack_endpointrh)TTruetrueT)_DUALSTACK_ENABLED_SERVICESrErhrCr9)r(r1rErfr.r.r/rs    z*ClientEndpointBridge._is_s3_dualstack_modecCs"dj|||d}|||ddgS)Nz){service}.dualstack.{region}.{dns_suffix})serviceregion dns_suffixhttphttps)formatr)r(r1r>rr?rr.r.r/rsz/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)r1r>rrrr@r8)rrrr_r`rrr)r(r1r>r@r?rrrr.r.r/rs   z%ClientEndpointBridge._assume_endpointcCs|||||||dS)N)r1r>rrr@rr8r.)r(r1r>rrr@rr8r.r.r/rsz#ClientEndpointBridge._create_resultcCs"|rd|krd}nd}d||fS)Nrrz%s://%sr.)r(rr?Zsupported_protocolsschemer.r.r/rs zClientEndpointBridge._make_urlcCs0d|kr d|dkr |ddS|jr,|jS|S)NcredentialScoper)r3)r(r1rr.r.r/rs   z*ClientEndpointBridge._resolve_signing_namecCs@|}|dkr8|d}|}d|kr8d|dkr8|dd}||fS)NZ endpointNamerrr.)r(rr>r@rr.r.r/rs   z(ClientEndpointBridge._pick_region_valuescCsrt||j|j}|dk r|Sd|kr^|d}|dkr8dSd|krDdSx|D]}|tkrJ|SqJWt|dddS)NrrhZs3v4r)r)rrErCrr r9)r(r1rZconfigured_versionZpotential_versionsZknownr.r.r/rs z/ClientEndpointBridge._resolve_signature_version)NNNN)NNT)rrrrrrr0rrrrrrrrrrrr.r.r.r/r7ws$      r7c@seZdZiZddZddZddZeddZd d Z d d Z d ddZ ddZ ddZ ddZddZddZeddZeddZddZd S)!rPc Cs\||_||_||_||_i|_||_||_t||j|j||j | |_ | |_ d|_ | dS)N) _serializer _endpointZ_response_parser_request_signer_cacher_client_config ClientMetahostrLr[r& _exceptions_register_handlers) r( serializerrZresponse_parserr,request_signerrGr)rErjr-r.r.r/r0<s zBaseClient.__init__cCsNd|jj|f}|jjj||d\}}|dk r6|Std|jj|fdS)Nz getattr.%s.%s)rcz!'%s' object has no attribute '%s') _service_modelrQrRr[raemit_until_responseAttributeError __class__r)r(item event_namerdevent_responser.r.r/ __getattr__MszBaseClient.__getattr__cCs*|jjj}|jjd||jjdS)Nzrequest-created.%s)r[rGrQrRrarbrrd)r(rQr.r.r/r\szBaseClient._register_handlerscCs|jjS)N)r[rG)r(r.r.r/rdszBaseClient._service_modelcCs|j|}|jj}td|||d|jrr]rr_convert_to_request_dictrQrRrarrr _make_requestr4 status_coder9 exceptionsZ from_code)r(r api_paramsrr1request_context request_dictrQrdrrZparsed_responseZ error_codeZ error_classr.r.r/rhsJ          zBaseClient._make_api_callc Cs`y|j||Stk rZ}z.|jjjdj|jj |j d||dWdd}~XYnXdS)Nz.after-call-error.{service_id}.{operation_name})rQr) exceptionr) rZ make_request Exceptionr[rar4rrrQrRname)r(rrrer.r.r/rs  zBaseClient._make_requestNcCsL||||}|j||}|jjs0|ddt||jj|jj |d|S)N host_prefix)r@r+r) _emit_api_paramsrZserialize_to_requestrZinject_host_prefixpoprrrr+)r(rrrrr.r.r/rs   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})rQr)rrr)r2z4before-parameter-build.{service_id}.{operation_name}) rrrQrRr[rar4rr )r(rrrrrQrFrr.r.r/rs    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(rr.r.r/rsz*BaseClient.get_paginator..paginate page_configF)Zpaginator_namer,rGpaginator_configrz%s.Paginator.%srN) can_paginater rLrrr[rarGrrTrrSrrrgetattr) r(ractual_operation_namerrZpaginator_class_nameZdocumented_paginator_clsrZ paginatorr.r.r/ 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)rrrXrr1rDr rL)r(rrrr.r.r/rs  zBaseClient.can_paginatecCsZd|jkrPy&|j|jjd|jj}||jd<Wntk rNi|jd<YnX|jdS)N waiter_configz waiters-2)rrrXrr1rDr )r(rr.r.r/_get_waiter_configs  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_namer]rrrr.r.r/ get_waiter+s     zBaseClient.get_waitercCs*|}|sgSt|}dd|jDS)z(Returns a list of all available waiters.cSsg|] }t|qSr.)r)rwrr.r.r/ Ksz+BaseClient.waiter_names..)rrrr)r(r]rr.r.r/rBs  zBaseClient.waiter_namescCs|jdkr||_|jS)N)r_load_exceptions)r(r.r.r/rMs  zBaseClient.exceptionscCs|j|jS)N)r&Zcreate_client_exceptionsr)r(r.r.r/rSszBaseClient._load_exceptions)N)rrrrLr0rrpropertyrrrrrrrrrrrrrr.r.r.r/rP2s  1 9  rPc@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)rar _endpoint_urlr_method_to_api_mapping _partition)r(rarEr@rGmethod_to_api_mappingrjr.r.r/r0es zClientMeta.__init__cCs|jS)N)r)r(r.r.r/rGnszClientMeta.service_modelcCs|jjS)N)rr>)r(r.r.r/r>rszClientMeta.region_namecCs|jS)N)r)r(r.r.r/r@vszClientMeta.endpoint_urlcCs|jS)N)r)r(r.r.r/r]zszClientMeta.configcCs|jS)N)r)r(r.r.r/r~sz ClientMeta.method_to_api_mappingcCs|jS)N)r)r(r.r.r/rjszClientMeta.partitionN) rrrrr0rrGr>r@r]rrjr.r.r.r/rXs      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.)rr9 isinstancedictr_r`)r1rErCZservice_configversionr.r.r/rs   r)6logging functoolsZbotocorerrZ botocore.authrZbotocore.awsrequestrZbotocore.docs.docstringrrZbotocore.exceptionsrr r r Zbotocore.hooksr Zbotocore.modelr Zbotocore.paginaterZbotocore.utilsrrrrrrrZ botocore.argsrZbotocore.compatrrZbotocore.configrZbotocore.historyrZbotocore.discoveryrrr getLoggerrr_robjectrr7rPrrr.r.r.r/ sJ                      F<(/