
                             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rSSK	J
r
  SSKJr  SS	 jr  SS
 jrSS jrS rg)z/Helper functions for Cloud API implementations.    )absolute_import)print_function)division)unicode_literalsN)ArgumentException)AddQueryParamToUrlc                 ,    U=(       d    U R                   $ )a  Gets a gsutil Cloud API instance.

Since Cloud API implementations are not guaranteed to be thread-safe, each
thread needs its own instance. These instances are passed to each thread
via the thread pool logic in command.

Args:
  cls: Command class to be used for single-threaded case.
  thread_state: Per thread state from this thread containing a gsutil
                Cloud API instance.

Returns:
  gsutil Cloud API instance.
)
gsutil_api)clsthread_states     /platform/gsutil/gslib/utils/cloud_api_helper.pyGetCloudApiInstancer      s     
	''    c                    U R                   nU(       a  [        USU5      n[        R                  (       a&  [	        U[
        5      (       a  UR                  S5      nSUU R                  US.n[        R                  " U5      $ )a  Returns download serialization data.

There are five entries:
  auto_transfer: JSON-specific field, always False.
  progress: How much of the download has already been completed.
  total_size: Total object size.
  url: Implementation-specific field used for saving a metadata get call.
       For JSON, this the download URL of the object.
       For XML, this is a pickled boto key.
  user_project: Project to be billed to, added as query param.

Args:
  src_obj_metadata: Object to be downloaded.
  progress: See above.
  user_project: User project to add to query string.

Returns:
  Serialization data for use with Cloud API GetObjectMedia.
userProjectasciiFalse)auto_transferprogress
total_sizeurl)
	mediaLinkr   sixPY3
isinstancebytesdecodesizejsondumps)src_obj_metadatar   user_projectr   serialization_dicts        r   GetDownloadSerializationDatar$   1   sp    . 	""#
S-
>CWW#uJJwc $))	 
&	''r   c                     U (       aD  [        5       nU  H2  nUS;   a  M  UR                  [        R                  " SSU5      5        M4     U$ g)a  Removes 'items/' from the input fields and converts it to a set.

Args:
  list_fields: Iterable fields usable in ListBuckets/ListObjects calls.

Returns:
  Set of fields usable in GetBucket/GetObjectMetadata calls (None implies
  all fields should be returned).
)kindnextPageTokenprefixeszitems/ N)setaddresub)list_fields
get_fieldsfields      r   ListToGetFieldsr1   Z   sL     J	7	7 	nnRVVIr512   r   c                     U (       d  [        S5      eU R                  (       d  [        S5      eU R                  (       d  [        S5      eg)zEnsures dst_obj_metadata supplies the needed fields for copy and insert.

Args:
  dst_obj_metadata: Metadata to validate.

Raises:
  ArgumentException if metadata is invalid.
z3No object metadata supplied for destination object.zCObject metadata supplied for destination object had no object name.zCObject metadata supplied for destination object had no bucket name.N)r   namebucket)dst_obj_metadatas    r   ValidateDstObjectMetadatar6   o   sR     

=? ?			
MO O		 	 
MO O 
!r   )N)r   N)__doc__
__future__r   r   r   r   r   r,   r   gslib.cloud_apir   gslib.utils.text_utilr   r   r$   r1   r6    r   r   <module>r<      sC    6 & %  '  	 
 - 4(& +,.2&(R*Or   