B -<`$6@sddlZddlZddlZddlmZddlmZddlmZm Z m Z ddl m Z e eZddZGd d d eZGd d d eZGd ddeZGdddeZGdddeZdS)N)get_service_module_name)WaiterDocstring) WaiterError ClientErrorWaiterConfigError) xform_namec Cs|||}t|j}tt||}dd}t||jj|jj|dd|_ t dt |jj|f}t |t fd|i}||||S)a :type waiter_name: str :param waiter_name: The name of the waiter. The name should match the name (including the casing) of the key name in the waiter model file (typically this is CamelCasing). :type waiter_model: botocore.waiter.WaiterModel :param waiter_model: The model for the waiter configuration. :type client: botocore.client.BaseClient :param client: The botocore client associated with the service. :rtype: botocore.waiter.Waiter :return: The waiter object. c[stj|f|dS)N)Waiterwait)selfkwargsr 6/tmp/pip-target-7cdyy134/lib/python/botocore/waiter.pyr 4sz'create_waiter_with_client..waitF) waiter_nameZ event_emitter service_modelZservice_waiter_modelZinclude_signaturez %s.Waiter.%sr ) get_waiterr operationNormalizedOperationMethodgetattrrmetaeventsr__doc__strrtyper ) rZ waiter_modelclientsingle_waiter_configZoperation_nameoperation_methodr Zwaiter_class_nameZdocumented_waiter_clsr r rcreate_waiter_with_clients$      rc@seZdZddZddZdS)rcCs ||_dS)N)_client_method)r Z client_methodr r r__init__Osz"NormalizedOperationMethod.__init__c Ks6y |jf|Stk r0}z|jSd}~XYnXdS)N)rrresponse)r r er r r__call__Rs z"NormalizedOperationMethod.__call__N)__name__ __module__ __qualname__rr"r r r rrNsrc@s(eZdZdZddZddZddZdS) WaiterModelcCs@|d|_|dd}||||_tt|d|_dS)a Note that the WaiterModel takes ownership of the waiter_config. It may or may not mutate the waiter_config. If this is a concern, it is best to make a copy of the waiter config before passing it to the WaiterModel. :type waiter_config: dict :param waiter_config: The loaded waiter config from the *.waiters.json file. This can be obtained from a botocore Loader object as well. waitersversionunknownN)_waiter_configget_verify_supported_versionr)listsortedkeysZ waiter_names)r Z waiter_configr)r r rr\s    zWaiterModel.__init__cCs"||jkrtd|j|fddS)Nz^Unsupported waiter version, supported version must be: %s, but version of waiter config is: %s) error_msg)SUPPORTED_VERSIONr)r r)r r rr-ts  z%WaiterModel._verify_supported_versioncCs8y|j|}Wn tk r.td|YnXt|S)NzWaiter does not exist: %s)r+KeyError ValueErrorSingleWaiterConfig)r rrr r rr|s zWaiterModel.get_waiterN)r#r$r%r2rr-rr r r rr&Ysr&c@s$eZdZdZddZeddZdS)r5zRepresents the waiter configuration for a single waiter. A single waiter is considered the configuration for a single value associated with a named waiter (i.e TableExists). cCs6||_|dd|_|d|_|d|_|d|_dS)N descriptionrdelayZ maxAttempts)_configr,r6rr8 max_attempts)r rr r rrs   zSingleWaiterConfig.__init__cCs.g}x$|jdD]}t|}||qW|S)N acceptors)r9AcceptorConfigappend)r r;Zacceptor_configacceptorr r rr;s zSingleWaiterConfig.acceptorsN)r#r$r%rrpropertyr;r r r rr5s r5c@sPeZdZddZeddZddZddZd d Zd d Z d dZ ddZ dS)r<cCs8|d|_|d|_|d|_|d|_||_dS)Nstatematcherexpectedargument)r@rArBr,rC_create_matcher_func matcher_func)r configr r rrs     zAcceptorConfig.__init__cCs|jdkrd|j|jfS|jdkr4d|j|jfS|jdkrNd|j|jfS|jdkrbd|jS|jd krvd |jSd |jSdS) Npathz2For expression "%s" we matched expected path: "%s"pathAllz;For expression "%s" all members matched excepted path: "%s"pathAnyz@For expression "%s" we matched expected path: "%s" at least oncestatusz%Matched expected HTTP status code: %serrorz'Matched expected service error code: %sz,No explanation for unknown waiter type: "%s")rArCrB)r r r r explanations       zAcceptorConfig.explanationcCsn|jdkr|S|jdkr$|S|jdkr6|S|jdkrH|S|jdkrZ|Std|jddS)NrGrHrIrJrKzUnknown acceptor: %s)r1)rA_create_path_matcher_create_path_all_matcher_create_path_any_matcher_create_status_matcher_create_error_matcherr)r r r rrDs     z#AcceptorConfig._create_matcher_funccs$t|j|jfdd}|S)Ncsd|kr dS|kS)NError)search)r )rB expressionr racceptor_matchessz=AcceptorConfig._create_path_matcher..acceptor_matches)jmespathcompilerCrB)r rUr )rBrTrrMs z#AcceptorConfig._create_path_matchercs$t|j|jfdd}|S)NcsFd|kr dS|}t|tr$|s(dSx|D]}|kr.dSq.WdS)NrRFT)rS isinstancer.)r resultelement)rBrTr rrUs  zAAcceptorConfig._create_path_all_matcher..acceptor_matches)rVrWrCrB)r rUr )rBrTrrNs z'AcceptorConfig._create_path_all_matchercs$t|j|jfdd}|S)NcsFd|kr dS|}t|tr$|s(dSx|D]}|kr.dSq.WdS)NrRFT)rSrXr.)r rYrZ)rBrTr rrUs  zAAcceptorConfig._create_path_any_matcher..acceptor_matches)rVrWrCrB)r rUr )rBrTrrOs z'AcceptorConfig._create_path_any_matchercs|jfdd}|S)Ncs|did}|kS)NZResponseMetadataZHTTPStatusCode)r,)r status_code)rBr rrUs z?AcceptorConfig._create_status_matcher..acceptor_matches)rB)r rUr )rBrrPs z%AcceptorConfig._create_status_matchercs|jfdd}|S)Ncs|diddkS)NrRCoder7)r,)r )rBr rrU sz>AcceptorConfig._create_error_matcher..acceptor_matches)rB)r rUr )rBrrQ s z$AcceptorConfig._create_error_matcherN) r#r$r%rr?rLrDrMrNrOrPrQr r r rr<s   r<c@seZdZddZddZdS)r cCs||_||_||_dS)a :type name: string :param name: The name of the waiter :type config: botocore.waiter.SingleWaiterConfig :param config: The configuration for the waiter. :type operation_method: callable :param operation_method: A callable that accepts **kwargs and returns a response. For example, this can be a method from a botocore client. N)_operation_methodnamerF)r r^rFrr r rrszWaiter.__init__c Ks4t|jj}d}|di}|d|jj}|d|jj}d}d}x|jf|} |d7}xZ|D]} | | r`| }| j }Pq`Wd| krt |j d| dd d | dd d f| d |d krt ddS|dkrd| j} t |j | | d ||kr"|dkrd} n d| j} t |j | | d t|qFWdS)NZwaitingZ WaiterConfigZDelayZ MaxAttemptsrrrRzAn error occurred (%s): %sr\UnknownMessage)r^reasonZ last_responsesuccessz3Waiting complete, waiter matched the success state.Zfailurez/Waiter encountered a terminal failure state: %szMax attempts exceededz4Max attempts exceeded. Previously accepted state: %s)r.rFr;popr,r8r:r]rEr@rr^loggerdebugrLtimesleep) r r r;Z current_staterFZ sleep_amountr:Zlast_matched_acceptorZ num_attemptsr r>rar r rr .sT        z Waiter.waitN)r#r$r%rr r r r rr sr )rVloggingrfZbotocore.utilsrZbotocore.docs.docstringr exceptionsrrrr7r getLoggerr#rdrobjectrr&r5r<r r r r r s    4 +z