
    E                         d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ ddl	m
Z ddlmZ dd	lmZ dd
lmZ ddlmZ ddlZ G d d ej*                  ej,                  ej.                              Zd Zy)zJCross-version utility classes and functions for gcloud functions commands.    )absolute_import)division)unicode_literalsN)Any)util)client)base)parser_extensions)flagsc                        e Zd ZdZ fdZej                  dej                  de	fd       Z
ej                  dej                  de	fd       Zej                  dej                  de	fd       Z xZS )FunctionResourceCommanda  Mix-in for single function resource commands that work with both v1 or v2.

  Which version of the command to run is determined by the following precedence:
  1. Explicit setting via the --gen2/--no-gen2 flags or functions/gen2 property.
  2. The generation of the function if it exists.
  3. The v2 API by default if the function doesn't exist.

  Subclasses should add the function resource arg and --gen2 flag.
  c                 :    t        t        | 
  |i | d | _        y )N)superr   __init___v2_function)selfargskwargs	__class__s      0lib/googlecloudsdk/command_lib/functions/util.pyr   z FunctionResourceCommand.__init__,   s     	
!414B6BD    r   returnc                      y)z$Runs the command against the v1 API.N r   r   s     r   _RunV1zFunctionResourceCommand._RunV10       r   c                      y)z$Runs the command against the v2 API.Nr   r   s     r   _RunV2zFunctionResourceCommand._RunV24   r   r   c                 *   t        j                         r| j                  |      S t        j                         r| j	                  |      S t        j                  | j                               }|j                  |j                  j                  j                         j                               | _        | j                  rDt        | j                  j                        dk(  r| j                  |      S | j	                  |      S | j                  |      S )zRuns the command.

    Args:
      args: The arguments this command was invoked with.

    Returns:
      The result of the command.

    Raises:
      HttpException: If an HttpError occurs.
    GEN_2)r   ShouldUseGen2r   ShouldUseGen1r   	client_v2FunctionsClientReleaseTrackGetFunctionCONCEPTSnameParseRelativeNamer   strenvironment)r   r   r   s      r   RunzFunctionResourceCommand.Run8   s     [[[[&&t'8'8':;F**  "//1D 	T**	+w	6{{4  {{4  ;;tr   )__name__
__module____qualname____doc__r   abcabstractmethodr
   	Namespacer   r   r   api_util_v1 CatchHTTPErrorRaiseHTTPExceptionr.   __classcell__)r   s   @r   r   r   !   s     /*44 / / / /*44 / / / //'11 c  0r   r   c                 P    t        j                  dd| j                  dd            S )zFormats a timestamp which will be presented to a user.

  Args:
    timestamp: Raw timestamp string in RFC3339 UTC "Zulu" format.

  Returns:
    Formatted timestamp string.
  z(\.\d{3})\d*Z$z\1T )resubreplace)	timestamps    r   FormatTimestampr@   Y   s%     
!5)*;*;C*E	FFr   )r2   
__future__r   r   r   r3   r<   typingr   #googlecloudsdk.api_lib.functions.v1r   r6   #googlecloudsdk.api_lib.functions.v2r   r$   googlecloudsdk.callioper	   r
   $googlecloudsdk.command_lib.functionsr   sixwith_metaclassABCMetaCommandr   r@   r   r   r   <module>rK      sZ    Q &  ' 
 	  C C ( 5 6 
50c00dllK 5p	Gr   