Ë
    U¼SfŽ3  ã                   ó¼   — 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 ddlmZ  G d	„ d
ej                  «      Zdd„Zd„ Zd„ Zdd„Zd„ Zdd„Zdd„Zy)a6  Futures for long-running operations returned from Google Cloud APIs.

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


.. code-block:: python

    operation = my_api_client.long_running_method()
    result = 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 = future.result()

    operation.add_done_callback(my_callback)

é    N)Ú
exceptions)Úprotobuf_helpers)Úpolling)Úoperations_pb2)Újson_format)Ú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dd„Zdd	„Zd
„ Zd„ Zˆ xZS )Ú	OperationaH  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.
        polling (google.api_core.retry.Retry): The configuration used for polling.
            This parameter controls how often :meth:`done` is polled. If the
            ``timeout`` argument is specified in the :meth:`result` method, it will
            override the ``polling.timeout`` property.
        retry (google.api_core.retry.Retry): DEPRECATED: use ``polling`` instead.
            If specified it will override ``polling`` parameter to maintain
            backward compatibility.
    Nc                 óÈ   •— t        t        | �
  dd|i|¤Ž || _        || _        || _        || _        || _        t        j                  «       | _
        | j                  «        y )Nr   © )Úsuperr
   Ú__init__Ú
_operationÚ_refreshÚ_cancelÚ_result_typeÚ_metadata_typeÚ	threadingÚLockÚ_completion_lockÚ_set_result_from_operation)	ÚselfÚ	operationÚrefreshÚcancelÚresult_typeÚmetadata_typer   ÚkwargsÚ	__class__s	           €úXC:\Users\user\Documents\project_loop\venv\Lib\site-packages\google/api_core/operation.pyr   zOperation.__init__I   s\   ø€ ô 	Œi˜Ñ'ÑB°ÐB¸6ÒBØ#ˆŒØˆŒØˆŒØ'ˆÔØ+ˆÔÜ )§¡Ó 0ˆÔà×'Ñ'Õ)ó    c                 ó   — | j                   S )zAgoogle.longrunning.Operation: The current long-running operation.)r   ©r   s    r    r   zOperation.operation]   s   € ð �‰Ðr!   c                 ó¢   — | j                   j                  d«      sy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Operation.metadatab   sA   € ð �‰×'Ñ'¨
Ô3Øä×+Ñ+Ø×Ñ §¡×!9Ñ!9ó
ð 	
r!   c                 ó@   — t         j                  j                  |«      S )zôDeserialize a ``google.longrunning.Operation`` protocol buffer.

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

        Returns:
            ~.operations_pb2.Operation: An Operation protobuf object.
        )r   r
   Ú
FromString)r   Úpayloads     r    ÚdeserializezOperation.deserializel   s   € ô ×'Ñ'×2Ñ2°7Ó;Ð;r!   c                 óî  — | j                   5  | j                  j                  r| j                  r
	 ddd«       y| j                  j	                  d«      rFt        j                  | j                  | j                  j                  «      }| j                  |«       nÇ| j                  j	                  d«      r†t        j                  | j                  j                  j                  | j                  j                  j                  | j                  j                  f| j                  ¬«      }| j                  |«       n&t        j                   d«      }| j                  |«       ddd«       y# 1 sw Y   yxY w)zASet the result or exception from the operation if it is complete.NÚresponseÚerror)Ústatus_codeÚmessageÚerrorsr-   zLUnexpected state: Long-running operation had neither response nor error set.)r   r   ÚdoneÚ_result_setr&   r   r'   r   r-   Ú
set_resultr   Úfrom_grpc_statusr.   Úcoder0   Úset_exceptionÚGoogleAPICallError)r   r-   Ú	exceptions      r    r   z$Operation._set_result_from_operationx   s!  € ð
 ×"Ñ"ñ 	.ð
 —?‘?×'Ò'¨4×+;Ò+;Ø÷	.ð 	.ð �‰×'Ñ'¨
Ô3Ü+×7Ñ7Ø×%Ñ% t§¡×'?Ñ'?ó�ð —‘ Õ)Ø—‘×)Ñ)¨'Ô2Ü&×7Ñ7Ø $§¡× 5Ñ 5× :Ñ :Ø ŸO™O×1Ñ1×9Ñ9Ø ŸO™O×1Ñ1Ð3Ø!Ÿ_™_ô	�	ð ×"Ñ" 9Õ-ä&×9Ñ9ð.ó�	ð ×"Ñ" 9Ô-÷5	.÷ 	.ñ 	.ús   �$E+ºD(E+Å+E4c                 ó¤   — | j                   j                  s:|r| j                  |¬«      n| j                  «       | _         | j                  «        yy)z Refresh the operation and update the result if needed.

        Args:
            retry (google.api_core.retry.Retry): (Optional) How to retry the RPC.
        )ÚretryN)r   r2   r   r   ©r   r;   s     r    Ú_refresh_and_updatezOperation._refresh_and_update™   s>   € ð �‰×#Ò#Ù<A˜dŸm™m°%˜mÔ8ÀtÇ}Á}ÃˆDŒOØ×+Ñ+Õ-ð $r!   c                 óP   — | j                  |«       | j                  j                  S )zíChecks 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.
        )r=   r   r2   r<   s     r    r2   zOperation.done¥   s"   € ð 	× Ñ  Ô'Ø�‰×#Ñ#Ð#r!   c                 óF   — | j                  «       ry| j                  «        y)zªAttempt to cancel the operation.

        Returns:
            bool: True if the cancel RPC was made, False if the operation is
                already complete.
        FT)r2   r   r#   s    r    r   zOperation.cancel±   s   € ð �9‰9Œ;Øà�‰ŒØr!   c                 ó¾   — | j                  «        | j                  j                  d«      xr1 | j                  j                  j                  t
        j                  k(  S )z$True if the operation was cancelled.r.   )r=   r   r&   r.   r6   r   Ú	CANCELLEDr#   s    r    Ú	cancelledzOperation.cancelled¾   sI   € à× Ñ Ô"à�O‰O×$Ñ$ WÓ-ò AØ—‘×%Ñ%×*Ñ*¬h×.@Ñ.@Ñ@ð	
r!   ©N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚDEFAULT_POLLINGr   Úpropertyr   r%   Úclassmethodr+   r   r=   r2   r   rB   Ú__classcell__)r   s   @r    r
   r
   2   sq   ø„ ñð8 Ø×'Ñ'õ*ð( ñó ðð ñ
ó ð
ð ñ	<ó ð	<ò.óB
.ó
$òö
r!   r
   c                 óœ   — dj                  |«      }|� || «      }  | d|¬«      }t        j                  |t        j                  «       «      S )aº  Refresh an operation using a JSON/HTTP client.

    Args:
        api_request (Callable): A callable used to make an API request. This
            should generally be
            :meth:`google.cloud._http.Connection.api_request`.
        operation_name (str): The name of the operation.
        retry (google.api_core.retry.Retry): (Optional) retry policy

    Returns:
        google.longrunning.operations_pb2.Operation: The operation.
    zoperations/{}ÚGET©ÚmethodÚpath)Úformatr   Ú	ParseDictr   r
   )Úapi_requestÚoperation_namer;   rP   Úapi_responses        r    Ú_refresh_httprV   Ç   sL   € ð ×!Ñ! .Ó1€DàÐÙ˜KÓ(ˆá e°$Ô7€LÜ× Ñ  ¬~×/GÑ/GÓ/IÓJÐJr!   c                 ó:   — dj                  |«      } | d|¬«       y)a"  Cancel an operation using a JSON/HTTP client.

    Args:
        api_request (Callable): A callable used to make an API request. This
            should generally be
            :meth:`google.cloud._http.Connection.api_request`.
        operation_name (str): The name of the operation.
    zoperations/{}:cancelÚPOSTrN   N)rQ   )rS   rT   rP   s      r    Ú_cancel_httprY   Ý   s   € ð "×(Ñ(¨Ó8€DÙ�v DÖ)r!   c                 ó  — t        j                  | t        j                  «       «      }t	        j
                  t        ||j                  «      }t	        j
                  t        ||j                  «      }t        ||||fi |¤ŽS )a  Create an operation future using a HTTP/JSON client.

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

    .. _HTTP/JSON: https://cloud.google.com/speech/reference/rest/            v1beta1/operations#Operation

    Args:
        operation (dict): Operation as a dictionary.
        api_request (Callable): A callable used to make an API request. This
            should generally be
            :meth:`google.cloud._http.Connection.api_request`.
        result_type (:func:`type`): The protobuf result type.
        kwargs: Keyword args passed into the :class:`Operation` constructor.

    Returns:
        ~.api_core.operation.Operation: The operation future to track the given
            operation.
    )	r   rR   r   r
   Ú	functoolsÚpartialrV   ÚnamerY   )r   rS   r   r   Úoperation_protor   r   s          r    Úfrom_http_jsonr_   ê   si   € ô* "×+Ñ+¨I´~×7OÑ7OÓ7QÓR€OÜ×Ñ¤¨{¸O×<PÑ<PÓQ€GÜ×Ñœ|¨[¸/×:NÑ:NÓO€FÜ�_ g¨v°{ÑMÀfÑMÐMr!   c                 ój   — t        j                  |¬«      }| j                  }|� ||«      } ||«      S )a{  Refresh an operation using a gRPC client.

    Args:
        operations_stub (google.longrunning.operations_pb2.OperationsStub):
            The gRPC operations stub.
        operation_name (str): The name of the operation.
        retry (google.api_core.retry.Retry): (Optional) retry policy

    Returns:
        google.longrunning.operations_pb2.Operation: The operation.
    ©r]   )r   ÚGetOperationRequestÚGetOperation)Úoperations_stubrT   r;   Ú
request_pbÚrpcs        r    Ú_refresh_grpcrg     s8   € ô  ×3Ñ3¸ÔH€Jà
×
&Ñ
&€CØÐÙ�C‹jˆáˆz‹?Ðr!   c                 óR   — t        j                  |¬«      }| j                  |«       y)zãCancel an operation using a gRPC client.

    Args:
        operations_stub (google.longrunning.operations_pb2.OperationsStub):
            The gRPC operations stub.
        operation_name (str): The name of the operation.
    ra   N)r   ÚCancelOperationRequestÚCancelOperation)rd   rT   re   s      r    Ú_cancel_grpcrk     s"   € ô  ×6Ñ6¸NÔK€JØ×#Ñ# JÕ/r!   c                 ó¼   — t        j                  t        || j                  |¬«      }t        j                  t        || j                  |¬«      }t        | |||fi |¤ŽS )a„  Create an operation future using a gRPC client.

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

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

    Args:
        operation (google.longrunning.operations_pb2.Operation): The operation.
        operations_stub (google.longrunning.operations_pb2.OperationsStub):
            The operations stub.
        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%   )r[   r\   rg   r]   rk   r
   )r   rd   r   Úgrpc_metadatar   r   r   s          r    Ú	from_grpcro   &  s^   € ô. ×ÑÜØØ�‰Øô	€Gô ×ÑÜØØ�‰Øô	€Fô �Y ¨°ÑGÀÑGÐGr!   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.
    rm   )r[   r\   Úget_operationr]   Úcancel_operationr
   )r   Úoperations_clientr   rn   r   r   r   s          r    Ú
from_gapicrt   L  sd   € ô. ×ÑØ×'Ñ'Ø�‰Øô€Gô
 ×ÑØ×*Ñ*Ø�‰Øô€Fô
 �Y ¨°ÑGÀÑGÐGr!   rC   )rG   r[   r   Úgoogle.api_corer   r   Úgoogle.api_core.futurer   Úgoogle.longrunningr   Úgoogle.protobufr   Ú
google.rpcr   ÚPollingFuturer
   rV   rY   r_   rg   rk   ro   rt   r   r!   r    ú<module>r{      sa   ðñó0 Û å &Ý ,Ý *Ý -Ý 'Ý ôR
�×%Ñ%ô R
ójKò,
*òNó6ò*	0ó#HôL!Hr!   