
    1                         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
\R                  5      rg)z*Download workflow used by GCS gRPC client.    )absolute_import)division)unicode_literals)	cloud_api)gcs_download)	grpc_util)
retry_utilc                   h   ^  \ rS rSrSrU 4S jrS rS r\R                  S 5       r
U 4S jrSrU =r$ )	GrpcDownload   z$Perform GCS Download using gRPC API.c
                 n   > [         T
U ]  X4U5        Xl        X l        X`l        Xpl        Xl        Xl        g)a  Initializes a GrpcDownload instance.

Args:
  gapic_client (StorageClient): The GAPIC API client to interact with
    GCS using gRPC.
  cloud_resource (resource_reference.ObjectResource): See
    cloud_api.CloudApi.download_object.
  download_stream (stream): Stream to send the object data to.
  start_byte (int): See super class.
  end_byte (int): See super class.
  digesters (dict): See cloud_api.CloudApi.download_object.
  progress_callback (function): See cloud_api.CloudApi.download_object.
  download_strategy (cloud_api.DownloadStrategy): Download strategy used to
    perform the download.
  decryption_key (encryption_util.EncryptionKey|None): The decryption key
    to be used to download the object if the object is encrypted.
N)super__init___gapic_client_cloud_resource
_digesters_progress_callback_download_strategy_decryption_key)selfgapic_clientcloud_resourcedownload_stream
start_byteend_byte	digestersprogress_callbackdownload_strategydecryption_key	__class__s             7lib/googlecloudsdk/api_lib/storage/gcs_grpc/download.pyr   GrpcDownload.__init__   s9    6 
)T#OJ%)O//)    c                 0    [         R                  " XU5      $ )See super class.)r	   is_retriable)r   exc_type	exc_valueexc_tracebacks       r!   should_retryGrpcDownload.should_retryA   s    ""8FFr#   c                     [         R                  " U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  S9	$ )r%   )	r   r   r   r   r   r   r   r   r   )r   download_objectr   r   _download_streamr   r   _start_byte	_end_byter   r   r   s    r!   launchGrpcDownload.launchE   sb    $$''++--//11##11++
 
r#   c                 "    U R                  5       $ )a_  Downloads the object.

On retriable errors, the entire download will be re-performed instead of
resuming from a particular byte. This is useful for streaming download
cases.

Unlike Apitools, the GAPIC client doesn't retry the request by
default, hence we are using the decorator.

Returns:
  Encoding string for object if requested. Otherwise, None.
)r2   r1   s    r!   simple_downloadGrpcDownload.simple_downloadS   s     ;;=r#   c                    > U R                   [        R                  R                  :X  a  U R	                  5       $ [
        TU ]  SS9$ )r%   T)retriable_in_flight)r   r   DownloadStrategyONE_SHOTr5   r   run)r   r    s    r!   r;   GrpcDownload.runc   sA    )"<"<"E"EE!!##9d'D'AAr#   )r   r   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r*   r2   r	   grpc_default_retryerr5   r;   __static_attributes____classcell__)r    s   @r!   r   r      s=    ,!*FG "" #B Br#   r   N)rA   
__future__r   r   r   googlecloudsdk.api_lib.storager   r   'googlecloudsdk.api_lib.storage.gcs_grpcr   r	   GcsDownloadr    r#   r!   <module>rJ      s5    1 &  ' 4 7 = >MB<++ MBr#   