
                         >    S r SSKJr  SSKrSSKJr   " S S\5      rg)z3Base class for implementing RPC of API proxy stubs.    )absolute_importN)
six_subsetc                       \ rS rSrSrSrSrSr  SS jrS r	  SS	 jr
S
 rS r\S 5       r\S 5       rS rS rS rSrg)RPC    zBase class for implementing RPC of API proxy stubs.

To implement a RPC to make real asynchronous API call:
  - Extend this class.
  - Override _MakeCallImpl and/or _WaitImpl to do a real asynchronous call.
r         Nc                     SU l         [        R                  U l        SU l        Xl        X l        X0l        X@l        XPl	        X`l
        Xpl        SU l        g)a  Constructor for the RPC object.

All arguments are optional, and simply set members on the class.
These data members will be overriden by values passed to MakeCall.

Args:
  package: string, the package for the call
  call: string, the call within the package
  request: ProtocolMessage instance, appropriate for the arguments
  response: ProtocolMessage instance, appropriate for the response
  callback: callable, called when call is complete
  deadline: A double specifying the deadline for this call as the number of
            seconds from the current time. Ignored if non-positive.
  stub: APIProxyStub instance, used in default _WaitImpl to do real call
Nr   )
_exceptionr   IDLE_state
_tracebackpackagecallrequestresponsecallbackdeadlinestubcpu_usage_mcycles)selfr   r   r   r   r   r   r   s           0lib/googlecloudsdk/appengine/api/apiproxy_rpc.py__init__RPC.__init__,   sH    " DO((DKDOLILMMMID    c                     U R                   [        R                  :w  a  [        S5      eU R	                  5       nU R
                  R                  5        H  u  p#[        XU5        M     U$ )zMake a shallow copy of this instances attributes, excluding methods.

This is usually used when an RPC has been specified with some configuration
options and is being used as a template for multiple RPCs outside of a
developer's easy control.
z'Cannot clone a call already in progress)stater   r   AssertionError	__class____dict__itemssetattr)r   clonekvs       r   Clone	RPC.CloneJ   sT     zzSXXDEENNE##%e &Lr   c                 0   U=(       d    U R                   U l         U=(       d    U R                  U l        U=(       d    U R                  U l        U=(       d    U R                  U l        U=(       d    U R                  U l        U=(       d    U R
                  U l        U R                  [        R                  L d$   SU R                  < SU R                  < S35       eU R                   b  [        U R                   5      (       d   eU R                  5         g)aZ  Makes an asynchronous (i.e. non-blocking) API call within the
specified package for the specified call method.

It will call the _MakeRealCall to do the real job.

Args:
  Same as constructor; see __init__.

Raises:
  TypeError or AssertionError if an argument is of an invalid type.
  AssertionError or RuntimeError is an RPC is already in use.
RPC for .z has already been startedN)r   r   r   r   r   r   r   r   r   callable_MakeCallImpl)r   r   r   r   r   r   r   s          r   MakeCallRPC.MakeCallY   s     -DM*dllDL!		DI*dllDL-DM-DM;;#((" A'+||TYY&@ A"== HT]]$;$;;;r   c                 z    U R                  5       nU(       d$   SU R                  < SU R                  < S35       eg)z/Waits on the API call associated with this RPC.r)   r*   z6 was not completed, and no other exception was raised N)	_WaitImplr   r   )r   rpc_completeds     r   WaitRPC.Waits   s2    NN$M P6:llDIIO P=r   c                    U R                   (       aR  U R                  (       aA  [        R                  " U R                   R                  U R                   U R                  5        gU R                   (       a  U R                   eg)zgIf there was an exception, raise it now.

Raises:
  Exception of the API call or the callback, if any.
N)	exceptionr   r   reraiser   r   s    r   CheckSuccessRPC.CheckSuccessz   sN     ~~$//114>>*	NN 
r   c                     U R                   $ N)r   r7   s    r   r5   RPC.exception   s    ??r   c                     U R                   $ r;   )r   r7   s    r   r   	RPC.state   s    ;;r   c                 .    [         R                  U l        g)z?Override this method to implement a real asynchronous call rpc.N)r   RUNNINGr   r7   s    r   r,   RPC._MakeCallImpl   s    ++DKr   c                      U R                   R                  U R                  U R                  U R                  U R
                  5        [        R                  U l        U R                  5         g! [         a%    [        R                  " 5       u  ol	        U l
         NTf = f! [        R                  U l        U R                  5         f = f)zOverride this method to implement a real asynchronous call rpc.

Returns:
  True if the async call was completed successfully.
T)r   MakeSyncCallr   r   r   r   	Exceptionsysexc_infor   r   r   	FINISHINGr   	_Callbackr   _s     r   r0   RPC._WaitImpl   s    =		t||TYY#||T]]	<
 MMdk
nn  =.1lln+?DO= MMdk
nns$   AA/ /,BB! BB! !'Cc                     U R                   (       a   U R                  5         g g !   [        R                  " 5       u  ol        U l        X R                  l        e = fr;   )r   rE   rF   r   r   _appengine_apiproxy_rpcrI   s     r   rH   RPC._Callback   sD    }} .1lln+?DO26/s	   % 5A)r   r   r   r   r   r   r   r   r   r   r   )NNNNNNN)NNNNNN)__name__
__module____qualname____firstlineno____doc__r   r@   rG   r   r&   r-   r2   r8   propertyr5   r   r,   r0   rH   __static_attributes__ r   r   r   r       sy     
$')EI26< FJ'+4P
    $r   r   )rS   
__future__r   rE   "googlecloudsdk.appengine._internalr   objectr   rV   r   r   <module>rZ      s#     : ' 
 9K& Kr   