
                         x    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Jr	  SS jr
SS	 jr SS
 jrS rS rg)zKShared utility methods for manipulating metadata of requests and resources.    )absolute_import)print_function)division)unicode_literalsN)storage_v1_messagesc                     U(       a  SU S'   g g )Ngzipzaccept-encoding )headers_dictcompressed_encodings     ,platform/gsutil/gslib/utils/metadata_util.pyAddAcceptEncodingGzipIfNeededr      s     '-L"#     c           	      4   Uc  [         R                  R                  / S9nU c  0 n [        R                  " U 5       HX  u  p#UR
                  R                  [         R                  R                  R                  [        U5      [        U5      S95        MZ     U$ )a  Creates a custom MetadataValue object.

Inserts the key/value pairs in entries.

Args:
  entries: (Dict[str, Any] or None) The dictionary containing key/value pairs
      to insert into metadata. Both the key and value must be able to be
      casted to a string type.
  custom_metadata (apitools_messages.Object.MetadataValue or None): A
      pre-existing custom metadata object to add to. If one is not provided,
      a new one will be constructed.

Returns:
  An apitools_messages.Object.MetadataValue.
)additionalPropertieskeyvalue)	apitools_messagesObjectMetadataValuesix	iteritemsr   appendAdditionalPropertystr)entriescustom_metadatar   r   s       r   CreateCustomMetadatar   ,   s      '..<< = !O_GMM'*jc((//  ..AACE
 	B 	,- + 
r   c                    ^  [        U4S jU R                  R                   5       S5      nUc  SU4$ SU4$ ! [         a    SU4s $ f = f)a/  Filters a specific element out of an object's custom metadata.

Args:
  obj_metadata: (apitools_messages.Object) The metadata for an object.
  search_key: (str) The custom metadata key to search for.
  default_value: (Any) The default value to use for the key if it cannot be
      found.

Returns:
  (Tuple(bool, Any)) A tuple indicating if the value could be found in
  metadata and a value corresponding to search_key (the value at the specified
  key in custom metadata, or the default value if the specified key does not
  exist in the custom metadata).
c              3   `   >#    U  H#  nUR                   T:X  d  M  UR                  v   M%     g 7fNr   ).0attr
search_keys     r   	<genexpr>3GetValueFromObjectCustomMetadata.<locals>.<genexpr>Z   s*      -HdXX+ $**Hs   ..NFT)nextmetadatar   AttributeError)obj_metadatar%   default_valuer   s    `  r    GetValueFromObjectCustomMetadatar-   H   sd    "  -*33HH-.24E }M!!;	  - s   08 8 A	A	c                 T    U R                  S5      =(       d    U R                  S5      $ )zDReturns true if header (which must be lowercase) is a custom header.zx-goog-meta-zx-amz-meta-)
startswith)headers    r   IsCustomMetadataHeaderr1   d   s#    			>	*	Nf.?.?.NNr   c                 z    U R                   =(       a)    U R                   R                  5       R                  S5      $ )zGReturns true if the apitools_messages.Object has gzip content-encoding.r	   )contentEncodinglowerendswith)r+   s    r   ObjectIsGzipEncodedr6   i   s4    

&
& @

&
&
,
,
.
7
7
?Ar   )F)NNr"   )__doc__
__future__r   r   r   r   r   "gslib.third_party.storage_apitoolsr   r   r   r   r-   r1   r6   r
   r   r   <module>r:      s=    R & %  ' 
 W-$< 48 8O
Ar   