
    u                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSK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  \R                  rSS jrg)zCShared utility structures and methods for handling request retries.    )absolute_import)print_function)division)unicode_literalsN)http_wrapper)thread_message)	constants)retry_decoratorc                 2   ^ U4S jnU4S jnU (       a  U$ U$ )zHigher-order function allowing retry handler to access global status queue.

Args:
  is_data_transfer: If True, disable retries in apitools.
  status_queue: The global status queue.

Returns:
  A retry function for retryable errors in apitools.
c           	        > U R                   b?  U R                   [        R                  :  a!  [        R                  " SU R
                  5        T(       aW  TR                  [        R                  " U R                  [        R                  " 5       U R
                  U R                   S95        [        R                  " U 5        g)a{  Exception handler for http failures in apitools.

If the user has had to wait several seconds since their first request, print
a progress message to the terminal to let them know we're still retrying,
then perform the default retry logic and post a
gslib.thread_message.RetryableErrorMessage to the global status queue.

Args:
  retry_args: An apitools ExceptionRetryArgs tuple.
Nz Retrying request, attempt #%d...num_retriestotal_wait_sec)r   r	   LONG_RETRY_WARN_SEClogginginfor   putr   RetryableErrorMessageexctimer   )HandleExceptionsAndRebuildHttpConnections
retry_argsstatus_queues    )platform/gsutil/gslib/utils/retry_util.pyWarnAfterManyRetriesHandler8LogAndHandleRetries.<locals>.WarnAfterManyRetriesHandler,   s     	!!-!!Y%B%BBll5z7M7MN

.
.nniik$00'66	89 :::F    c           	         > T(       aW  TR                  [        R                  " U R                  [        R                  " 5       U R
                  U R                  S95        [        R                  " U 5        g)a  Exception handler that disables retries in apitools data transfers.

Post a gslib.thread_message.RetryableErrorMessage to the global status
queue. We handle the actual retries within the download and upload
functions.

Args:
  retry_args: An apitools ExceptionRetryArgs tuple.
r   N)	r   r   r   r   r   r   r   r   RethrowExceptionHandlerr   s    r   RetriesInDataTransferHandler9LogAndHandleRetries.<locals>.RetriesInDataTransferHandlerC   sV     

.
.nniik$00'66	89 ((4r    )is_data_transferr   r   r!   s    `  r   LogAndHandleRetriesr%   !   s    G.5& ''	$$r   )FN)__doc__
__future__r   r   r   r   r   r   apitools.base.pyr   gslibr   gslib.utilsr	   r
   retryRetryr%   r#   r   r   <module>r-      s9    J & %  '   )   ! +7%r   