o .&a6@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)selfkwargsr1/usr/lib/python3/dist-packages/botocore/waiter.pyr 4sz'create_waiter_with_client..waitF) waiter_name event_emitter service_modelservice_waiter_modelinclude_signaturez %s.Waiter.%sr ) get_waiterr operationNormalizedOperationMethodgetattrrmetaeventsr__doc__strrtyper ) r waiter_modelclientsingle_waiter_configoperation_nameoperation_methodr waiter_class_namedocumented_waiter_clsrrrcreate_waiter_with_clients.    r%cCs$|d}t|trd|vrdSdS)NErrorCodeTF)get isinstancedict)responseerrorrrris_valid_waiter_errorNs r-c@eZdZddZddZdS)rcCs ||_dSr )_client_method)r client_methodrrr__init__Vs z"NormalizedOperationMethod.__init__c Ks>z |jdi|WSty}z |jWYd}~Sd}~ww)Nr)r/rr+)r r errr__call__Ys z"NormalizedOperationMethod.__call__N)__name__ __module__ __qualname__r1r3rrrrrUs 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_versionr:listsortedkeys waiter_names)r waiter_configr:rrrr1cs   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={s z%WaiterModel._verify_supported_versioncCs0z |j|}Wt|Stytd|w)NzWaiter does not exist: %s)r<KeyError ValueErrorSingleWaiterConfig)r rr rrrrs   zWaiterModel.get_waiterN)r4r5r6rEr1r=rrrrrr7`s  r7c@s$eZdZdZddZeddZdS)rHzRepresents 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 descriptionrdelay maxAttempts)_configr(rIrrK max_attempts)r r rrrr1s   zSingleWaiterConfig.__init__cCs*g}|jdD] }t|}||q|S)N acceptors)rMAcceptorConfigappend)r rOacceptor_configacceptorrrrrOs  zSingleWaiterConfig.acceptorsN)r4r5r6rr1propertyrOrrrrrHs  rHc@sPeZdZddZeddZddZddZd d Zd d Z d dZ ddZ dS)rPcCs8|d|_|d|_|d|_|d|_||_dS)Nstatematcherexpectedargument)rUrVrWr(rX_create_matcher_func matcher_func)r configrrrr1s    zAcceptorConfig.__init__cCs|jdkr d|j|jfS|jdkrd|j|jfS|jdkr'd|j|jfS|jdkr1d|jS|jd kr;d |jSd |jS) 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")rVrXrWr rrr explanations        zAcceptorConfig.explanationcCsj|jdkr |S|jdkr|S|jdkr|S|jdkr$|S|jdkr-|Std|jd)Nr\r]r^r_r,zUnknown acceptor: %srC)rV_create_path_matcher_create_path_all_matcher_create_path_any_matcher_create_status_matcher_create_error_matcherrr`rrrrYs     z#AcceptorConfig._create_matcher_funcc$t|j|jfdd}|S)Ncst|rdS|kSr )r-searchr+rW expressionrracceptor_matchessz=AcceptorConfig._create_path_matcher..acceptor_matchesjmespathcompilerXrWr rlrrjrrbs z#AcceptorConfig._create_path_matchercrg)NcsDt|rdS|}t|tr|sdS|D] }|krdSqdSNFTr-rhr)r>r+resultelementrjrrrl zAAcceptorConfig._create_path_all_matcher..acceptor_matchesrmrprrjrrc z'AcceptorConfig._create_path_all_matchercrg)NcsDt|rdS|}t|tr|sdS|D] }|krdSqdSrqrrrsrjrrrlrvzAAcceptorConfig._create_path_any_matcher..acceptor_matchesrmrprrjrrdrwz'AcceptorConfig._create_path_any_matcherc|jfdd}|S)Ncs|did}|kS)NResponseMetadataHTTPStatusCoder()r+ status_coderWrrrls z?AcceptorConfig._create_status_matcher..acceptor_matchesr}rprr}rres z%AcceptorConfig._create_status_matchercrx)Ncs|diddkS)Nr&r'rJr{rir}rrrlsz>AcceptorConfig._create_error_matcher..acceptor_matchesr}rprr}rrfs z$AcceptorConfig._create_error_matcherN) r4r5r6r1rTrarYrbrcrdrerfrrrrrPs   rPc@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_methodnamer[)r rr[r"rrrr1 s 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#)Nwaiting WaiterConfigDelay MaxAttemptsrTrzAn error occurred (%s): %sr&r'UnknownMessage)rreason last_responsesuccessz3Waiting complete, waiter matched the success state.failurez/Waiter encountered a terminal failure state: %szMax attempts exceededz4Max attempts exceeded. Previously accepted state: %sr)r>r[rOpopr(rKrNr~rZrUr-rrloggerdebugratimesleep) r r rO current_stater[ sleep_amountrNlast_matched_acceptor num_attemptsr+rSrrrrr 5sd     z Waiter.waitN)r4r5r6r1r rrrrr s r )rnloggingrbotocore.utilsrbotocore.docs.docstringr exceptionsrrrrJr getLoggerr4rr%r-objectrr7rHrPr rrrrs     4 +z