o ?c7@sddlZddlZddlZddlmZddlmZddlmZddl m Z m Z m Z e eZddZd d ZGd d d ZGd ddZGdddZGdddZGdddZdS)N)WaiterDocstring)get_service_module_name) xform_name) ClientErrorWaiterConfigError WaiterErrorc 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/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/botocore/waiter.pyr 6sz'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|trd|vrdSdS)NErrorCodeTF)get isinstancedict)responseerrorrrris_valid_waiter_errorPs r&c@eZdZddZddZdS)rcCs ||_dSr )_client_method)r Z client_methodrrr__init__Xs z"NormalizedOperationMethod.__init__c Ks>z |jdi|WSty}z |jWYd}~Sd}~ww)Nr)r(rr$)r r errr__call__[s z"NormalizedOperationMethod.__call__N)__name__ __module__ __qualname__r)r+rrrrrWs rc@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_versionr2listsortedkeysZ waiter_names)r Z waiter_configr2rrrr)es   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 r2rrrr5}s z%WaiterModel._verify_supported_versioncCs0z |j|}Wt|Stytd|w)NzWaiter does not exist: %s)r4KeyError ValueErrorSingleWaiterConfig)r rrrrrrs   zWaiterModel.get_waiterN)r,r-r.r;r)r5rrrrrr/bs  r/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?rrA max_attempts)r rrrrr)s   zSingleWaiterConfig.__init__cCs*g}|jdD] }t|}||q|S)N acceptors)rBAcceptorConfigappend)r rDZacceptor_configacceptorrrrrDs  zSingleWaiterConfig.acceptorsN)r,r-r.rr)propertyrDrrrrr>s  r>c@sPeZdZddZeddZddZddZd d Zd d Z d dZ ddZ dS)rEcCs8|d|_|d|_|d|_|d|_||_dS)Nstatematcherexpectedargument)rIrJrKr!rL_create_matcher_func matcher_func)r configrrrr)s    zAcceptorConfig.__init__cCs|jdkr d|j|jS|jdkrd|j|jfS|jdkr'd|j|jfS|jdkr1d|jS|jd kr;d |jSd |jS) Npathz2For expression "{}" we matched expected path: "{}"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")rJformatrLrKr rrr explanations*         zAcceptorConfig.explanationcCsj|jdkr |S|jdkr|S|jdkr|S|jdkr$|S|jdkr-|Std|jd)NrPrQrRrSr%zUnknown acceptor: %sr9)rJ_create_path_matcher_create_path_all_matcher_create_path_any_matcher_create_status_matcher_create_error_matcherrrUrrrrMs     z#AcceptorConfig._create_matcher_funcc$t|j|jfdd}|S)Ncst|rdS|kSr )r&searchr$rKZ expressionrracceptor_matchessz=AcceptorConfig._create_path_matcher..acceptor_matchesjmespathcompilerLrKr r`rr_rrWs z#AcceptorConfig._create_path_matchercr\)NcsDt|rdS|}t|tr|sdS|D] }|krdSqdSNFTr&r]r"r6r$resultelementr_rrr` zAAcceptorConfig._create_path_all_matcher..acceptor_matchesrardrr_rrX z'AcceptorConfig._create_path_all_matchercr\)NcsDt|rdS|}t|tr|sdS|D] }|krdSqdSrerfrgr_rrr`rjzAAcceptorConfig._create_path_any_matcher..acceptor_matchesrardrr_rrYrkz'AcceptorConfig._create_path_any_matcherc|jfdd}|S)Ncs|did}|kS)NZResponseMetadataZHTTPStatusCoder!)r$ status_coderKrrr`s z?AcceptorConfig._create_status_matcher..acceptor_matchesrordrrorrZ  z%AcceptorConfig._create_status_matchercrl)Ncs|diddkS)Nrr r@rmr^rorrr`*sz>AcceptorConfig._create_error_matcher..acceptor_matchesrordrrorr['rpz$AcceptorConfig._create_error_matcherN) r,r-r.r)rHrVrMrWrXrYrZr[rrrrrEs   rEc@r')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_methodnamerO)r rrrOrrrrr)7s zWaiter.__init__c Ks,t|jj}d}|di}|d|jj}|d|jj}d}d} |jdi|} |d7}|D]} | | r?| }| j }nq1t | r\t |j d| d d d | d d d f| d |dkrgt ddS|dkrxd| j} t |j | | d ||kr|durd} nd| j} t |j | | d t|q#)NZwaitingZ WaiterConfigZDelayZ MaxAttemptsrTrzAn error occurred (%s): %srr UnknownMessage)rrreasonZ last_responsesuccessz3Waiting complete, waiter matched the success state.Zfailurez/Waiter encountered a terminal failure state: %szMax attempts exceededz4Max attempts exceeded. Previously accepted state: %sr)r6rOrDpopr!rArCrqrNrIr&rrrloggerdebugrVtimesleep) r r rDZ current_staterOZ sleep_amountrCZlast_matched_acceptorZ num_attemptsr$rGrurrrr Lsl     z Waiter.waitN)r,r-r.r)r rrrrr 6s r )loggingrzrbZbotocore.docs.docstringrZbotocore.utilsrr@r exceptionsrrr getLoggerr,rxrr&rr/r>rEr rrrrs      5 -