
                         v    S r SSKJr  SSKJr  SSKJ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  S
 rS rS rg)z+Helper functions for making gRPC API calls.    )absolute_import)division)unicode_literalsN)	cloud_api)errors)encryption_util)logc                 $    SR                  U 5      $ )z9Returns the bucket resource name as expected by gRPC API.zprojects/_/buckets/{})format)bucket_names    8lib/googlecloudsdk/api_lib/storage/gcs_grpc/grpc_util.pyget_full_bucket_namer      s    	 	'	'	44    c           	      `   Ub  UR                   [        R                  R                  :X  a  U R                  R                  [        R                  [        R                  " UR                  R                  S5      5      [        R                  " UR                  R                  S5      5      S9$ g )Nzutf-8)encryption_algorithmencryption_key_bytesencryption_key_sha256_bytes)typer   KeyTypeCSEKtypesCommonObjectRequestParamsENCRYPTION_ALGORITHMbase64	b64decodekeyencodesha256)gapic_clientdecryption_keys     r   get_encryption_request_paramsr!   $   s     


!8!8!=!=
=77,AA#--%%g.0$*$4$4!!((1%3	 8   r   c	                    [        UR                  R                  5      n	U R                  R	                  U	UR                  R
                  UR                  (       a  [        UR                  5      OSUUb  Xe-
  S-   OS[        X5      S9n
U R                  R                  U
S9nUnSnU H  nUR                  R                  nU(       d  M"   UR                  U5        U(       a(  UR)                  5        H  nUR+                  U5        M     U[-        U5      -  nU(       d  Mz  U" U5        M     Ub  Xe-
  S-   OUR.                  nX-
  nUU:w  aF  U(       d>  S	R1                  UU5      n[$        R2                  " U5        [4        R6                  " U5      egg! [         a;    U[        R                   R"                  L a  [$        R&                  " S5        Sn   M  e f = f)
z Downloads the object using gRPC.N   r   )bucketobject_
generationread_offset
read_limitcommon_object_request_params)requestFz4Writing to download stream raised broken pipe error.TzDownload not completed. Target size={}, downloaded data={}. The input stream terminated before the entire content was read, possibly due to a network condition.)r   storage_urlr   r   ReadObjectRequestresource_namer&   intr!   storageread_objectchecksummed_datacontentwriteBrokenPipeErrorr   DownloadStrategyONE_SHOTr	   infovaluesupdatelensizer   debugcloud_errorsRetryableApiError)r   cloud_resourcedownload_stream	digestersprogress_callback
start_byteend_bytedownload_strategyr    r   r*   streamprocessed_bytesdestination_pipe_is_brokenresponsedatahash_objecttarget_sizetotal_downloaded_datamessages                       r   download_objectrO   2   s    %^%?%?%K%KL+00((66,:,E,E#n''
(4.6.B&*#@
$ 1 ' ++G+<& /$h$$,,Dtd# 
$++-K


T
" . T"o		/*% * $,#7ha^=P=P  *6))2L	006.10 
 IIg

(
(
11 3M)'  	 : : C CC
((I
J'+
$
s   F?GG)__doc__
__future__r   r   r   r   googlecloudsdk.api_lib.storager   r   r=   "googlecloudsdk.command_lib.storager   googlecloudsdk.corer	   r   r!   rO    r   r   <module>rV      s4    2 '  '  4 A > #5
B2r   