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'e(e)Z*e'Z+Gddde,Z-Gddde,Z.Gddde,Z/Gdd d e,Z0d!d"Z1dS)#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_recorderc@seZdZdZd&ddZd'ddZd(dd Zd d Zd)d d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%ZdS)* ClientCreatorz%Creates client objects for a service.Nc Cs4||_||_||_||_||_||_||_||_dS)N)_loader_endpoint_resolver _user_agent_event_emitter_retry_handler_factory_retry_config_translator_response_parser_factory_exceptions_factory) selfloaderendpoint_resolver user_agent event_emitterZretry_handler_factoryZretry_config_translatorresponse_parser_factoryexceptions_factoryr+P/Users/kashii/Desktop/Projects/Workshops/worker-safety/lambda/botocore/client.py__init__1szClientCreator.__init__Tc  Cs|jjd|d} t| |d}|||} ||| } t|j|| | jdd} | | ||||||| | }| f|}| || || || ||S)Nzchoose-service-name) service_name)defaultZ signingName)service_signing_name) remitr _load_service_model_create_client_classClientEndpointBridgermetadataget_get_client_args_register_retries_register_s3_events)r$r. region_name is_secure endpoint_urlverify credentials scoped_config api_version client_config responses service_modelclsendpoint_bridgeZ client_argsZservice_clientr+r+r, create_client=s"      zClientCreator.create_clientcCs|||}|||S)N)r2r3)r$r.r@rCr+r+r,create_client_classTs 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 hyphenizerr1rtypestrtuple) r$r.rCrIZpy_name_to_operation_namebasesrM class_namerDr+r+r,r3Xs   z"ClientCreator._create_client_classcCs"|jj|d|d}t||d}|S)Nz service-2)r@)r.)rload_service_modelr )r$r.r@Z json_modelrCr+r+r,r2fs  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)metarCendpoint_prefixrMrNr load_datar!Zbuild_retry_configr6configretriesloggerdebugr.r Zcreate_retry_handlereventsregister) r$clientrXrMZservice_event_nameZoriginal_configZ retry_confighandlerrVr+r+r,r8ls$       zClientCreator._register_retriescCst|jjjdkrdSt|||||jjj|jj|jj | ||jjjr`|jj dt | |j||dS)Ns3zbefore-sign.s3)rWrCr.rr__set_s3_addressing_stylerZrbr^ partition_is_s3_accelerateregister_firstr!_set_s3_presign_signature_version)r$r`rEr<rAr?r+r+r,r9s z!ClientCreator._register_s3_eventscCs@|dkr i}|||}|||||}|dk r<|d|dS)Nzbefore-sign.s3)_get_s3_addressing_style_get_s3_addressing_handlerr_)r$r< s3_configr(rdaddressing_stylerar+r+r,rcs z&ClientCreator._set_s3_addressing_stylecCs6|dd}|s|||r dS|d}|r2|SdS)Nuse_accelerate_endpointFvirtualrk)r6re)r$r<rjZ accelerateZconfigured_addressing_styler+r+r,rhs   z&ClientCreator._get_s3_addressing_stylecCsB|dkrtdtS|dks&|dk r4tddStdtS)Nrmz'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<rjrkrdr+r+r,ris   z(ClientCreator._get_s3_addressing_handlercCs|dk r|drdS|dkr"dSt|j}|ds:dS|d}|ddkrTdS|dd }t|tt|krxdStd d |DS) NrlTFz amazonaws.com.rz s3-acceleratecss|]}|tkVqdS)N)r).0pr+r+r, sz2ClientCreator._is_s3_accelerate..)r6rnetlocendswithsplitlensetall)r$r<rjrupartsZ feature_partsr+r+r,res     zClientCreator._is_s3_acceleratecCsntd||}|dk rdS|jd|j}|j|kr6dS|jd|j}|d}d|krZdS|jd|jdS)NrbsignatureVersionszchoose-signer.s3) !_get_configured_signature_versionrget_available_endpointsrdr:construct_endpointr^r__default_s3_presign_to_sigv2)r$Z client_metarAr?Zprovided_signature_versionZregionsendpointZsignature_versionsr+r+r,rgs    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-postrbN)rv)r$signature_versionkwargssuffixr+r+r,rs  z*ClientCreator._default_s3_presign_to_sigv2c Cs4t|j|j|j|j|j} | ||||||||| S)N)rrrr"rr#Zget_client_args) r$rCr:r;r<r=r>r?rArEZ args_creatorr+r+r,r7szClientCreator._get_client_argscCs2i}x(|jD]}t|}||||||<q W|S)N)operation_namesr_create_api_method)r$rCZop_dictoperation_namepy_operation_namer+r+r,rJ%s  zClientCreator._create_methodscCs(i}x|jD]}t|}|||<q W|S)N)rr)r$rCmappingrrr+r+r,rK-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$argsr)rrr+r, _api_call8s z3ClientCreator._create_api_method.._api_callzresponse = client.%sF)operation_model method_namer(Zmethod_descriptionZexample_prefixinclude_signature)rP__name__rrrZ documentation__doc__)r$rrrCrrZ docstringr+)rrr,r6s  z ClientCreator._create_api_method)NN)TNNNNNN)N)N)r __module__ __qualname__rr-rFrGr3r2r8r9rcrhrirergrr7rJrKrr+r+r+r,r/s,         rc@sxeZdZdZdZdddZdddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZdS)r4aBridges 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.comNcCs(||_||_||_||_|p |j|_dS)N)r0r&r?rADEFAULT_ENDPOINTdefault_endpoint)r$r&r?rArr0r+r+r,r-_s zClientEndpointBridge.__init__TcCsD|||}|j||}|r0||||||S|||||SdS)N)_check_default_regionr&r_create_endpoint_assume_endpoint)r$r.r:r<r;resolvedr+r+r,resolvehs zClientEndpointBridge.resolvecCs*|dk r |S|jr&|jjdk r&|jjSdS)N)rAr:)r$r.r:r+r+r,rtsz*ClientEndpointBridge._check_default_regionc Cs||||\}}|dkrb||r:||||d|}n(|d|d}||||dg}|||}|||} |j|||| |||dS)NZ dnsSuffixZ sslCommonNamehostnameZ protocols)r.r:signing_region signing_namer<r5r)_pick_region_values_is_s3_dualstack_mode_create_dualstack_endpointr6 _make_url_resolve_signature_version_resolve_signing_name_create_result) r$rr.r:r<r;rrrrr+r+r,r{s$  z%ClientEndpointBridge._create_endpointcCsl|dkr dS|j}|dk r8|jdk r8d|jkr8|jdS|jdkrFdS|jdidd}|dkrhdSdS)NrbFZuse_dualstack_endpoint)TTruetrueT)rArbr?r6)r$r.rAZenabledr+r+r,rs   z*ClientEndpointBridge._is_s3_dualstack_modecCs"dj|||d}|||ddgS)Nz){service}.dualstack.{region}.{dns_suffix})serviceregion dns_suffixhttphttps)formatr)r$r.r: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: %sr|v4)r)r.r:rrrr<r5)rrrr\r]rrr)r$r.r:r<r;rrrr+r+r,rs   z%ClientEndpointBridge._assume_endpointcCs|||||||dS)N)r.r:rrr<rr5r+)r$r.r:rrr<rr5r+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)r0)r$r.rr+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|krDdSxtD]}||krJ|SqJWt|dddS)Nr|rbZs3v4r)r)r}rAr?rr r6)r$r.rZconfigured_versionZpotential_versionsZknownr+r+r,rs z/ClientEndpointBridge._resolve_signature_version)NNNN)NNT)rrrrrr-rrrrrrrrrrrr+r+r+r,r4Rs"      r4c@seZdZiZddZddZddZeddZd d Z dd d Z ddZ ddZ ddZ ddZddZeddZeddZddZd S)rLc Cs\||_||_||_||_i|_||_||_t||j|j||j | |_ | |_ d|_ | dS)N) _serializer _endpointZ_response_parser_request_signer_cacher_client_config ClientMetahostrHrWr# _exceptions_register_handlers) r$Z serializerrZresponse_parserr(request_signerrCr%rArdr*r+r+r,r-s zBaseClient.__init__cCsNd|jj|f}|jjj||d\}}|dk r6|Std|jj|fdS)Nz getattr.%s.%s)r`z!'%s' object has no attribute '%s') _service_modelrMrNrWr^emit_until_responseAttributeError __class__r)r$item event_nameraevent_responser+r+r, __getattr__'szBaseClient.__getattr__cCs*|jjj}|jjd||jjdS)Nzrequest-created.%s)rWrCrMrNr^r_rra)r$rMr+r+r,r6szBaseClient._register_handlerscCs|jjS)N)rWrC)r$r+r+r,r>szBaseClient._service_modelcCs|j|}|jj}td|||d|jr.paginate page_configF)Zpaginator_namer(rCpaginator_configrz%s.Paginator.%srN) can_paginater rHrrrWr^rCrrPrrOrrrgetattr) 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)rrrTrr.r@r rH)r$rrrr+r+r,rs  zBaseClient.can_paginatecCsZd|jkrPy&|j|jjd|jj}||jd<Wntk rNi|jd<YnX|jdS)N waiter_configz waiters-2)rrrTrr.r@r )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_namerZrrrr+r+r, get_waiters     zBaseClient.get_waitercCs*|}|sgSt|}dd|jDS)z(Returns a list of all available waiters.cSsg|] }t|qSr+)r)rrrr+r+r, sz+BaseClient.waiter_names..)rrrr)r$rZrr+r+r,rs  zBaseClient.waiter_namescCs|jdkr||_|jS)N)r_load_exceptions)r$r+r+r,rs  zBaseClient.exceptionscCs|j|jS)N)r#Zcreate_client_exceptionsr)r$r+r+r,rszBaseClient._load_exceptions)N)rrrrHr-rrpropertyrrrrrrrrrrrrr+r+r+r,rL s 2 9  rLc@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)r^r _endpoint_urlr_method_to_api_mapping _partition)r$r^rAr<rCmethod_to_api_mappingrdr+r+r,r-1s zClientMeta.__init__cCs|jS)N)r)r$r+r+r,rC:szClientMeta.service_modelcCs|jjS)N)rr:)r$r+r+r,r:>szClientMeta.region_namecCs|jS)N)r)r$r+r+r,r<BszClientMeta.endpoint_urlcCs|jS)N)r)r$r+r+r,rZFszClientMeta.configcCs|jS)N)r)r$r+r+r,rJsz ClientMeta.method_to_api_mappingcCs|jS)N)r)r$r+r+r,rdNszClientMeta.partitionN) rrrrr-rrCr:r<rZrrdr+r+r+r,r$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.)rr6 isinstancedictr\r])r.rAr?Zservice_configversionr+r+r,r}Ss   r})2logging functoolsbotocorerrZ botocore.authrbotocore.awsrequestrZbotocore.docs.docstringrrbotocore.exceptionsrr r r botocore.hooksr botocore.modelr Zbotocore.paginaterbotocore.utilsrrrrrrrZ botocore.argsrbotocore.compatrrZbotocore.configrZbotocore.historyr getLoggerrr\robjectrr4rLrr}r+r+r+r, sH                      %;/