
    Bfn                         d 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	 ddl
mZ  G d d	ej                  Zdd
ZdS )aB  AsyncIO futures for long-running operations returned from Google Cloud APIs.

These futures can be used to await for the result of a long-running operation
using :meth:`AsyncOperation.result`:


.. code-block:: python

    operation = my_api_client.long_running_method()
    result = await operation.result()

Or asynchronously using callbacks and :meth:`Operation.add_done_callback`:

.. code-block:: python

    operation = my_api_client.long_running_method()

    def my_callback(future):
        result = await future.result()

    operation.add_done_callback(my_callback)

    N)
exceptions)protobuf_helpers)async_future)operations_pb2)code_pb2c                        e Zd ZdZdej        f fd	Zed             Zed             Z	e
d             Zd Zej        fdZej        fd	Zd
 Zd Z xZS )AsyncOperationa  A Future for interacting with a Google API Long-Running Operation.

    Args:
        operation (google.longrunning.operations_pb2.Operation): The
            initial operation.
        refresh (Callable[[], ~.api_core.operation.Operation]): A callable that
            returns the latest state of the operation.
        cancel (Callable[[], None]): A callable that tries to cancel
            the operation.
        result_type (func:`type`): The protobuf type for the operation's
            result.
        metadata_type (func:`type`): The protobuf type for the operation's
            metadata.
        retry (google.api_core.retry.Retry): The retry configuration used
            when polling. This can be used to control how often :meth:`done`
            is polled. Regardless of the retry's ``deadline``, it will be
            overridden by the ``timeout`` argument to :meth:`result`.
    Nc                     t                                          |           || _        || _        || _        || _        || _        t          j                    | _	        | 
                                 d S )Nretry)super__init__
_operation_refresh_cancel_result_type_metadata_type	threadingLock_completion_lock_set_result_from_operation)self	operationrefreshcancelresult_typemetadata_typer   	__class__s          n/home/panchajanya/Development/work/volatility3/lib/python3.11/site-packages/google/api_core/operation_async.pyr   zAsyncOperation.__init__E   sm     	u%%%#'+ ) 0 0'')))))    c                     | j         S )zAgoogle.longrunning.Operation: The current long-running operation.)r   r   s    r   r   zAsyncOperation.operationX   s     r    c                     | j                             d          sdS t          j        | j        | j         j                  S )z8google.protobuf.Message: the current operation metadata.metadataN)r   HasFieldr   from_any_pbr   r$   r"   s    r   r$   zAsyncOperation.metadata]   sC     ''
33 	4+!9
 
 	
r    c                 @    t           j                            |          S )zDeserialize a ``google.longrunning.Operation`` protocol buffer.

        Args:
            payload (bytes): A serialized operation protocol buffer.

        Returns:
            ~.operations_pb2.Operation: An Operation protobuf object.
        )r   	Operation
FromString)clspayloads     r   deserializezAsyncOperation.deserializeg   s     '227;;;r    c                 r   | j         5  | j        j        r| j                                        r	 ddd           dS | j                            d          r:t          j        | j        | j        j                  }| 	                    |           n| j                            d          rLt          j        | j        j        j        | j        j        f| j                  }|                     |           n)t          j        d          }|                     |           ddd           dS # 1 swxY w Y   dS )zASet the result or exception from the operation if it is complete.Nresponseerror)errorsr.   zLUnexpected state: Long-running operation had neither response nor error set.)r   r   done_futurer%   r   r&   r   r.   
set_resultr   GoogleAPICallErrorr/   messageset_exception)r   r.   	exceptions      r   r   z)AsyncOperation._set_result_from_operations   s   
 " 	. 	. ?' 4<+<+<+>+> 		. 	. 	. 	. 	. 	. 	. 	. ''
33 .+7%t'?  ))))))'22 .&9O)1 O13!_  	
 ""9----&9. 	 ""9---/	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   'D,C#D,,D03D0c                    K   | j         j        s7|                     |           d{V | _         |                                  dS dS )zRefresh the operation and update the result if needed.

        Args:
            retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.
        r   N)r   r1   r   r   r   r   s     r   _refresh_and_updatez"AsyncOperation._refresh_and_update   s^       # 	.$(MMM$>$>>>>>>>DO++-----	. 	.r    c                 T   K   |                      |           d{V  | j        j        S )zChecks to see if the operation is complete.

        Args:
            retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.

        Returns:
            bool: True if the operation is complete, False otherwise.
        N)r:   r   r1   r9   s     r   r1   zAsyncOperation.done   s9       &&u---------##r    c                 z   K   |                                   d{V }|rdS |                                  d{V  dS )zAttempt to cancel the operation.

        Returns:
            bool: True if the cancel RPC was made, False if the operation is
                already complete.
        NFT)r1   r   )r   results     r   r   zAsyncOperation.cancel   sY       yy{{"""""" 	5,,..       4r    c                    K   |                                   d{V  | j                            d          o| j        j        j        t
          j        k    S )z$True if the operation was cancelled.Nr/   )r:   r   r%   r/   coder   	CANCELLEDr"   s    r   	cancelledzAsyncOperation.cancelled   s[      &&(((((((((O$$W-- A%*h.@@	
r    )__name__
__module____qualname____doc__r   DEFAULT_RETRYr   propertyr   r$   classmethodr,   r   r:   r1   r   rA   __classcell__)r   s   @r   r	   r	   1   s        2 (* * * * * *&   X 
 
 X
 	< 	< [	<. . .< /;.H 
. 
. 
. 
.  ,9 
$ 
$ 
$ 
$  
 
 
 
 
 
 
r    r	   c                     t          j        |j        | j        |          }t          j        |j        | j        |          }t          | |||fi |S )a  Create an operation future from a gapic client.

    This interacts with the long-running operations `service`_ (specific
    to a given API) via a gapic client.

    .. _service: https://github.com/googleapis/googleapis/blob/                 050400df0fdb16f63b63e9dee53819044bffc857/                 google/longrunning/operations.proto#L38

    Args:
        operation (google.longrunning.operations_pb2.Operation): The operation.
        operations_client (google.api_core.operations_v1.OperationsClient):
            The operations client.
        result_type (:func:`type`): The protobuf result type.
        grpc_metadata (Optional[List[Tuple[str, str]]]): Additional metadata to pass
            to the rpc.
        kwargs: Keyword args passed into the :class:`Operation` constructor.

    Returns:
        ~.api_core.operation.Operation: The operation future to track the given
            operation.
    )r$   )	functoolspartialget_operationnamecancel_operationr	   )r   operations_clientr   grpc_metadatakwargsr   r   s          r   
from_gapicrS      sn    . '  G
 *  F
 )WfkLLVLLLr    )N)rE   rK   r   google.api_corer   r   google.api_core.futurer   google.longrunningr   
google.rpcr   AsyncFuturer	   rS    r    r   <module>rZ      s    0         & & & & & & , , , , , , / / / / / / - - - - - -      L
 L
 L
 L
 L
\- L
 L
 L
^!M !M !M !M !M !Mr    