
    u                         d Z ddlmZ ddlmZ ddlmZ ddlm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 ej                  ZddZy)zCShared utility structures and methods for handling request retries.    )absolute_import)print_function)division)unicode_literalsN)http_wrapper)thread_message)	constants)retry_decoratorc                 $    fd}fd}| r|S |S )a  Higher-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                 v   | j                   =| j                   t        j                  k\  r t        j                  d| j
                         rXj                  t        j                  | j                  t        j                         | j
                  | j                                t        j                  |        y)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WarnAfterManyRetriesHandlerz8LogAndHandleRetries.<locals>.WarnAfterManyRetriesHandler,   s     	!!-!!Y%B%BBll5z7M7MN

.
.nniik$00'66	89 :::F    c                     rXj                  t        j                  | j                  t	        j                         | j
                  | j                               t        j                  |        y)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   RetriesInDataTransferHandlerz9LogAndHandleRetries.<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   