
    Mg8                         d dl Z d dlZd dlZd dlmZ d dlmZ ddlmZ ddl	m
Z
mZmZ  e j                  e      Zd Zd Z G d	 d
      Z G d d      Z G d d      Z G d d      Z G d d      Zy)    N)WaiterDocstring)get_service_module_name   )
xform_name)ClientErrorWaiterConfigErrorWaiterErrorc                    |j                  |       }t        |j                        }t        t	        ||            }d }t        | |j                  j                  |j                  j                  |d      |_	        t        t        |j                  j                         d|        }t        |t        fd|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                 0    t        j                  | fi | y N)Waiterwait)selfkwargss     ]E:\wamp.anq\www\apps\calme\nutritwin\resources\nutritwin\Lib\site-packages\botocore/waiter.pyr   z'create_waiter_with_client.<locals>.wait6   s    D#F#    F)waiter_nameevent_emitterservice_modelservice_waiter_modelinclude_signaturez.Waiter.r   )
get_waiterr   	operationNormalizedOperationMethodgetattrr   metaeventsr   __doc__strr   typer   )	r   waiter_modelclientsingle_waiter_configoperation_nameoperation_methodr   waiter_class_namedocumented_waiter_clss	            r   create_waiter_with_clientr(      s    $ (22;? 4 > >?N0'$ #kk((kk//)DL "6;;#<#<=
>h{mT
 !!2VI~N !)+; r   c                 P    | j                  d      }t        |t              rd|v ryy)NErrorCodeTF)get
isinstancedict)responseerrors     r   is_valid_waiter_errorr1   O   s&    LL!E%6U?r   c                       e Zd Zd Zd Zy)r   c                     || _         y r   )_client_method)r   client_methods     r   __init__z"NormalizedOperationMethod.__init__W   s
    +r   c                 l    	  | j                   di |S # t        $ r}|j                  cY d }~S d }~ww xY w)N )r4   r   r/   )r   r   es      r   __call__z"NormalizedOperationMethod.__call__Z   s7    	&4&&000 	::	s    	3.33N)__name__
__module____qualname__r6   r:   r8   r   r   r   r   V   s    ,r   r   c                   "    e Zd ZdZd Zd Zd Zy)WaiterModel   c                     |d   | _         |j                  dd      }| j                  |       || _        t	        t        |d   j                                     | _        y)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 <service>*.waiters.json file.  This can be
            obtained from a botocore Loader object as well.

        waitersversionunknownN)_waiter_configr,   _verify_supported_versionrC   listsortedkeyswaiter_names)r   waiter_configrC   s      r   r6   zWaiterModel.__init__d   sZ     ,I6
  ##Iy9&&w/ i(@(E(E(G!HIr   c                 Z    || j                   k7  rt        d| j                    d|       y )Nz7Unsupported waiter version, supported version must be: z#, but version of waiter config is: 	error_msg)SUPPORTED_VERSIONr   )r   rC   s     r   rF   z%WaiterModel._verify_supported_version|   sB    d,,,#  $ 6 67 8,,396  -r   c                 n    	 | j                   |   }t        |      S # t        $ r t        d|       w xY w)NzWaiter does not exist: )rE   KeyError
ValueErrorSingleWaiterConfig)r   r   r#   s      r   r   zWaiterModel.get_waiter   sM    	F#'#6#6{#C  ""677  	F6{mDEE	Fs    4N)r;   r<   r=   rO   r6   rF   r   r8   r   r   r?   r?   a   s    J08r   r?   c                   &    e Zd ZdZd Zed        Zy)rS   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).

    c                 |    || _         |j                  dd      | _        |d   | _        |d   | _        |d   | _        y )Ndescription r   delaymaxAttempts)_configr,   rV   r   rX   max_attempts)r   r#   s     r   r6   zSingleWaiterConfig.__init__   sE    + 033M2F-k:)'2
0?r   c                 j    g }| j                   d   D ]  }t        |      }|j                  |         |S )N	acceptors)rZ   AcceptorConfigappend)r   r]   acceptor_configacceptors       r   r]   zSingleWaiterConfig.acceptors   s:    	#||K8O%o6HX&  9 r   N)r;   r<   r=   r   r6   propertyr]   r8   r   r   rS   rS      s!    @  r   rS   c                   F    e Zd Zd Zed        Zd Zd Zd Zd Z	d Z
d Zy	)
r^   c                     |d   | _         |d   | _        |d   | _        |j                  d      | _        | j                         | _        y )Nstatematcherexpectedargument)re   rf   rg   r,   rh   _create_matcher_funcmatcher_func)r   configs     r   r6   zAcceptorConfig.__init__   sF    G_
i(z*

:. 557r   c                    | j                   dk(  rd| j                   d| j                   dS | j                   dk(  rd| j                   d| j                   dS | j                   dk(  rd| j                   d| j                   dS | j                   d	k(  rd
| j                   S | j                   dk(  rd| j                   S d| j                    dS )NpathzFor expression "z" we matched expected path: ""pathAllz&" all members matched expected path: "pathAnyz" at least oncestatusz#Matched expected HTTP status code: r0   z%Matched expected service error code: z)No explanation for unknown waiter type: ")rf   rh   rg   r   s    r   explanationzAcceptorConfig.explanation   s    <<6!%dmm_4QRVR_R_Q``abb\\Y&"4==/ 2##'==/4 \\Y&"4==/ 2--9 \\X%8HH\\W$:4==/JJ>t||nANNr   c                 j   | j                   dk(  r| j                         S | j                   dk(  r| j                         S | j                   dk(  r| j                         S | j                   dk(  r| j	                         S | j                   dk(  r| j                         S t        d| j                          )Nrm   ro   rp   rq   r0   zUnknown acceptor: rM   )rf   _create_path_matcher_create_path_all_matcher_create_path_any_matcher_create_status_matcher_create_error_matcherr   rr   s    r   ri   z#AcceptorConfig._create_matcher_func   s     <<6!,,..\\Y&0022\\Y&0022\\X%..00\\W$--//#.t||n= r   c                 l    t        j                  | j                        | j                  fd}|S )Nc                 D    t        |       ry j                  |       k(  S r   )r1   search)r/   rg   
expressions    r   acceptor_matchesz=AcceptorConfig._create_path_matcher.<locals>.acceptor_matches   s$    $X.$$X.(::r   jmespathcompilerh   rg   r   r~   rg   r}   s     @@r   ru   z#AcceptorConfig._create_path_matcher   s-    %%dmm4
==	;
  r   c                 l    t        j                  | j                        | j                  fd}|S )Nc                     t        |       ry j                  |       }t        |t              r|sy|D ]	  }|k7  s	 y yNFTr1   r|   r-   rG   r/   resultelementrg   r}   s      r   r~   zAAcceptorConfig._create_path_all_matcher.<locals>.acceptor_matches   sI    $X.&&x0Ffd+6
 !h&  " r   r   r   s     @@r   rv   z'AcceptorConfig._create_path_all_matcher   s-    %%dmm4
==	  r   c                 l    t        j                  | j                        | j                  fd}|S )Nc                     t        |       ry j                  |       }t        |t              r|sy|D ]	  }|k(  s	 y yr   r   r   s      r   r~   zAAcceptorConfig._create_path_any_matcher.<locals>.acceptor_matches  sI    $X.&&x0Ffd+6
 !h& " r   r   r   s     @@r   rw   z'AcceptorConfig._create_path_any_matcher   s-    %%dmm4
==	  r   c                 *    | j                   fd}|S )Nc                 P    | j                  di       j                  d      }|k(  S )NResponseMetadataHTTPStatusCoder,   )r/   status_coderg   s     r   r~   z?AcceptorConfig._create_status_matcher.<locals>.acceptor_matches  s1     #,,'92>BB K (**r   rg   r   r~   rg   s     @r   rx   z%AcceptorConfig._create_status_matcher  s    ==	+  r   c                 *    | j                   fd}|S )Nc                     du rd| v xr d| d   v S du rd| vS | j                  di       j                  dd      k(  S )NTr*   r+   FrW   r   )r/   rg   s    r   r~   z>AcceptorConfig._create_error_matcher.<locals>.acceptor_matches$  s]     4(*Jv'9J/JJU"h..||GR044VR@HLLr   r   r   s     @r   ry   z$AcceptorConfig._create_error_matcher!  s    ==	M"  r   N)r;   r<   r=   r6   rb   rs   ri   ru   rv   rw   rx   ry   r8   r   r   r^   r^      s;    8 O O(0	  * *  r   r^   c                       e Zd Zd Zd Zy)r   c                 .    || _         || _        || _        y)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_methodnamerk   )r   r   rk   r%   s       r   r6   zWaiter.__init__9  s     "2 	r   c           
      X   t        | j                  j                        }d}|j                  di       }|j	                  d| j                  j
                        }|j	                  d| j                  j                        }d }d}	  | j                  di |}	|dz  }|D ]#  }
|
j                  |	      s|
}|
j                  } nZ t        |	      rNt        | j                  dj                  |	d   j	                  d	d
      |	d   j	                  dd
            |	      |dk(  rt        j                  d       y |dk(  r'd
j                    }t        | j                  ||	      ||k\  r,|d}nd
j                    }t        | j                  ||	      t#        j$                  |       ')NwaitingWaiterConfigDelayMaxAttemptsr   r   zAn error occurred ({}): {}r*   r+   UnknownMessage)r   reasonlast_responsesuccessz3Waiting complete, waiter matched the success state.failurez-Waiter encountered a terminal failure state: zMax attempts exceededz2Max attempts exceeded. Previously accepted state: r8   )rG   rk   r]   popr,   rX   r[   r   rj   re   r1   r	   r   formatloggerdebugrs   timesleep)r   r   r]   current_staterk   sleep_amountr[   last_matched_acceptornum_attemptsr/   ra   r   s               r   r   zWaiter.waitN  s   ../	!NB/zz'4;;+<+<=zz-1I1IJ $-t--77HAL%((2,4)$,NNM	 & )2 &!YY;BB$W-11&)D$W-11)YG  '/  	)L 	)HI]I]H^_!!"* 
 |+(04F M#//02  "!"* 
 JJ|$a r   N)r;   r<   r=   r6   r   r8   r   r   r   r   8  s    *:%r   r   )loggingr   r   botocore.docs.docstringr   botocore.utilsr   rW   r   
exceptionsr   r   r	   	getLoggerr;   r   r(   r1   r   r?   rS   r^   r   r8   r   r   <module>r      st       3 2  C C			8	$1h *8 *8Z 6L  L ^P% P%r   