
                             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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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Qr " S S\5      rg)z)Helper for cat and cp streaming download.    )absolute_import)print_function)division)unicode_literalsN)config)EncryptionException)CommandException)NO_URLS_MATCHED_TARGET)StorageUrlFromString)CryptoKeyWrapperFromKey)FindMatchingCSEKInBotoConfig)ObjectIsGzipEncoded)	text_util)bucketcontentEncodingcrc32ccustomerEncryption
generationmd5Hashnamesizec                   6    \ rS rSrSrS rS r    SS jrSrg)		CatHelper0   zDProvides methods for the "cat" command and associated functionality.c                     Xl         g)zaInitializes the helper object.

Args:
  command_obj: gsutil command instance of calling command.
Ncommand_obj)selfr   s     )platform/gsutil/gslib/utils/cat_helper.py__init__CatHelper.__init__3   s
     #    c                      UR                  [        R                  5      nU(       d  g[        R                  " X#5        M?  )ax  Copies contents of the source to the destination via buffered IO.

Buffered reads are necessary in the case where you're reading from a
source that produces more data than can fit into memory all at once. This
method does not close either file when finished.

Args:
  src_fd: The already-open source file to read from.
  dst_fd: The already-open destination file to write to.
N)readioDEFAULT_BUFFER_SIZEr   write_to_fd)r   src_fddst_fdbufs       r   _WriteBytesBufferedFileToFile'CatHelper._WriteBytesBufferedFileToFile;   s4     KK../cF(	 r"   Nc                     SnUc  [         R                  n[         R                  n[         R                  [         l         U(       a+  US   S;   a"  U R                  [         R                  U5        GO_U GHX  nSn	U R
                  R                  U5      R                  [        S9 GH  n
SnU
R                  (       a  U
R                  R                  (       a  U
R                  R                  R                  (       a{  [        U
R                  R                  R                  [        5      nU(       d;  [        SU
R                  R                  R                  < SU
R                  < 35      e[!        U5      nSn	U(       a!  U(       a
  [#        5         [#        S	U
-  5        SnU
R                  nS[%        US
S5      s=:  a  U::  a  O  O    U[         l        g['        U
R                  5      nUR)                  5       (       a|  [+        U5      nU R
                  R,                  R/                  UR0                  UR2                  UUUUUR4                  UR6                  UUR8                  S9
  UR;                  5         GM  [=        UR>                  S5       nU R                  UU5        SSS5        GM     U	(       a  GMI  [A        [B        U-  5      e   U[         l        g! , (       d  f       GMG  = f! U[         l        f = f)a  Prints each of the url strings to stdout.

Args:
  url_strings: String iterable.
  show_header: If true, print a header per file.
  start_byte: Starting byte of the file to print, used for constructing
              range requests.
  end_byte: Ending byte of the file to print; used for constructing range
            requests. If this is negative, the start_byte is ignored and
            and end range is sent over HTTP (such as range: bytes -9)
  cat_out_fd: File descriptor to which output should be written. Defaults to
             stdout if no file descriptor is supplied.
Returns:
  0 on success.

Raises:
  CommandException if no URLs can be found.
FNr   )-zfile://-)bucket_listing_fieldsz(Missing decryption key with SHA256 hash z#. No decryption key matches object Tz
==> %s <==r   )compressed_encoding
start_byteend_byteobject_sizer   decryption_tupleproviderrb)"sysstdoutstderrr+   stdinr   WildcardIteratorIterObjects_CAT_BUCKET_LISTING_FIELDSroot_objectr   	keySha256r   r   r   
url_stringr   printgetattrr   
IsCloudUrlr   
gsutil_apiGetObjectMediar   r   r   r   schemeflushopenobject_namer	   r
   )r   url_stringsshow_headerr2   r3   
cat_out_fdprinted_one
old_stdouturl_strdid_some_workblrdecryption_keywrapperdecryption_key
cat_objectstorage_urlr1   fs                    r   CatUrlStringsCatHelper.CatUrlStringsL   sg   0 K ::j JCJ7	Q+<<**399jA"G-%%66w?KK$> L @c$(!COO$F$F22<<;//44>> Hn#) __77AA^^%& &
 '>n&M# ML3&' kJ 7:vr2@j@. cj- /s~~>K%%''$7
$C!))88##//&9'#(oo(33#8&-- 9 
/   //6!221jA 76W@Z "#9G#CDDc #f cj 76
 cjs2    FK0 B<K0 K&K0 =K0 
K-'	K0 0K=r   )Fr   NN)	__name__
__module____qualname____firstlineno____doc__r    r+   rX   __static_attributes__ r"   r   r   r   0   s#    L#)& !& !#[r"   r   )r^   
__future__r   r   r   r   r%   r8   botor   gslib.cloud_apir   gslib.exceptionr	   r
   gslib.storage_urlr   gslib.utils.encryption_helperr   r   gslib.utils.metadata_utilr   gslib.utilsr   r>   objectr   r`   r"   r   <module>rj      sM    0 & %  ' 	 
  / , 2 2 A F 9 !	 w wr"   