
    G                        S r SSKrSSKrSSKJr  SSKrSSKr\R                  r	Sr
Sr\R                  (       aR  SSKr\R                  r\\R                  R                   R"                  \R                  R                   R$                  /rO@\R                  R                   R"                  \R                  R                   R$                  /rS r " S S\5      r " S	 S
\R.                  5      rg)zHThis package facilitates retries for HTTP/REST requests to the registry.    N)nested   g      ?c                 B    [          H  n[        X5      (       d  M    g   g)NTF)RETRYABLE_EXCEPTION_TYPES
isinstance)errexception_types     5lib/third_party/containerregistry/transport/retry_.pyShouldRetryr   *   s    1n#&& 2 
    c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)Factory2   z'A factory for creating RetryTransports.c                 (    0 U l         [        U l        g N)kwargs!DEFAULT_SOURCE_TRANSPORT_CALLABLEsource_transport_callableselfs    r
   __init__Factory.__init__5   s    DK%FD"r   c                     Xl         U $ r   )r   )r   r   s     r
   WithSourceTransportCallable#Factory.WithSourceTransportCallable9   s    %>"Kr   c                 "    XR                   S'   U $ )Nmax_retriesr   )r   r   s     r
   WithMaxRetriesFactory.WithMaxRetries=   s    !,KKKr   c                 "    XR                   S'   U $ )Nbackoff_factorr   )r   r"   s     r
   WithBackoffFactorFactory.WithBackoffFactorA   s    $2KK !Kr   c                 "    XR                   S'   U $ )Nshould_retry_fnr   )r   r&   s     r
   WithShouldRetryFunctionFactory.WithShouldRetryFunctionE   s    %4KK!"Kr   c                 J    [        U R                  5       40 U R                  D6$ )z;Returns a RetryTransport constructed with the given values.)RetryTransportr   r   r   s    r
   BuildFactory.BuildI   s    $88:JdkkJJr   )r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r#   r'   r+   __static_attributes__ r   r
   r   r   2   s%    /GKr   r   c                   <   ^  \ rS rSrSr\\\4U 4S jjrS r	Sr
U =r$ )r*   N   zEA wrapper for the given transport which automatically retries errors.c                 P   > [         [        U ]  U5        X l        X0l        X@l        g r   )superr*   r   _max_retries_backoff_factor_should_retry)r   source_transportr   r"   r&   	__class__s        r
   r   RetryTransport.__init__Q   s'    
 
.$()9:#)(r   c                 B   Sn  U R                   R                  " U0 UD6$ ! [         as  nX0R                  :  d  U R	                  U5      (       d  e [
        R                  " SU5        US-  n[        R                  " U R                  SU-  -  5         SnAM  SnAff = f)aa  Does the request, exponentially backing off and retrying as appropriate.

Backoff is backoff_factor * (2 ^ (retry #)) seconds.
Args:
  *args: The sequence of positional arguments to forward to the source
    transport.
  **kwargs: The keyword arguments to forward to the source transport.

Returns:
  The response of the HTTP request, and its contents.
r   zRetrying after exception %s.   r   N)
r;   request	Exceptionr8   r:   loggingerrortimesleepr9   )r   argsr   retriesr   s        r
   r@   RetryTransport.request[   s     G
	$$,,d=f== '''t/A/A#/F/F
4c:1

4''1g:67s   ! 
BA(BB)r9   r8   r:   )r-   r.   r/   r0   r1   DEFAULT_MAX_RETRIESDEFAULT_BACKOFF_FACTORr   r   r@   r2   __classcell__)r<   s   @r
   r*   r*   N   s     M 1 6!,	) r   r*   )r1   rB   rD   containerregistry.transportr   httplib2six.moves.http_clientsixHttpr   rI   rJ   PY3builtinsBrokenPipeErrormoveshttp_clientIncompleteReadResponseNotReadyr   r   objectr   NestedTransportr*   r3   r   r
   <module>rZ      s    O   .  $,MM !  77,,/	ii**	ii,, 
ii**	ii,,Kf K8$V++ $r   