
    Bf8                     H   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
  G d de          Z ej        eej        ej        ej        ej                  Z ej        e	          Z ej        e          Z ej        ed
ddd          Z G d de
j                  ZdS )z5Abstract and helper bases for Future implementations.    N)
exceptionsretry)_helpers)basec                       e Zd ZdZdS )_OperationNotCompletez-Private exception used for polling via retry.N)__name__
__module____qualname____doc__     m/home/panchajanya/Development/work/volatility3/lib/python3.11/site-packages/google/api_core/future/polling.pyr	   r	      s        77Dr   r	   )	predicateg      ?g      4@g      ?i  )r   initialmaximum
multipliertimeoutc                        e Zd ZdZ e            Zef fd	Zej	        dd            Z
ddZd ZeddfdZeddfdZefd	Zd
 Zd Zd Zd Z xZS )PollingFuturea  A Future that needs to poll some service to check its status.

    The :meth:`done` method should be implemented by subclasses. The polling
    behavior will repeatedly call ``done`` until it returns True.

    The actual polling logic is encapsulated in :meth:`result` method. See
    documentation for that method for details on how polling works.

    .. note::

        Privacy here is intended to prevent the final class from
        overexposing, not to prevent subclasses from accessing methods.

    Args:
        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 :meth:`result` method it will
            override the ``polling.timeout`` property.
        retry (google.api_core.retry.Retry): DEPRECATED use ``polling`` instead.
            If set, it will override ``polling`` parameter for backward
            compatibility.
    c                     t          t          |                                            |                    d|          | _        d | _        d | _        d| _        	 d | _        g | _	        d S )Nr   F)
superr   __init__get_polling_result
_exception_result_set_polling_thread_done_callbacks)selfpollingkwargs	__class__s      r   r   zPollingFuture.__init__[   se    mT""++---

7G44 	#!r   Nc                     t                      )a{  Checks to see if the operation is complete.

        Args:
            retry (google.api_core.retry.Retry): (Optional) How to retry the
                polling RPC (to not be confused with polling configuration. See
                the documentation for :meth:`result` for details).

        Returns:
            bool: True if the operation is complete, False otherwise.
        )NotImplementedErrorr"   r   s     r   donezPollingFuture.donef   s     "###r   c                 N    |                      |          st                      dS )z2Check if the future is done and raise if it's not.r   N)r)   r	   r(   s     r   _done_or_raisezPollingFuture._done_or_raiseu   s.    yyuy%% 	*')))	* 	*r   c                 ,    |                                   S )z+True if the operation is currently running.)r)   )r"   s    r   runningzPollingFuture.runningz   s    99;;r   c                    | j         rdS |p| j        }|t          j        ur|                    |          }	   || j                  |           dS # t          j        $ r) t          j	        
                    d|j         d          w xY w)z,Poll and wait for the Future to be resolved.Nr   z<Operation did not complete within the designated timeout of z	 seconds.)r   r   r   _DEFAULT_VALUEwith_timeoutr+   r   
RetryError
concurrentfuturesTimeoutErrorr   r"   r   r   r#   s       r   _blocking_pollzPollingFuture._blocking_poll~   s      	F*T]-666**733G	(GGD'((u555555$ 	 	 	$11.?. . .  	s   A 8Bc                 \    |                      |||           | j        | j        | j        S )a&  Get the result of the operation.

        This method will poll for operation status periodically, blocking if
        necessary. If you just want to make sure that this method does not block
        for more than X seconds and you do not care about the nitty-gritty of
        how this method operates, just call it with ``result(timeout=X)``. The
        other parameters are for advanced use only.

        Every call to this method is controlled by the following three
        parameters, each of which has a specific, distinct role, even though all three
        may look very similar: ``timeout``, ``retry`` and ``polling``. In most
        cases users do not need to specify any custom values for any of these
        parameters and may simply rely on default ones instead.

        If you choose to specify custom parameters, please make sure you've
        read the documentation below carefully.

        First, please check :class:`google.api_core.retry.Retry`
        class documentation for the proper definition of timeout and deadline
        terms and for the definition the three different types of timeouts.
        This class operates in terms of Retry Timeout and Polling Timeout. It
        does not let customizing RPC timeout and the user is expected to rely on
        default behavior for it.

        The roles of each argument of this method are as follows:

        ``timeout`` (int): (Optional) The Polling Timeout as defined in
        :class:`google.api_core.retry.Retry`. If the operation does not complete
        within this timeout an exception will be thrown. This parameter affects
        neither Retry Timeout nor RPC Timeout.

        ``retry`` (google.api_core.retry.Retry): (Optional) How to retry the
        polling RPC. The ``retry.timeout`` property of this parameter is the
        Retry Timeout as defined in :class:`google.api_core.retry.Retry`.
        This parameter defines ONLY how the polling RPC call is retried
        (i.e. what to do if the RPC we used for polling returned an error). It
        does NOT define how the polling is done (i.e. how frequently and for
        how long to call the polling RPC); use the ``polling`` parameter for that.
        If a polling RPC throws and error and retrying it fails, the whole
        future fails with the corresponding exception. If you want to tune which
        server response error codes are not fatal for operation polling, use this
        parameter to control that (``retry.predicate`` in particular).

        ``polling`` (google.api_core.retry.Retry): (Optional) How often and
        for how long to call the polling RPC periodically (i.e. what to do if
        a polling rpc returned successfully but its returned result indicates
        that the long running operation is not completed yet, so we need to
        check it again at some point in future). This parameter does NOT define
        how to retry each individual polling RPC in case of an error; use the
        ``retry`` parameter for that. The ``polling.timeout`` of this parameter
        is Polling Timeout as defined in as defined in
        :class:`google.api_core.retry.Retry`.

        For each of the arguments, there are also default values in place, which
        will be used if a user does not specify their own. The default values
        for the three parameters are not to be confused with the default values
        for the corresponding arguments in this method (those serve as "not set"
        markers for the resolution logic).

        If ``timeout`` is provided (i.e.``timeout is not _DEFAULT VALUE``; note
        the ``None`` value means "infinite timeout"), it will be used to control
        the actual Polling Timeout. Otherwise, the ``polling.timeout`` value
        will be used instead (see below for how the ``polling`` config itself
        gets resolved). In other words, this parameter  effectively overrides
        the ``polling.timeout`` value if specified. This is so to preserve
        backward compatibility.

        If ``retry`` is provided (i.e. ``retry is not None``) it will be used to
        control retry behavior for the polling RPC and the ``retry.timeout``
        will determine the Retry Timeout. If not provided, the
        polling RPC will be called with whichever default retry config was
        specified for the polling RPC at the moment of the construction of the
        polling RPC's client. For example, if the polling RPC is
        ``operations_client.get_operation()``, the ``retry`` parameter will be
        controlling its retry behavior (not polling  behavior) and, if not
        specified, that specific method (``operations_client.get_operation()``)
        will be retried according to the default retry config provided during
        creation of ``operations_client`` client instead. This argument exists
        mainly for backward compatibility; users are very unlikely to ever need
        to set this parameter explicitly.

        If ``polling`` is provided (i.e. ``polling is not None``), it will be used
        to control the overall polling behavior and ``polling.timeout`` will
        control Polling Timeout unless it is overridden by ``timeout`` parameter
        as described above. If not provided, the``polling`` parameter specified
        during construction of this future (the ``polling`` argument in the
        constructor) will be used instead. Note: since the ``timeout`` argument may
        override ``polling.timeout`` value, this parameter should be viewed as
        coupled with the ``timeout`` parameter as described above.

        Args:
            timeout (int): (Optional) How long (in seconds) to wait for the
                operation to complete. If None, wait indefinitely.
            retry (google.api_core.retry.Retry): (Optional) How to retry the
                polling RPC. This defines ONLY how the polling RPC call is
                retried (i.e. what to do if the RPC we used for polling returned
                an error). It does  NOT define how the polling is done (i.e. how
                frequently and for how long to call the polling RPC).
            polling (google.api_core.retry.Retry): (Optional) How often and
                for how long to call polling RPC periodically. This parameter
                does NOT define how to retry each individual polling RPC call
                (use the ``retry`` parameter for that).

        Returns:
            google.protobuf.Message: The Operation's result.

        Raises:
            google.api_core.GoogleAPICallError: If the operation errors or if
                the timeout is reached before the operation completes.
        )r   r   r#   )r6   r   r   r5   s       r   resultzPollingFuture.result   s:    ` 	G5'JJJ?& /!|r   c                 <    |                      |           | j        S )a  Get the exception from the operation, blocking if necessary.

        See the documentation for the :meth:`result` method for details on how
        this method operates, as both ``result`` and this method rely on the
        exact same polling logic. The only difference is that this method does
        not accept ``retry`` and ``polling`` arguments but relies on the default ones
        instead.

        Args:
            timeout (int): How long to wait for the operation to complete.
            If None, wait indefinitely.

        Returns:
            Optional[google.api_core.GoogleAPICallError]: The operation's
                error.
        )r   )r6   r   )r"   r   s     r   	exceptionzPollingFuture.exception	  s#    " 	G,,,r   c                     | j         rt          j        ||            dS | j                            |           | j        !t          j        | j                  | _        dS dS )aV  Add a callback to be executed when the operation is complete.

        If the operation is not already complete, this will start a helper
        thread to poll for the status of the operation in the background.

        Args:
            fn (Callable[Future]): The callback to execute when the operation
                is complete.
        N)target)r   r   safe_invoke_callbackr!   appendr    start_daemon_threadr6   )r"   fns     r   add_done_callbackzPollingFuture.add_done_callback  sw      	)"d333F##B'''' $,#?*$ $ $D    ('r   c                 D    | j         D ]}t          j        |g|R i | dS )zInvoke all done callbacks.N)r!   r   r=   )r"   argsr$   callbacks       r   _invoke_callbackszPollingFuture._invoke_callbacks4  sF    , 	E 	EH)(DTDDDVDDDD	E 	Er   c                 L    || _         d| _        |                     |            dS )zSet the Future's result.TN)r   r   rE   )r"   r8   s     r   
set_resultzPollingFuture.set_result9  s+    t$$$$$r   c                 L    || _         d| _        |                     |            dS )zSet the Future's exception.TN)r   r   rE   )r"   r:   s     r   set_exceptionzPollingFuture.set_exception?  s+    #t$$$$$r   )N)r
   r   r   r   objectr/   DEFAULT_POLLINGr   abcabstractmethodr)   r+   r-   r6   r8   r:   rA   rE   rG   rI   __classcell__)r%   s   @r   r   r   A   s5        . VXXN. 	" 	" 	" 	" 	" 	" 	$ $ $ $* * * *
   &44    $ ,4 w w w wr !/    (  .E E E
% % %% % % % % % %r   r   )r   rL   concurrent.futuresr2   google.api_corer   r   retriesgoogle.api_core.futurer   r   	Exceptionr	   if_exception_typeTooManyRequestsInternalServerError
BadGatewayServiceUnavailableRETRY_PREDICATERetryDEFAULT_RETRYPOLLING_PREDICATErK   Futurer   r   r   r   <module>r^      s^   < ; 



     & & & & & & , , , , , , + + + + + + ' ' ' ' ' '	 	 	 	 	I 	 	 	 ,'+"!  888 .G-  
  '-  B% B% B% B% B%DK B% B% B% B% B%r   