
                         t    S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSK	J
r
  SSKJr  SS	KJr  S
 rSS jrg)z,Utilities for retrying requests on failures.    )absolute_import)division)unicode_literalsN)http_wrapper)errors)
properties)retryc                     S nXl         g)a  Sets the retry function for the apitools transfer object.

Replaces the Apitools' default retry function
HandleExceptionsAndRebuildHttpConnections with a custom one which calls
HandleExceptionsAndRebuildHttpConnections and then raise a custom exception.
This is useful when we don't want MakeRequest method in Apitools to retry
the http request directly and instead let the caller decide the next action.

Args:
  apitools_transfer_object (apitools.base.py.transfer.Transfer): The
  Apitools' transfer object.
c                     [         R                  " U 5        [        U R                  [        5      (       a4  U R                  R
                  [
        R                  :X  a  U R                  e[        R                  " 5       e)N)	apitools_http_wrapper)HandleExceptionsAndRebuildHttpConnections
isinstanceexcOSErrorerrnoENOSPCr   RetryableApiError)
retry_argss    0lib/googlecloudsdk/api_lib/storage/retry_util.py_handle_error_and_raise/set_retry_func.<locals>._handle_error_and_raise*   sV     CCJO
 	:>>7++NN  ELL0NN 
"
"
$$    N)
retry_func)apitools_transfer_objectr   s     r   set_retry_funcr      s    %  )@%r   c                    [         R                  " [        R                  R                  R
                  R                  5       [        R                  R                  R                  R                  5       S-  [        R                  R                  R                  R                  5       S9R                  U UU[        R                  R                  R                  R                  5       S-  US9$ )aL  Retries the target with specific default value.

This function is intended to be used for all gcloud storage's API requests
that require custom retry handling (e.g downloads and uploads).

Args:
  target (Callable): The function to call and retry.
  should_retry_if (Callable): func(exc_type, exc_value, exc_traceback, state)
      that returns True or False.
  target_args (Sequence|None): A sequence of positional arguments to be passed
      to the target.
  target_kwargs (Dict|None): A dict of keyword arguments to be passed
      to target.

Returns:
  Whatever the target returns.
i  )max_retrialswait_ceiling_msexponential_sleep_multiplier)argskwargssleep_msshould_retry_if)r	   Retryerr   VALUESstoragemax_retriesGetIntmax_retry_delayr   RetryOnExceptionbase_retry_delay)targetr#   target_argstarget_kwargss       r   retryerr/   =   s    & 
$$,,88??A ''//??FFH4O



#
#
@
@
G
G
I	
	
 
	
$$,,==DDFM) 
 
+
+r   )NN)__doc__
__future__r   r   r   r   apitools.base.pyr   r   googlecloudsdk.api_lib.storager   googlecloudsdk.corer   googlecloudsdk.core.utilr	   r   r/    r   r   <module>r7      s.    3 &  '  B 1 * *@@+r   