
                             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J	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 r   SS jr   SS jrg
)zIImplementation functions for downloads from the Google Cloud Storage API.    )absolute_import)division)unicode_literals)http_wrapper)errors)
retry_util)
exceptions)logNc                     g)z+Disables Apitools' default print callbacks.N )unused_responseunused_objects     7lib/googlecloudsdk/api_lib/storage/gcs_json/download.py_no_op_callbackr       s        c                     U(       d  Ub  U R                  UUUSS9  U R                  $ U R                  U[        [        SS9  U R                  $ )aL  GCS-specific download implementation.

Args:
  apitools_download (apitools.transfer.Download): Apitools object for managing
    downloads.
  start_byte (int): Starting point for download (for resumable downloads and
    range requests). Can be set to negative to request a range of bytes
    (python equivalent of [:-3]).
  end_byte (int): Ending byte number, inclusive, for download (for range
    requests). If None, download the rest of the object.
  additional_headers (dict|None): Headers to add to HTTP request.

Returns:
  Encoding string for object if requested. Otherwise, None.
F)additional_headersstartend
use_chunks)r   callbackfinish_callbackr   )GetRangeStreamMediar   encoding)apitools_download
start_byteend_byter   s       r   launchr   %   sh    & 8'-	   
	#	## !!- '	 " 
 
	#	##r   c                    ^ ^^^^ SU0m[         R                  " T5        UU U4S jnUUUU4S jn[         R                  " XeS9$ )z$Wraps download to make it retriable.r   c                    > [         R                  " U5      u  pE[        U[        R                  R
                  5      (       a"  UR                  S:  a  UR                  S:w  a  gO?[        U[        R                  5      (       d   [        U[        R                  5      (       d  gTR                  5       nUT	S   :  a  UT	S'   SUl        [        R                  " SR                  X`U5      5        [         R"                  " TR$                  5        g)Ni  i  Fr   r   z=Retrying download from byte {} after exception: {}. Trace: {}T)calliope_errorsConvertKnownError
isinstanceoauth2clientclientHttpAccessTokenRefreshErrorstatuscore_exceptionsNetworkIssueErrorcloud_errorsRetryableApiErrortellretrialr
   debugformatapitools_http_wrapperRebuildHttpConnections
bytes_http)
exc_type	exc_valueexc_tracebackstateconverted_error_r   r   download_streamprogress_states
          r    _should_retry_resumable_download:launch_retriable.<locals>._should_retry_resumable_downloadQ   s    (::9EO)\00LLMM			C	I$4$4$;/*K*KLL,*H*HII %%'JN<00%/n\"emII !6*FH 001B1M1MNr   c                  "   > [        TTS   TT S9$ )Nr   )r   r   r   )r   )r   r   r   r;   s   r   _call_launch&launch_retriable.<locals>._call_launchh   s!    !,/-	/ /r   )targetshould_retry_if)r   set_retry_funcretryer)r:   r   r   r   r   r<   r?   r;   s   `` ``  @r   launch_retriablerE   G   sG     !*-.-../ / 
		
M Mr   )r   NN)__doc__
__future__r   r   r   apitools.base.pyr   r1   googlecloudsdk.api_lib.storager   r+   r   googlecloudsdk.callioper	   r"   googlecloudsdk.corer)   r
   r%   r   r   rE   r   r   r   <module>rL      sP    P &  ' B A 5 A = #  "$H !""(,	)Mr   