o ?c9@sddlZddlZddlZddlmZmZddlmZddlm Z ddl m Z ddl m Z mZmZddlmZmZddlmZmZmZmZdd lmZdd lmZdd lmZmZdd lm Z dd l!m"Z"ddl#m$Z$m%Z%ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1ddlm2Z2ddlmZddlm3Z3e4e5Z6eZ7GdddZ8GdddZ9GdddZ:GdddZ;ddZr typestrtuple) r/r:rUr[Zpy_name_to_operation_namebasesr_ class_namerVr6r6r7r@s   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.)replacer!mergeloggerwarning)r/rKrRZnormalized_region_nameZconfig_use_fips_endpointr6r6r7rAs$  z$ClientCreator._normalize_fips_regioncCs"|jj|d|d}t||d}|S)Nz service-2)rQr9)r&load_service_modelr)r/r:rQZ json_modelrUr6r6r7r?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_moder6r6r7rFs zClientCreator._register_retriescCs<|jjjd}d|i}|dur||d<tjdi|dS)Ntotal_max_attemptsru max_attemptsr6)rorprqrDrregister_retry_handler)r/rurxkwargsr6r6r7rrs z+ClientCreator._register_v2_standard_retriescCst|dSr%)rry)r/rur6r6r7rssz+ClientCreator._register_v2_adaptive_retriesc Cs|jjj}|jjj}|}|jd}|sdS||jjj }|j || di| di|}t d|jjj|j||}d|} |jjjd||| ddS)NZ_retryretryZ definitionsz*Registering retry handlers for service: %szretry-config-%sz needs-retry.) unique_id)rorUendpoint_prefixr_r`r&Z load_data_transform_legacy_retriesrprqr+Zbuild_retry_configrDrjdebugr:r*Zcreate_retry_handlereventsregister) r/rur}r_Zservice_event_nameZoriginal_configrqZ retry_confighandlerr|r6r6r7rts0       z&ClientCreator._register_legacy_retriescCs:|durdS|}d|vr|}|dd|d<|S)Nrwrx)copypop)r/rqZ copied_argsr6r6r7r~s z'ClientCreator._transform_legacy_retriescCs6|jjj}|dur|ddur|dS|dpdS)Nrmrvrn)rorprqrDget_config_variable)r/rur5Zclient_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)Zalways_discoverzbefore-parameter-build)rorUZendpoint_discovery_operationrr_r`rr.r$_normalize_endpoint_discovery_config_requires_endpoint_discoveryrrrr ) r/rurMrprr_enabledZdiscovermanagerrr6r6r7rJs2 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)Z config_value) isinstancerblowerstriprboolr )r/rr6r6r7r:s    z2ClientCreator._normalize_endpoint_discovery_configcCs|dkr |jjjS|S)Nr)rorUZendpoint_discovery_required)r/rurr6r6r7rGs z*ClientCreator._requires_endpoint_discoverycCs4|jjjdkr dSt|j|jj|d|jjdS)Nr)r1regionrM)rorUr:rr'rKrr)r/rurWrMr6r6r7rGLsz*ClientCreator._register_eventbridge_eventscCs||jjjdkr dSt||t|jj|jjj}t |j |jj |jjj ||jj |d|jj||j||dS)Ns3r1rZ s3_configrM partitionrg)rorUr:rrrrrprgrr'rKrr!_set_s3_presign_signature_versionr/rurWrMrRrPrgr6r6r7rHWs"  z!ClientCreator._register_s3_eventscCs^|jjjdkr dS|jjj}t|jjt|j |jj |jjj ||jj |d|jjdS)NZ s3controlr) rorUr:rprgrrrrr'rKrrrr6r6r7rIps 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'Zget_available_endpointsrrKconstruct_endpointrr_default_s3_presign_to_sigv2)r/Z client_metarRrPZprovided_signature_versionZregionsendpointZsignature_versionsr6r6r7rs,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_versionrzsuffixr6r6r7rs   z*ClientCreator._default_s3_presign_to_sigv2c Cs<t|j|j|j|j|j|jd} | ||||||||| | S)N)r5)rr)r(r,r&r-r.Zget_client_args) r/rUrKrLrMrNrOrPrRrWrSZ args_creatorr6r6r7rEs( zClientCreator._get_client_argscCs.i}|jD]}t|}||||||<q|Sr%)operation_namesr_create_api_method)r/rUZop_dictoperation_namepy_operation_namer6r6r7r\s  zClientCreator._create_methodscCs$i}|jD] }t|}|||<q|Sr%)rr)r/rUmappingrrr6r6r7r]s   z"ClientCreator._create_name_mappingcsHfdd}t|_|}t||j|jddd}||_|S)Ncs|r td||S)Nz"() only accepts keyword arguments.) TypeError_make_api_call)r/argsrzrrr6r7 _api_calls  z3ClientCreator._create_api_method.._api_callzresponse = client.%sF)operation_model method_namer3Zmethod_descriptionZexample_prefixinclude_signature)rb__name__rr r)Z documentation__doc__)r/rrrUrr docstringr6rr7rs z ClientCreator._create_api_method)NNN)TNNNNNNNr%)r __module__ __qualname__rr8rXrYr@rAr?rFrrrsrtr~rrJrrrGrHrIrrrEr\r]rr6r6r6r7r$DsJ   A      +" r$c@seZdZdZdZddgZ     d!ddZ d"d d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd ZdS)#rBaBridges 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=r1rPrRDEFAULT_ENDPOINTdefault_endpointr5)r/r1rPrRrr=r5r6r6r7r8"s    zClientEndpointBridge.__init__TcCst|||}||}|d}|jj||||d}|s'|jj||d||d}|r2||||||S|||||S)Nrg)use_dualstack_endpointrgZaws)Zpartition_namerrg)_check_default_region_resolve_use_dualstack_endpoint$_resolve_endpoint_variant_config_varr1r_create_endpoint_assume_endpoint)r/r:rKrMrLrrgresolvedr6r6r7resolve2s8   zClientEndpointBridge.resolvecCs.|dur|S|jr|jjdur|jjSdSdSr%)rRrK)r/r:rKr6r6r7rYs z*ClientEndpointBridge._check_default_regionc Cs||||\}}|durH|d}|d}ttjdd} | s=|dur=||kr=tjd|d|d|dtd |}||||d g}| ||} | ||} |j |||| ||| d S) N sslCommonNamehostnameZBOTO_DISABLE_COMMONNAMEFzThe z2 client is currently using a deprecated endpoint: z2. In the next minor version this will be moved to zD. See https://github.com/boto/botocore/issues/2705 for more details.)category protocols)r:rKsigning_region signing_namerMrCr) _pick_region_valuesrDrosenvironwarningswarn FutureWarning _make_url_resolve_signature_version_resolve_signing_name_create_result) r/rr:rKrMrLrrrZ is_disabledrrr6r6r7r`sP    z%ClientEndpointBridge._create_endpointcCs@|j}d}|rt||durt||S|jdur|j|}|S)NF)rRgetattrr5r)r/Z config_varrRZ config_valr6r6r7rs   z9ClientEndpointBridge._resolve_endpoint_variant_config_varcCs ||}|dur |S|dS)Nr)_is_s3_dualstack_moder)r/r:Zs3_dualstack_moder6r6r7rs z4ClientEndpointBridge._resolve_use_dualstack_endpointcCsl||jvrdS|j}|dur|jdurd|jvr|jdS|jdur2|jdid}|dvr4dSdSdS)Nrr)TTruerT)_DUALSTACK_CUSTOMIZED_SERVICESrRrrPrD)r/r:rRrr6r6r7rs$   z*ClientEndpointBridge._is_s3_dualstack_modec Cs~|dur|jj||d}|||ddg}td|d|d|||ddgi}|j|id }|j||||||id S) N)servicerhttphttpszAssuming an endpoint for z, z: rv4)r)r:rKrrrrMrC)rformatrrjrrrr)r/r:rKrMrLrrrr6r6r7rs.  z%ClientEndpointBridge._assume_endpointcCs|||||||dS)N)r:rKrrrMrrCr6)r/r:rKrrrMrrCr6r6r7rs z#ClientEndpointBridge._create_resultcCs$|r d|vr d}nd}|d|S)Nrrz://r6)r/rrLZsupported_protocolsschemer6r6r7rs zClientEndpointBridge._make_urlcCs0d|vrd|dvr|ddS|jr|jS|S)NcredentialScoper)r=)r/r:rr6r6r7rs  z*ClientEndpointBridge._resolve_signing_namecCs@|}|dur|d}|}d|vrd|dvr|dd}||fS)NZ endpointNamerrr6)r/rrKrMrr6r6r7rs   z(ClientEndpointBridge._pick_region_valuescCsnt||j|j}|dur|Sd|vr/|d}|dkrdSd|vr"dS|D] }|tvr.|Sq$t|dd)NrrZs3v4r)r)rrRrPrrrD)r/r:rZconfigured_versionZpotential_versionsZknownr6r6r7rs$ z/ClientEndpointBridge._resolve_signature_version)NNNNN)NNT)rrrrrrr8rrrrrrrrrrrrr6r6r6r7rBs.   '+  rBc@seZdZiZddZddZddZddZed d Z d d Z d dZ d"ddZ ddZ ddZddZddZddZeddZeddZd d!ZdS)#r^c Cs\||_||_||_||_i|_||_||_t||j|j||j | |_ | |_ d|_ | dSr%) _serializer _endpointZ_response_parser_request_signer_cacher&_client_config ClientMetahostrZror- _exceptions_register_handlers) r/ serializerrZresponse_parserr3request_signerrUr0rRrr4r6r6r7r82s$  zBaseClient.__init__cCsX|jj}d|d|}|jjj||d\}}|dur|Std|jjd|d)Nzgetattr..)ru'z' object has no attribute ') _service_modelr_r`roremit_until_responseAttributeError __class__r)r/itemr_Z event_namerevent_responser6r6r7 __getattr__Rs  zBaseClient.__getattr__cCs|jdS)z'Closes underlying endpoint connections.N)rcloser/r6r6r7raszBaseClient.closecCs,|jjj}|jjd||jjdS)Nzrequest-created.)rorUr_r`rrrr)r/r_r6r6r7reszBaseClient._register_handlerscC|jjSr%)rorUrr6r6r7rlzBaseClient._service_modelcCs*|j|}|jj}td|||d|jrtd|||jj |jj |j |j d}|j |||d}t||||jj}|jjjdj||d|||j|d\}} | dur\| \} } n t|||||\} } |jjjd j||d| | ||d | jd kr| d id } |j| } | | || S)NZAPI_CALL)rZ operationparamszWarning: %s.%s() is deprecated)Z client_regionrRhas_streaming_input auth_type)contextz)before-call.{service_id}.{operation_name}r_r)modelrrrz(after-call.{service_id}.{operation_name}) http_responseparsedrri,ErrorZCode)rrr:history_recorderrecord deprecatedrjrrorKrprr_convert_to_request_dictrr_r`rrrrr _make_requestr> status_coderD exceptionsZ from_code)r/r api_paramsrr:request_context request_dictr_rrrZparsed_responseZ error_codeZ error_classr6r6r7rpsh        zBaseClient._make_api_callc CsTz|j||WSty)}z|jjjdj|jj |j d||dd}~ww)Nz.after-call-error.{service_id}.{operation_name}r) exceptionr) rZ make_request Exceptionrorr>rrr_r`name)r/rrrer6r6r7rs zBaseClient._make_requestNcCsL||||}|j||}|jjs|ddt||jj|jj |d|S)N host_prefix)rMr2r) _emit_api_paramsrZserialize_to_requestrZinject_host_prefixrrrrr2)r/rrrrr6r6r7rs z#BaseClient._convert_to_request_dictcCsf|j}|jj}|jjjd|d||||d}t||d}|jjjd|d||||d|S)Nzprovide-client-params.r)rrrr;zbefore-parameter-build.)rrr_r`rorr>r)r/rrrrr_rTr6r6r7r s   zBaseClient._emit_api_paramsc Cs||s t|d|j|}dd}|jd|}t||jj|jj|dd|_t |jj}|d|}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/rzr6r6r7r sz*BaseClient.get_paginator..paginate page_configF)Zpaginator_namer3rUpaginator_configrz .Paginator.r ) can_paginaterrZrr rorrUrr rarrrr) r/ractual_operation_namer r Zservice_module_nameZpaginator_class_nameZdocumented_paginator_clsrZ paginatorr6r6r7 get_paginators>      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-1Z pagination)rr&rlrr:rQr rZ)r/rr rr6r6r7r )s   zBaseClient.can_paginatecCsXd|jvr'z|j|jjd|jj}||jd<Wnty&i|jd<Ynw|jdS)N waiter_configz waiters-2)rr&rlrr:rQr )r/rr6r6r7_get_waiter_configEs   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)r ValueErrorr WaiterModel waiter_namesrZcreate_waiter_with_client)r/Z waiter_namerprrrr6r6r7 get_waiterRs      zBaseClient.get_waitercCs*|}|sgSt|}dd|jDS)z(Returns a list of all available waiters.cSsg|]}t|qSr6)r).0rr6r6r7 ssz+BaseClient.waiter_names..)rrrr)r/rprr6r6r7rjs  zBaseClient.waiter_namescCs|jdur ||_|jSr%)r_load_exceptionsrr6r6r7rus  zBaseClient.exceptionscCs|j|jSr%)r-Zcreate_client_exceptionsrrr6r6r7r{szBaseClient._load_exceptionsr%)rrrrZr8rrrpropertyrrrrr rr rrrrrrr6r6r6r7r^(s,  > A    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/rrRrMrUmethod_to_api_mappingrr6r6r7r8s   zClientMeta.__init__cC|jSr%)rrr6r6r7rUzClientMeta.service_modelcCrr%)rrKrr6r6r7rKrzClientMeta.region_namecCrr%)rrr6r6r7rMrzClientMeta.endpoint_urlcCrr%)rrr6r6r7rprzClientMeta.configcCrr%)rrr6r6r7rrz ClientMeta.method_to_api_mappingcCrr%)rrr6r6r7rrzClientMeta.partitionN) rrrrr8rrUrKrMrprrr6r6r6r7rs      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.)rrDrdictrjr)r:rRrPZservice_configversionr6r6r7rs   r)=loggingrrZbotocorerrZ botocore.argsrZ botocore.authrZbotocore.awsrequestrZbotocore.discoveryrrr Zbotocore.docs.docstringr r Zbotocore.exceptionsr r rrZbotocore.historyrZbotocore.hooksrZbotocore.httpchecksumrrZbotocore.modelrZbotocore.paginaterZbotocore.retriesrrZbotocore.utilsrrrrrrrrr Zbotocore.configr!r"r# getLoggerrrjrr$rBr^rrr6r6r6r7sF        ,     S[ 6