
    &              	          S 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rSSK	r	SSK
Jr  SSKJr  SSKJr  S	rS
rSrSrS\-  rSrSr0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_S!S_S"S_S#S_SSS$S%S%S%S%S&.Er " S' S(\R0                  5      rS) rS* rS+ rS, rS- rS. rS/ r S0 r!S1 r" S:S2 jr#S3 r$S4 r%S5 r& S;S6 jr'S7 r(S8 r)S9 r*g)<zUtils for resource classes.    )absolute_import)division)unicode_literalsN)storage_url)resource_reference)resource_projector         z     zgoog-reserved-file-is-symlinkz1Skipping item {} with unsupported object type: {}RPOz				LabelsACL	Autoclassz			zLocation typeMetagenerationzTime createdzTime updatedzSatisfies PZSzStorage classzDefault ACLzPlacement locationsz		zRetention PolicyzLocation constraintzVersioning enabledzLogging configurationzWebsite configurationz 			)zRequester Pays enabledzDefault KMS keyzCORS configurationzLifecycle configurationzDefault Event-Based HoldzBucket Policy Only enabledzPublic access preventionc                       \ rS rSrSrSrg)UnsupportedObjectTypeI   GLACIER N)__name__
__module____qualname____firstlineno__r   __static_attributes__r       Alib/googlecloudsdk/command_lib/storage/resources/resource_util.pyr   r   I   s    'r   r   c                     [        U [        R                  5      (       aR  U R                  R                  [        R
                  R                  :X  a   U R                  S:X  a  [        R                  $ g)a^  Returns unsupported type or None if object is supported for copies.

Currently, S3 Glacier objects are the only unsupported object type.

Args:
  resource (ObjectResource|FileObjectResource): Check if this resource is
    supported for copies.

Returns:
  (UnsupportedObjectType|None) If resource is unsupported, the unsupported
    type, else None.
r   N)

isinstancer   ObjectResourcer   schemeProviderPrefixS3storage_classr   r   )resources    r   get_unsupported_object_typer'   M   sU     -<<==



%
%)C)C)F)F
F

 
 I
- (((	r   c                 4    [         R                  " U [        S9$ )z.Return json.dumps with formatting options set.)indent)jsondumpsMETADATA_LINE_INDENT_LENGTHitems    r   configured_json_dumpsr/   c   s    	D!<	==r   c                     U c  g[        U [        R                  5      (       d  [        S[        U 5      -  5      eU R	                  S5      $ )z2Returns a formatted string from a datetime object.Nz(Expected a datetime object, but got a %sz%Y-%m-%dT%H:%M:%S%z)r    datetime
ValueErrortypestrftimedatetime_objects    r   )get_formatted_string_from_datetime_objectr7   h   sL    	OX%6%6	7	7
2T/5JJ  
	!	!"7	88r   c                     [        U [        5      (       a  [        U 5      $ [        U [        R                  5      (       a  [	        U 5      $ [        U [        R
                  5      (       a  U R                  S5      $ U $ )z<Converts values encountered in metadata to be JSON-parsable.z%Y-%m-%d)r    	Exceptionstrr1   r7   dater4   values    r   convert_to_json_parsable_typer>   s   s\    y!!u:x(())4U;;x}}%%>>*%%	,r   c                 ,   U(       a  U R                   nOkSU R                  R                  0nU R                  5       nUR                   H3  nXT;   a  UR                  U5      nO[        XS5      n[        U5      X5'   M5     [        R                  " U5      $ )a#  Makes a resource better for returning from describe and list commands.

Display = Removes complex nested objects and makes other string tweaks.

Args:
  resource (resource_reference.Resource): Resource to format.
  display_titles_and_defaults (namedtuple): Contains names of fields for
    display.
  display_raw_keys (bool): Displays raw API responses if True, otherwise
    standardizes metadata keys. If True, `resource` must have a metadata
    attribute.

Returns:
  Dictionary representing input resource with optimizations described above.
r   N)
metadatar   
url_stringget_formatted_acl_fieldsgetgetattrr>   r   MakeSerializable)r&   display_titles_and_defaultsdisplay_raw_keysdisplay_dataformatted_acl_dictfieldr=   s          r   get_display_dict_for_resourcerL      s    $ $$L "8#7#7#B#BCL!335,44		$"&&u-.9%@l 5 
	,	,\	::r   c                     U R                  5       nU(       a)  X-
  R                  [        R                  R                  S9$ U $ )z/Converts datetime object to UTC and returns it.)tzinfo)	utcoffsetreplacer1   timezoneutc)r6   offsets     r   convert_datetime_object_to_utcrT      s>     $$&&$--X5F5F5J5J-KK	r   c                 F    U (       d  g[        U 5      R                  S5      $ )zEConverts datetime to UTC and returns formatted string representation.Nonez%Y-%m-%dT%H:%M:%SZ)rT   r4   r5   s    r   get_formatted_timestamp_in_utcrW      s#    		'	8	A	A
 r   c                 n    [        [        R                  " [        U 5      R	                  5       5      5      $ )zBConverts datetime to UTC and returns Unix seconds-since-epoch int.)intcalendartimegmrT   	timetupler5   s    r   get_unix_timestamp_in_utcr]      s,    	oo
(
9
C
C
E
 r   c                 n    [         R                  " [        U5      [        S9nSR	                  [        XS9$ )zReturns metadata section with potentially multiple lines of JSON.

Args:
  key_string (str): Key to give section.
  value_to_convert_to_json (list|object): json_dump_method run on this.

Returns:
  String with key followed by JSON version of value.
prefixz{indent}{key}:
{json})r)   keyr*   )textwrapr)   r/   METADATA_LINE_INDENT_STRINGformat)
key_stringvalue_to_convert_to_jsonjson_strings      r    get_metadata_json_section_stringrh      s?     45(*+ 
"	(	((j 
) 
L Lr   c                     [        S[        [        U 5      -
  [        -   U-
  5      nSR	                  SS[        U-   -  U UUS9$ )z+Returns metadata line with correct padding.   z({indent}{key}:{_:>{left_spacing}}{value} r   )_r)   ra   left_spacingr=   )maxLONGEST_METADATA_KEY_LENGTHlenr,   rd   )re   value_stringextra_indentspaces_left_of_values       r   "get_padded_metadata_key_value_linert      sa    
 Q!<s:!N!<"=?K"L N	3	:	:
/,>?
' 
; 
 r   c                 .    [        U5      n[        X5      $ )zBReturns _get_padded_metadata_value_line with formatted time value.)rW   rt   )re   
value_timeformatted_times      r   get_padded_metadata_time_linerx      s    1*=.	+J	GGr   c                     [          U  S3R                  [        5      n[        R                  " [        U5      SS9nU U 3$ )zEReturns object metadata JSON(multiple lines) section in gsutil style.:rk   r_   )GSUTIL_METADATA_LINE_INDENTljust!GSUTIL_LIMIT_BREAKING_LINE_LENGTHrb   r)   r/   )re   rf   padded_key_stringrg   s       r   .get_gsutil_object_metadata_json_section_stringr      sR    
 66zl!DKK' 45+
 {m	,,r   c                 f    [         U    n[        R                  " [        U5      SS9nSU  SU SU 3$ )zEReturns bucket metadata JSON(multiple lines) section in gsutil style.z	  r_   r   rz   
))_LEFT_TAB_FOR_GSUTIL_BUCKET_METADATA_KEYSrb   r)   r/   )re   rf   rs   rg   s       r   .get_gsutil_bucket_metadata_json_section_stringr      sG     C:N45+
 j\/0;-	@@r   c                 P    [         U-   U  S3R                  [        5      nU U 3$ )zBReturns object metadata line with correct padding in gsutil style.rz   )r{   r|   r}   )re   rq   r)   r~   s       r   0get_gsutil_padded_object_metadata_key_value_liner     s:    
 &
.0A>	E
+,  |n	--r   c                 (    [         U    nSU  SU U 3$ )zBReturns bucket metadata line with correct padding in gsutil style.r   rz   )r   )re   rq   rs   s      r   0get_gsutil_padded_bucket_metadata_key_value_liner     s&    B:Nj\/0	??r   c                     U S;   $ )z3There are falsy values we want to keep as metadata.)r   g        Fr   r<   s    r   $should_preserve_falsy_metadata_valuer     s     
/	!!r   c                 H    U (       d  [        U 5      (       a  g[        U 5      $ )zDReturns string showing if item exists. May return 'None', '[]', etc.Present)r   r:   r-   s    r   get_exists_stringr     s    	1$77t9r   )r   )rj   )+__doc__
__future__r   r   r   rZ   r1   enumr*   rb   "googlecloudsdk.command_lib.storager   ,googlecloudsdk.command_lib.storage.resourcesr   googlecloudsdk.core.resourcer   ro   r}   r,   r{   rc   SYMLINK_METADATA_KEY!UNSUPPORTED_OBJECT_WARNING_FORMATr   Enumr   r'   r/   r7   r>   rL   rT   rW   r]   rh   rt   rx   r   r   r   r   r   r   r   r   r   <module>r      s   " &  '      : K ; ! $& ! % !$??  7  8 "-	:-j- 
:- 	-
 X- h- H- H- X- X- 8- 6- - 6- &-  V!-" V#-$ %!# $"& $1- )8DII ,>
9	";J	L& 56H- 
A &'.@"r   