U m^0@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|dSN)Waiterwait)selfkwargsri/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/botocore/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_clients6    rc@seZdZddZddZdS)rcCs ||_dSr )_client_method)r Z client_methodrrr__init__Osz"NormalizedOperationMethod.__init__c Ks@z|jf|WStk r:}z|jWYSd}~XYnXdSr )rrresponse)r r errr__call__Rsz"NormalizedOperationMethod.__call__N)__name__ __module__ __qualname__r r#rrrrrNsrc@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*rrrr \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*rrrr.ts z%WaiterModel._verify_supported_versioncCs8z|j|}Wn tk r.td|YnXt|S)NzWaiter does not exist: %s)r,KeyError ValueErrorSingleWaiterConfig)r rrrrrr|s zWaiterModel.get_waiterN)r$r%r&r4r r.rrrrrr'Ysr'c@s$eZdZdZddZeddZdS)r7zRepresents 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-r8rr: max_attempts)r rrrrr s   zSingleWaiterConfig.__init__cCs*g}|jdD]}t|}||q|S)N acceptors)r;AcceptorConfigappend)r r=Zacceptor_configacceptorrrrr=s  zSingleWaiterConfig.acceptorsN)r$r%r&rr propertyr=rrrrr7s r7c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)r>cCs8|d|_|d|_|d|_|d|_||_dS)Nstatematcherexpectedargument)rBrCrDr-rE_create_matcher_func matcher_func)r configrrrr s     zAcceptorConfig.__init__cCsn|jdkr|S|jdkr$|S|jdkr6|S|jdkrH|S|jdkrZ|Std|jddS)NpathZpathAllZpathAnystatuserrorzUnknown acceptor: %sr2)rC_create_path_matcher_create_path_all_matcher_create_path_any_matcher_create_status_matcher_create_error_matcherr)r rrrrFs     z#AcceptorConfig._create_matcher_funccs$t|j|jfdd}|S)Ncsd|kr dS|kS)NError)searchr!rDZ expressionrracceptor_matchessz=AcceptorConfig._create_path_matcher..acceptor_matchesjmespathcompilerErDr rUrrTrrLs z#AcceptorConfig._create_path_matchercs$t|j|jfdd}|S)NcsDd|kr dS|}t|tr$|s(dS|D]}|kr,dSq,dSNrQFTrR isinstancer/r!resultelementrTrrrUs zAAcceptorConfig._create_path_all_matcher..acceptor_matchesrVrYrrTrrMs z'AcceptorConfig._create_path_all_matchercs$t|j|jfdd}|S)NcsDd|kr dS|}t|tr$|s(dS|D]}|kr,dSq,dSrZr[r]rTrrrUs zAAcceptorConfig._create_path_any_matcher..acceptor_matchesrVrYrrTrrNs z'AcceptorConfig._create_path_any_matchercs|jfdd}|S)Ncs|did}|kS)NZResponseMetadataZHTTPStatusCoder-)r! status_coderDrrrUs z?AcceptorConfig._create_status_matcher..acceptor_matchesrbrYrrbrrOs z%AcceptorConfig._create_status_matchercs|jfdd}|S)Ncs|diddkS)NrQZCoder9r`rSrbrrrUsz>AcceptorConfig._create_error_matcher..acceptor_matchesrbrYrrbrrPs z$AcceptorConfig._create_error_matcherN) r$r%r&r rFrLrMrNrOrPrrrrr>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_methodnamerH)r rdrHrrrrr szWaiter.__init__c Kst|jj}d}|di}|d|jj}|d|jj}d}|jf|}|d7}|D]} | |rX| j }qqXd|krt |j |ddd |d |d krt d dS|d krt |j d|d ||krt |j d|d t|q@dS)NZwaitingZ WaiterConfigZDelayZ MaxAttemptsrrrQMessageUnknown)rdreasonZ last_responsesuccessz3Waiting complete, waiter matched the success state.Zfailurez+Waiter encountered a terminal failure statezMax attempts exceeded)r/rHr=popr-r:r<rcrGrBrrdloggerdebugtimesleep) r r r=Z current_staterHZ sleep_amountr<Z num_attemptsr!r@rrrr sD     z Waiter.waitN)r$r%r&r r rrrrr sr )rWloggingrlZbotocore.utilsrZbotocore.docs.docstringr exceptionsrrrr9r getLoggerr$rjrobjectrr'r7r>r rrrr s    4 +k