a 97a6@sddlZddlZddlZddlmZddlmZddlmZm Z m Z ddl m Z e eZddZd d ZGd d d eZGd ddeZGdddeZGdddeZGdddeZdS)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|fi|dSN)Waiterwait)selfkwargsrj/private/var/folders/s6/9n5zrl012gv99k63s4q6ccsd4s6mqz/T/pip-target-f5cq3f2q/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_clsrrrcreate_waiter_with_clients.     rcCs$|d}t|tr d|vr dSdS)NErrorCodeTF)get isinstancedict)responseerrorrrris_valid_waiter_errorNs r&c@seZdZddZddZdS)rcCs ||_dSr )_client_method)r Z client_methodrrr__init__Vsz"NormalizedOperationMethod.__init__c KsBz|jfi|WSty<}z|jWYd}~Sd}~00dSr )r'rr$)r r errr__call__Ysz"NormalizedOperationMethod.__call__N)__name__ __module__ __qualname__r(r*rrrrrUsrc@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_configr!_verify_supported_versionr1listsortedkeysZ waiter_names)r Z waiter_configr1rrrr(cs    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 r1rrrr4{s z%WaiterModel._verify_supported_versioncCs6z|j|}Wnty,td|Yn0t|S)NzWaiter does not exist: %s)r3KeyError ValueErrorSingleWaiterConfig)r rrrrrrs  zWaiterModel.get_waiterN)r+r,r-r:r(r4rrrrrr.`sr.c@s$eZdZdZddZeddZdS)r=zRepresents 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!r>rr@ max_attempts)r rrrrr(s   zSingleWaiterConfig.__init__cCs*g}|jdD]}t|}||q|S)N acceptors)rAAcceptorConfigappend)r rCZacceptor_configacceptorrrrrCs  zSingleWaiterConfig.acceptorsN)r+r,r-rr(propertyrCrrrrr=s r=c@sPeZdZddZeddZddZddZd d Zd d Z d dZ ddZ dS)rDcCs8|d|_|d|_|d|_|d|_||_dS)Nstatematcherexpectedargument)rHrIrJr!rK_create_matcher_func matcher_func)r configrrrr(s     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: %sr%z'Matched expected service error code: %sz,No explanation for unknown waiter type: "%s")rIrKrJr rrr explanations       zAcceptorConfig.explanationcCsn|jdkr|S|jdkr$|S|jdkr6|S|jdkrH|S|jdkrZ|Std|jddS)NrOrPrQrRr%zUnknown acceptor: %sr8)rI_create_path_matcher_create_path_all_matcher_create_path_any_matcher_create_status_matcher_create_error_matcherrrSrrrrLs     z#AcceptorConfig._create_matcher_funccs$t|j|jfdd}|S)Ncst|r dS|kSr )r&searchr$rJZ expressionrracceptor_matchessz=AcceptorConfig._create_path_matcher..acceptor_matchesjmespathcompilerKrJr r]rr\rrUs z#AcceptorConfig._create_path_matchercs$t|j|jfdd}|S)NcsDt|r dS|}t|tr$|s(dS|D]}|kr,dSq,dSNFTr&rZr"r5r$resultelementr\rrr]s zAAcceptorConfig._create_path_all_matcher..acceptor_matchesr^rarr\rrVs z'AcceptorConfig._create_path_all_matchercs$t|j|jfdd}|S)NcsDt|r dS|}t|tr$|s(dS|D]}|kr,dSq,dSrbrcrdr\rrr]s zAAcceptorConfig._create_path_any_matcher..acceptor_matchesr^rarr\rrWs z'AcceptorConfig._create_path_any_matchercs|jfdd}|S)Ncs|did}|kS)NZResponseMetadataZHTTPStatusCoder!)r$ status_coderJrrr]s z?AcceptorConfig._create_status_matcher..acceptor_matchesrirarrirrXs z%AcceptorConfig._create_status_matchercs|jfdd}|S)Ncs|diddkS)Nrr r?rgr[rirrr]sz>AcceptorConfig._create_error_matcher..acceptor_matchesrirarrirrYs z$AcceptorConfig._create_error_matcherN) r+r,r-r(rGrTrLrUrVrWrXrYrrrrrDs   rDc@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_methodnamerN)r rkrNrrrrr( szWaiter.__init__c Ks2t|jj}d}|di}|d|jj}|d|jj}d}d}|jfi|} |d7}|D]} | | r`| }| j }qq`t | rt |j d| dd d | dd d f| d |d krt ddS|dkrd| j} t |j | | d ||kr"|durd} n d| j} t |j | | d t|qDdS)NZwaitingZ WaiterConfigZDelayZ MaxAttemptsrrzAn error occurred (%s): %srr UnknownMessage)rkreasonZ last_responsesuccessz3Waiting complete, waiter matched the success state.Zfailurez/Waiter encountered a terminal failure state: %szMax attempts exceededz4Max attempts exceeded. Previously accepted state: %s)r5rNrCpopr!r@rBrjrMrHr&rrkloggerdebugrTtimesleep) r r rCZ current_staterNZ sleep_amountrBZlast_matched_acceptorZ num_attemptsr$rFrnrrrr 5s^      z Waiter.waitN)r+r,r-r(r rrrrr sr )r_loggingrsZbotocore.utilsrZbotocore.docs.docstringr exceptionsrrrr?r getLoggerr+rqrr&objectrr.r=rDr rrrr s    4 +z