
     hw9                        d dl Z d dlZd dlm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 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)partial)with_current_context)WaiterDocstring)register_feature_id)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     k/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/botocore/waiter.pyr   z'create_waiter_with_client.<locals>.wait9   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_errorr4   R   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__Z   s
    +r   c                 l    	  | j                   di |S # t        $ r}|j                  cY d }~S d }~ww xY w)N )r7   r
   r2   )r   r   es      r   __call__z"NormalizedOperationMethod.__call__]   s7    	&4&&000 	::	s    	3.33N)__name__
__module____qualname__r9   r=   r;   r   r   r   r   Y   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_versionrF   listsortedkeyswaiter_names)r   waiter_configrF   s      r   r9   zWaiterModel.__init__g   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   rF   s     r   rI   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: )rH   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@   rR   r9   rI   r   r;   r   r   rB   rB   d   s    J08r   rB   c                   &    e Zd ZdZd Zed        Zy)rV   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/   rY   r   r[   max_attempts)r   r&   s     r   r9   zSingleWaiterConfig.__init__   sE    + 033M2F-k:)'2
0?r   c                 j    g }| j                   d   D ]  }t        |      }|j                  |         |S )N	acceptors)r]   AcceptorConfigappend)r   r`   acceptor_configacceptors       r   r`   zSingleWaiterConfig.acceptors   s?    	#||K8 	'O%o6HX&	' r   N)r>   r?   r@   r!   r9   propertyr`   r;   r   r   rV   rV      s!    @  r   rV   c                   F    e Zd Zd Zed        Zd Zd Zd Zd Z	d Z
d Zy	)
ra   c                     |d   | _         |d   | _        |d   | _        |j                  d      | _        | j                         | _        y )Nstatematcherexpectedargument)rh   ri   rj   r/   rk   _create_matcher_funcmatcher_func)r   configs     r   r9   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: r3   z%Matched expected service error code: z)No explanation for unknown waiter type: ")ri   rk   rj   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                          )Nrp   rr   rs   rt   r3   zUnknown acceptor: rP   )ri   _create_path_matcher_create_path_all_matcher_create_path_any_matcher_create_status_matcher_create_error_matcherr   ru   s    r   rl   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   )r4   search)r2   rj   
expressions    r   acceptor_matchesz=AcceptorConfig._create_path_matcher.<locals>.acceptor_matches   s$    $X.$$X.(::r   jmespathcompilerk   rj   r   r   rj   r   s     @@r   rx   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r4   r   r0   rJ   r2   resultelementrj   r   s      r   r   zAAcceptorConfig._create_path_all_matcher.<locals>.acceptor_matches   sN    $X.&&x0Ffd+6
 ! !h& ! r   r   r   s     @@r   ry   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  sN    $X.&&x0Ffd+6
 !  h&  r   r   r   s     @@r   rz   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/   )r2   status_coderj   s     r   r   z?AcceptorConfig._create_status_matcher.<locals>.acceptor_matches  s1     #,,'92>BB K (**r   rj   r   r   rj   s     @r   r{   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.   FrZ   r   )r2   rj   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   r|   z$AcceptorConfig._create_error_matcher$  s    ==	M"  r   N)r>   r?   r@   r9   re   rv   rl   rx   ry   rz   r{   r|   r;   r   r   ra   ra      s;    8 O O(0	  * *  r   ra   c                   <    e Zd Zd Z e eed            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namern   )r   r   rn   r(   s       r   r9   zWaiter.__init__<  s     "2 	r   WAITERc           
      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: r;   )rJ   rn   r`   popr/   r[   r^   r   rm   rh   r4   r   r   formatloggerdebugrv   timesleep)r   r   r`   current_statern   sleep_amountr^   last_matched_acceptornum_attemptsr2   rd   r   s               r   r   zWaiter.waitQ  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  '/  	)I 	)HI]I]H^_!!"* 
 |+(04F M#//02  "!"* 
 JJ|$a r   N)r>   r?   r@   r9   r   r   r   r   r;   r   r   r   r   ;  s)    * '"5x@A:% B:%r   r   )loggingr   	functoolsr   r   botocore.contextr   botocore.docs.docstringr   botocore.useragentr   botocore.utilsr   rZ   r	   
exceptionsr
   r   r   	getLoggerr>   r   r+   r4   r   rB   rV   ra   r   r;   r   r   <module>r      s}        1 3 2 2  C C			8	$1h *8 *8Z 6L  L ^Q% Q%r   