
    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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mZ ddlmZ ddlZd Zd Zd Z G d dej0                        Z G d dej0                        Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d d e      Z! G d! d"e      Z" G d# d$e       Z# G d% d&e      Z$ G d' d(e      Z% G d) d*e%      Z& G d+ d,e      Z' G d- d.e       Z( G d/ d0e      Z) G d1 d2e      Z* G d3 d4e      Z+ G d5 d6e      Z, G d7 d8e      Z-y)9aY  Classes to specify concept and resource specs.

To use a concept, give it at least help text and a name (or use
the default name if the concept provides one) and add it to a concept manager.
During command.Run, the parsed concept will be available under args.
For example:

from googlecloudsdk.command_lib.concepts import concept_managers

  def Args(self, parser):
    manager = concept_managers.ConceptManager()
    concept = concepts.SimpleArg('foo', help_text='Provide the value of foo.')
    manager.AddConcept(concept)
    manager.AddToParser(parser)

  def Run(self, args):
    return args.foo
    )absolute_import)division)unicode_literalsN)deps)base)dependency_managers)
exceptions)names)scaled_integer)semver)timesc                 |    t        j                  |       j                  d      }|d   j                         |dd z   S )z4Return the string representation of sub-exception e..r      N)six	text_typerstripupper)emessages     @lib/googlecloudsdk/command_lib/concepts/all_concepts/concepts.py_SubExceptionr   7   s9    MM!##C('				gabk	))    c                 <    | sy| d   j                         r| S | dz   S )z:Appends a space to text if it is not empty and returns it.  isspacetexts    r   _Insertr"   =   s'    		"XK	r   c                 <    | sy| d   j                         r| S d| z   S )z:Inserts a space to text if it is not empty and returns it.r   r   r   r   r    s    r   _Appendr$   F   s'    		"XK	tr   c                   F     e Zd ZdZ	 	 d fd	Zd Zd Zd Zd Zd Z	 xZ
S )		SimpleArga  A basic concept with a single attribute.

  Attributes:
    fallthroughs: [calliope.concepts.deps.Fallthrough], the list of sources of
      data, in priority order, that can provide a value for the attribute if
      not given on the command line. These should only be sources inherent to
      the attribute, such as associated properties, not command- specific
      sources.
    positional: bool, True if the concept is a positional value.
    completer: core.cache.completion_cache.Completer, the completer associated
      with the attribute.
    metavar: string,  a name for the argument in usage messages.
    default: object, the concept value if one is not otherwise specified.
    choices: {name: help}, the possible concept values with help text.
    action: string or argparse.Action, the basic action to take when the
       concept is specified on the command line. Required for the current
       underlying argparse implementation.
  c	                     |t        j                  d      |xs g | _        || _        || _        || _        || _        || _        || _        t        t        | .  |fi |	 yzInitializes the concept.NzConcept name required.)r	   InitializationErrorfallthroughs
positional	completermetavardefaultchoicesactionsuperr&   __init__)selfnamer*   r+   r,   r-   r.   r/   r0   kwargs	__class__s             r   r2   zSimpleArg.__init__c   sg     |**+CDD$*D DODNDLDLDLDK	)T#D3F3r   c                     t        j                  d| | j                  | j                  | j                  | j
                  | j                  | j                  d| j                         S )N)conceptr*   r,   r-   r.   r0   r/    )	r   	Attributer*   r,   r-   r.   r0   r/   MakeArgKwargsr3   s    r   r:   zSimpleArg.Attributeq   sY    >> 2$'+'8'8$(NN"&,,"&,,!%"&,,2 !..02 2r   c                      y)zReturns the type constraints message text if any.

    This message text decribes the Validate() method constraints in English.
    For example, a regex validator could provide prose for a better UX than
    a raw 100 char regex pattern.
    r   r9   r<   s    r   ConstraintszSimpleArg.Constraints{   s     r   c                     	 |j                   S # t        j                  $ rC}| j                  r-t	        j
                  | j                         t        |            Y d}~yd}~ww xY w)aa  Parses the concept.

    Args:
      dependencies: googlecloudsdk.command_lib.concepts.dependency_managers
        .DependencyView, the dependency namespace for the concept.

    Raises:
      exceptions.MissingRequiredArgumentException, if no value is provided and
        one is required.

    Returns:
      str, the value given to the argument.
    N)valuedeps_libAttributeNotFoundErrorrequiredr	   MissingRequiredArgumentErrorGetPresentationNamer   )r3   dependenciesr   s      r   ParsezSimpleArg.Parse   sY    ** 	55$$&a(8: 	:	s    A$9AA$c                     | j                   rt        j                  | j                        S t        j                  | j                        S )zDGets presentation name for the attribute, either positional or flag.)r+   r
   ConvertToPositionalNamer4   ConvertToFlagNamer<   s    r   rE   zSimpleArg.GetPresentationName   s3    **49955""499--r   c                 8    | j                   xr | j                   S )ai  Determines whether command line argument for attribute is required.

    Returns:
      bool: True, if the command line argument is required to be provided,
        meaning that the attribute is required and that there are no
        fallthroughs. There may still be a parsing error if the argument isn't
        provided and none of the fallthroughs work.
    )rC   r*   r<   s    r   IsArgRequiredzSimpleArg.IsArgRequired   s     ==2!2!222r   )NFNNNNN)__name__
__module____qualname____doc__r2   r:   r>   rG   rE   rL   __classcell__r6   s   @r   r&   r&   O   s0    & KO@D42,.	3r   r&   c                   H     e Zd ZdZd	 fd	Zd Zd Zd Zd Zd Z	d Z
 xZS )
GroupArgzgA group concept.

  Attributes:
    mutex: bool, True if this is a mutex (mutually exclusive) group.
  c                     |t        j                  d      || _        || _        g | _        t        t        |   |fi | yr(   )r	   r)   mutexprefixesconceptsr1   rT   r2   )r3   r4   rV   rW   r5   r6   s        r   r2   zGroupArg.__init__   sC    |**+CDDDJDMDM	(D"4262r   c                     t        j                   |      }| j                  |j                        |_        | j                  j	                  |       y N)copy_GetSubConceptNamer4   rX   append)r3   r8   new_concepts      r   
AddConceptzGroupArg.AddConcept   s;    ))G$K..{/?/?@KMM%r   c           	          t        j                  d| | j                  D cg c]  }|j                          c}| j                  d| j                         S c c}w )N)r8   
attributesrV   r9   )r   AttributeGrouprX   r:   rV   r;   )r3   cs     r   r:   zGroupArg.Attribute   sV     +/==9=aAKKM=9jj 


	 9s   Ac                 h    | j                   r%t        j                  | j                  dz   |z         S |S )N_)rW   r
   ConvertToNamespaceNamer4   )r3   attribute_names     r   r\   zGroupArg._GetSubConceptName   s-    }}))$))c/N*JKKr   c                     |S )z:Returns a namespace with the values of the child concepts.r9   )r3   rF   s     r   rG   zGroupArg.Parse   s    r   c                     | j                   S )z/Gets presentation name for the attribute group.)r4   r<   s    r   rE   zGroupArg.GetPresentationName   s    99r   c                 X    | j                   xr t        d | j                  D               S )ag  Determines whether the concept group is required to be specified.

    Returns:
      bool: True, if the command line argument is required to be provided,
        meaning that the attribute is required and that there are no
        fallthroughs. There may still be a parsing error if the argument isn't
        provided and none of the fallthroughs work.
    c              3   4   K   | ]  }|j                     y wrZ   )r*   ).0rc   s     r   	<genexpr>z)GroupArg.IsArgRequired.<locals>.<genexpr>   s     $K]Q^^]s   )rC   anyrX   r<   s    r   rL   zGroupArg.IsArgRequired   s%     ==K$KT]]$K!KKKr   )FF)rM   rN   rO   rP   r2   r_   r:   r\   rG   rE   rL   rQ   rR   s   @r   rT   rT      s,    3&

	Lr   rT   c                   :     e Zd ZdZd Zd Zd Z fdZd Z xZ	S )ConceptTypezConcept type base class.

  All concept types derive from this class. The methods implement lexing,
  parsing, constraints, help text, and formatting.
  c                     |S )ax  Converts a value from string and returns it.

    The converter must do syntax checking and raise actionable exceptions. All
    non-space characters in string must be consumed. This method may raise
    syntax exceptions, but otherwise does no validation.

    Args:
        string: The string to convert to a concept type value.

    Returns:
      The converted value.
    r9   r3   strings     r   ConvertzConceptType.Convert   s	     Mr   c                 ,    t        j                  |      S )ak  Returns the string representation of a parsed concept value.

    This method is the inverse of Convert() and Parse(). It returns the
    string representation of a parsed concept value that can be used in
    formatted messages.

    Args:
        value: The concept value to display.

    Returns:
      The string representation of a parsed concept value.
    )r   r   r3   r@   s     r   DisplayzConceptType.Display   s     ==r   c                     |S )ah  Returns the normalized value.

    Called after the value has been validated. It normalizes internal values
    for compatibility with other interfaces. This can be accomplished by
    subclassing with a shim class that contains only a Normalize() method.

    Args:
        value: The concept value to normalize.

    Returns:
      The normalized value.
    r9   rv   s     r   	NormalizezConceptType.Normalize  s	     Lr   c                     t         t        |   |      }| j                  |      }| j	                  |       | j                  |      S )zDConverts, validates and normalizes a value string from dependencies.)r1   rp   rG   rt   Validatery   )r3   rF   rs   r@   r6   s       r   rG   zConceptType.Parse  s=    ;+L9FLL EMM%>>%  r   c                      y)a&  Validates value.

    Syntax checking has already been done by Convert(). The validator imposes
    additional constraints on valid values for the concept type and must raise
    actionable exceptions when the constraints are not met.

    Args:
      value: The concept value to validate.
    Nr9   rv   s     r   r{   zConceptType.Validate  s     	r   )
rM   rN   rO   rP   rt   rw   ry   rG   r{   rQ   rR   s   @r   rp   rp      s!     !
	r   rp   c                       e Zd ZdZddZy)EndpointzTypeWithIntervalConstraint endpoint.

  Attributes:
    string: string, the representation of the endpoint value.
    closed: bool, True if the interval is closed (the endpoint is included).
  c                 .    || _         || _        d | _        y rZ   )rs   closedr@   )r3   rs   r   s      r   r2   zEndpoint.__init__2  s    DKDKDJr   N)T)rM   rN   rO   rP   r2   r9   r   r   r~   r~   *  s    r   r~   c                   <     e Zd ZdZ	 	 	 d fd	Zd Zd Zd Z xZS )TypeWithIntervalConstrainta  Concept type with value interval constraints.

  Validates that a ConceptType value is within the interval defined by min and
  max endpoints. A missing min or max endpoint indicates that there is no min or
  max value, respectively.

  Attributes:
    _min_endpoint: Endpoint, the minimum value interval endpoint.
    _max_endpoint: Endpoint, the maximum value interval endpoint.
    _constraint_kind: string, the interval value type name.
    _convert_endpoint: f(str)=>x, converts an endpoint string to a value.
    _convert_interval: f(str)=>x, converts an interval value to a value.
    _display_endpoint: f(value)=>str, displays an interval endpoint.
  c                 n   t        t        | 
  |fi | || _        || _        |xs d| _        |xs | j                  | _        |xs | j                  | _	        |xs d | _
        | j                  r| j                  | j                  d       | j                  r| j                  | j                  d       y y )Nr@   c                     | S rZ   r9   )xs    r   <lambda>z5TypeWithIntervalConstraint.__init__.<locals>.<lambda>Q  s    ar   zmin endpointzmax endpoint)r1   r   r2   _min_endpoint_max_endpoint_kindrt   _convert_endpointrw   _display_endpoint_convert_value_ConvertEndpoint)
r3   r4   min_endpointmax_endpointconstraint_kindconvert_endpointconvert_valuedisplay_endpointr5   r6   s
            r   r2   z#TypeWithIntervalConstraint.__init__H  s     

$d4TDVD%D%D +GDJ-=D-=D'8KD
D..?
D..? r   c                    d}	 | j                  |j                        |_        y# t        j                  $ rA}t        j                  |      j                  dd      d   j                  d      }Y d}~n*d}~wt        t        f$ r}t        |      }Y d}~nd}~ww xY wt        j                  | j                         ||j                  |dz         )z+Declaration time endpoint conversion check.Nz. r   r   )r   rs   r@   r	   
ParseErrorr   r   splitr   AttributeError
ValueErrorr   ConstraintErrorrE   )r3   endpointkindr   r   s        r   r   z+TypeWithIntervalConstraint._ConvertEndpointW  s    G!--hoo>hn   ?a &&tQ/299#>gJ' !a g!

$
$  "D(//7S=J Js     % B7A44BBBc                    g }| j                   ra| j                   j                  }| j                   j                  rd}nd}|j                  dj	                  || j                  |                   | j                  ra| j                  j                  }| j                  j                  rd}nd}|j                  dj	                  || j                  |                   |sydj	                  | j                  dj                  |            S )	1Returns the type constraints message text if any.greater than or equal togreater thanz{} {}less than or equal to	less thanr   zThe {} must be {}.z and )	r   r@   r   r]   formatr   r   r   join)r3   
boundariesr   boundarys       r   r>   z&TypeWithIntervalConstraint.Constraintsd  s    J##))h				"	"-!
D**846 7##))h				"	"*
D**846 7&&tzz7<<
3KLLr   c                 H   | j                  |      }d }| j                  r;| j                  j                  }| j                  j                  r||k  r
d}n||k  rd}|sG| j                  r;| j                  j                  }| j                  j                  r||kD  r
d}n||k\  rd}|r}t        j                  | j                         dj                  | j                  d   j                         | j                  dd  | j                  |      || j                                    y )Nr   r   r   r   z{}{} [{}] must be {} [{}].r   r   )r   r   r@   r   r   r	   ValidationErrorrE   r   r   r   r   )r3   r@   invalidr   s       r   r{   z#TypeWithIntervalConstraint.Validate{  s   &EG##))h				"	"8.'H t))##))h				"	"8+'H&&

"
"
$
&
-
-jjm!!#jjn$$U+$$X.01 1 r   )NNNNNN)	rM   rN   rO   rP   r2   r   r>   r{   rQ   rR   s   @r   r   r   8  s+     <@JN $@JM.1r   r   c                   F     e Zd ZdZdZdZed        Z	 	 d fd	Zd Z	 xZ
S )TypeWithSizeConstraintzConcept type with size interval constraints.

  Validates that a ConceptType size is within the interval defined by min and
  max endpoints. A missing min or max endpoint indicates that there is no min or
  max size, respectively.
  ,^c                      |rt        |      S dS )Nr   )len)clsr@   s     r   _GetIntervalValuez(TypeWithSizeConstraint._GetIntervalValue  s    3u:%A%r   c                 |    t        t        | 
  |f|xs d|xs t        |xs | j                  |xs t
        d| y )Nsize)r   r   r   r   )r1   r   r2   intr   str)r3   r4   r   r   r   r   r5   r6   s          r   r2   zTypeWithSizeConstraint.__init__  sK    	
 $0'16)0S#=t'='=)0S r   c                 .   |sy| j                   }|j                  | j                        rY| j                  |dd v rH|dd j                  | j                  d      \  }}|s$t	        j
                  | j                         d      |j                  |      |fS )aO  Splits string on _DEFAULT_DELIM or the alternate delimiter expression.

    By default, splits on commas:
        'a,b,c' -> ['a', 'b', 'c']

    Alternate delimiter syntax:
        '^:^a,b:c' -> ['a,b', 'c']
        '^::^a:b::c' -> ['a:b', 'c']
        '^,^^a^,b,c' -> ['^a^', ',b', 'c']

    See `gcloud topic escaping` for details.

    Args:
      string: The string with optional alternate delimiter expression.

    Raises:
      exceptions.ParseError: on invalid delimiter expression.

    Returns:
      (string, delimiter) string with the delimiter expression stripped, if any.
    NNr   NzqInvalid delimiter. Please see $ gcloud topic escaping for information on escaping list or dictionary flag values.)_DEFAULT_DELIM
startswith
_ALT_DELIMr   r	   r   rE   )r3   rs   delims      r   _SplitzTypeWithSizeConstraint._Split  s    , E)doo.KQRj&&t:meV##$$&FG 	G <<%%r   )NNNN)rM   rN   rO   rP   r   r   classmethodr   r2   r   rQ   rR   s   @r   r   r     s:     .*& & CG48 &r   r   c                   0     e Zd ZdZd fd	Zd Zd Z xZS )TypeWithRegexConstraintzConcept type with regex constraint.

  Attributes:
    _regex: string, an unanchored regular expression pattern that must match
      valid values.
    _constraint_details: string, optional prose that describes the regex
      constraint.
  c                 J    t        t        | 
  |fi | || _        || _        y rZ   )r1   r   r2   _regex_constraint_details)r3   r4   regexconstraint_detailsr5   r6   s        r   r2   z TypeWithRegexConstraint.__init__  s'    	
!41$A&ADK1Dr   c                     | j                   sy| j                  r| j                  S dj                  | j                         S )r   r   z5The value must match the regular expression ```{}```.)r   r   r   r<   s    r   r>   z#TypeWithRegexConstraint.Constraints  s;    ;;%%%BII r   c                    | j                   r}t        j                  | j                   | j                  |            sMt	        j
                  | j                         dj                  | j                  |      | j                               y y )NzValue [{}] does not match [{}].)r   rematchrw   r	   r   rE   r   rv   s     r   r{   z TypeWithRegexConstraint.Validate  sk    {{288DKKe1DE&&

"
"
$
+
2
2ll5!kk  F{r   r   )rM   rN   rO   rP   r2   r>   r{   rQ   rR   s   @r   r   r     s    2
r   r   c                   0     e Zd ZdZd fd	Zd Zd Z xZS )BooleanzBoolean value concept.c                     |rdnd}|j                  dd      }|r8| j                         }|j                  d      r|dj                  |dd        z  }||d<   t	        t
        |   |f||d| y )	Nstore_false
store_true	help_textzA Boolean value.z--z' On by default, use --no-{} to disable.   )r.   r0   )getrE   r   r   r1   r   r2   )r3   r4   r.   r5   r0   r   presentationr6   s          r   r2   zBoolean.__init__  s    %]<F

;(:;I--/l		 	 	&>EE 		#F;	'4!$ , ,$*,r   c                     |y|dk(  s|j                         dk(  ry|dk(  s|j                         dk(  ryt        j                  | j                         dj	                  |            )NF1trueT0falsezInvalid Boolean value [{}].)lowerr	   r   rE   r   rr   s     r   rt   zBoolean.Convert  se    ~}&0}'1


  "%,,V46 6r   c                     |rdS dS )z/Returns the display string for a Boolean value.r   r   r9   rv   s     r   rw   zBoolean.Display  s    6''r   rZ   )rM   rN   rO   rP   r2   rt   rw   rQ   rR   s   @r   r   r     s    
,
6(r   r   c                   4     e Zd ZdZd fd	Zd Z fdZ xZS )EnumzEnum value concept.c                     |st        j                  d      |r||vrt        j                  d      || _        t        t        |   |f||d| y )Nz(Choices must be specified for Enum type.z*Enum default value must be a valid choice.)r/   r.   )r	   r)   r/   r1   r   r2   )r3   r4   r/   r.   r5   r6   s        r   r2   zEnum.__init__  s^    **
46 67')**
68 8DL	$tPWgPPr   c                 r   	 |j                         }|| j                  vr|j                         | j                  vrdt        j                  | j                         dj                  |dj                  t        | j                  j                                                 |S # t        t        f$ r |cY S w xY w)Nz)Invalid choice [{}], must be one of [{}].r   )r   r/   r   r	   r   rE   r   r   sortedkeysr   r   )r3   rs   choices      r   rt   zEnum.Convert!  s    	||~f	t||	#dll(J##$$&7>>(9(9(;!<=?@ 	@ mJ' ms   BB" "B65B6c                 b   t        j                         }|j                  d       t        t	        j
                  | j                              D ]&  \  }}|j                  dj                  ||             ( dj                  t        t        t        | /               |j                               S )z.Appends enum values to the original help text.
+
*{}*::: {}
z({}Must be one of the following values:{})ioStringIOwriter   r   	iteritemsr/   r   r"   r1   r   BuildHelpTextgetvalue)r3   bufkeyr   r6   s       r   r   zEnum.BuildHelpText-  s    
++-CIIg t||!<=Y	ii%%c956 > 	399E$356	HIr   r   )rM   rN   rO   rP   r2   rt   r   rQ   rR   s   @r   r   r     s    Q
I Ir   r   c                   "     e Zd ZdZ fdZ xZS )StringzString value concept.c                 @    d|vrd|d<   t        t        | 
  |fi | y )Nr   zA string value.)r1   r   r2   )r3   r4   r5   r6   s      r   r2   zString.__init__;  s)    & -f[	&$ 00r   )rM   rN   rO   rP   r2   rQ   rR   s   @r   r   r   8  s    1 1r   r   c                   4     e Zd ZdZd fd	Z fdZd Z xZS )IntegerzInteger value concept.

  Attributes:
    _unlimited: bool, the value 'unlimited' specifies the largest valid value.
      Internally it's represented as None.
  c                 <    || _         t        t        |   |fi | y rZ   )
_unlimitedr1   r   r2   r3   r4   	unlimitedr5   r6   s       r   r2   zInteger.__init__I  s    DO	'4!$1&1r   c                 X    dj                  t        t        t        |                      S )z1Appends integer syntax to the original help text.z+{}Must be a string representing an integer.)r   r"   r1   r   r   r3   r6   s    r   r   zInteger.BuildHelpTextM  s*     	6<<E'4689	;<r   c           	          |y 	 t        |      S # t        $ rW}| j                  r
|dk(  rY d }~y t        j                  | j                         dj                  t        |                  d }~ww xY w)Nr   z{}.)r   r   r   r	   r   rE   r   r   r3   rs   r   s      r   rt   zInteger.ConvertS  sj    ~*[ *	V{2!!

"
"
$
,,}Q'
(* **s   
 	A0A+<A++A0FrM   rN   rO   rP   r2   r   rt   rQ   rR   s   @r   r   r   A  s    2<
*r   r   c                   D     e Zd ZdZ	 	 d fd	Zd Z fdZd Zd Z xZ	S )ScaledIntegera  ISO Decimal/Binary scaled Integer value concept.

  ISO/IEC prefixes: 1k == 1000, 1ki == 1024.

  Attributes:
    _default_unit: string, the unit suffix if none is specified.
    _output_unit: string, the implicit output unit. Integer values are
      divided by the output unit value.
    _output_unit_value: int, the output unit value.
    _type_abbr: string, the type abbreviation, for example 'b/s' or 'Hz'.
    _type_details: string, prose that describes type syntax details.
  c                 V   || _         || _        || _        | j                  r$| j                  d| j                        \  | _        }|| _        | j                  r*| j                  d| j                        \  | _        | _        nd| _        |xs d| _        t        t        | &  |fi | y )Nzdefault scaled integer unitzoutput scaled integer unitr   zqMust be a string representing an ISO/IEC Decimal/Binary scaled integer. For example, 1k == 1000 and 1ki == 1024. )
r4   
_type_abbr_default_unit_GetUnitValue_output_unit_output_unit_value_type_detailsr1   r   r2   )	r3   r4   default_unitoutput_unit	type_abbrtype_detailsr5   re   r6   s	           r   r2   zScaledInteger.__init__n  s    DIDO%D"00
'););=d!#D373E3E
&(9(94;0d0 !"d% >	= 	 
-'77r   c           	          | j                   rt        j                  |      }	 |t        j                  |      fS # t        $ r3}t        j                  | j                  ||t        |      dz         d}~ww xY w)z3Returns the integer unit suffix and value for unit.r   N)	r   r   DeleteTypeAbbrGetUnitSizer   r	   r   r4   r   )r3   r   unitr   s       r   r   zScaledInteger._GetUnitValue  sn    **40d9>--d333 9&&
))T4q!1C!79 99s   : 	A6.A11A6c                    | j                   rdj                  | j                         }nd}| j                  rdj                  | j                        }nd}| j                  rdj                  | j                        }nd}dj                  t	        t
        t        |                | j                  |||t	        | j                                     S )zBAppends ISO Decimal/Binary scaled integer syntax to the help text.zThe default unit is `{}`. r   zGThe output unit is `{}`. Integer values are divided by the unit value. z'The default type abbreviation is `{}`. zH{}{}{}{}{}{}See https://en.wikipedia.org/wiki/Binary_prefix for details.)
r   r   r   r   r"   r1   r   r   r  r>   )r3   r  r  r  r6   s       r   r   zScaledInteger.BuildHelpText  s    1889K9KLllF4,,-  k;BB
//i i	6E-<>?D$$&')*r   c           
      8   |sy 	 t        j                  || j                  | j                        }| j                  r|| j                  z  }|S # t
        $ rB}t        j                  | j                         dj                  |t        |                  d }~ww xY w)N)r  r  z7Failed to parse binary/decimal scaled integer [{}]: {}.)r   ParseIntegerr   r   r   r   r	   r   rE   r   r   )r3   rs   r@   r   s       r   rt   zScaledInteger.Convert  s    
)))
t11T__Ne		 	 $)))l )!!

"
"
$
C
J
JmA&() ))s   AA 	B=BBc                 z    | j                   r|| j                   z  }t        j                  || j                        S )z5Returns the display string for a binary scaled value.)r  )r   r   FormatIntegerr   rv   s     r   rw   zScaledInteger.Display  s2    t&&&e''IIr   )NNBN)
rM   rN   rO   rP   r2   r   r   rt   rw   rQ   rR   s   @r   r   r   `  s,     KN 8&9*6)Jr   r   c                   *     e Zd ZdZd fd	Zd Z xZS )BinaryScaledIntegera%  ISO Binary scaled Integer value with binary display concept.

  All ISO/IEC prefixes are powers of 2: 1k == 1ki == 1024. This is a
  concession to the inconsistent mix of binary/decimal scaled measures for
  memory capacity, disk capacity, cpu speed. Ideally ScaledInteger should
  be used.
  c                 :    |d}t        t        | 
  |fd|i| y )NzMust be a string representing binary scaled integer where all ISO/IEC prefixes are powers of 2. For example, 1k == 1ki == 1024. r  )r1   r  r2   )r3   r4   r  r5   r6   s       r   r2   zBinaryScaledInteger.__init__  s9    O  

t-3'3+13r   c           
          |sy 	 t        j                  || j                        S # t        $ rB}t	        j
                  | j                         dj                  |t        |                  d }~ww xY w)Nz/Failed to parse binary scaled integer [{}]: {}.)	r   ParseBinaryIntegerr   r   r	   r   rE   r   r   r   s      r   rt   zBinaryScaledInteger.Convert  sm    )..vt7I7IJJ )!!

"
"
$
;
B
BmA&() ))s   % 	A0=A++A0rZ   )rM   rN   rO   rP   r2   rt   rQ   rR   s   @r   r  r    s    3	)r   r  c                   4     e Zd ZdZd fd	Z fdZd Z xZS )FloatzFloat value concept.

  Attributes:
    _unlimited: bool, the value 'unlimited' specifies the largest valid value.
      Internally it's represented as None.
  c                 <    || _         t        t        |   |fi | y rZ   )r   r1   r  r2   r   s       r   r2   zFloat.__init__  s    DO	%//r   c                     dj                  t        t        t        |                t        | j                                     S )z/Appends float syntax to the original help text.z:{}Must be a string representing a floating point number.{})r   r"   r1   r  r   r$   r>   r   s    r   r   zFloat.BuildHelpText  s<     	EKKE%467D$$&'	)*r   c           
          |sy 	 t        |      S # t        $ rX}| j                  r
|dk(  rY d }~y t        j                  | j                         dj                  |t        |                  d }~ww xY w)Nr   z/Failed to parse floating point number [{}]: {}.)floatr   r   r	   r   rE   r   r   r   s      r   rt   zFloat.Convert  so    )6] )	V{2!!

"
"
$
;
B
BmA&() ))s   
 	A1A,=A,,A1r   r   rR   s   @r   r  r    s    0*)r   r  c                   0     e Zd ZdZg dZ fdZd Z xZS )	DayOfWeekzDay of the week concept.)SUNMONTUEWEDTHUFRISATc                     dj                  t        t        t        |                t        | j                                     S )z5Appends day of week syntax to the original help text.z{}Must be a string representing a day of the week in English, such as 'MON' or 'FRI'. Case is ignored, and any characters after the first three are ignored.{})r   r"   r1   r  r   r$   r>   r   s    r   r   zDayOfWeek.BuildHelpText  s:    	))/E)T8:;D$$&'*)*r   c           	          |sy|j                         dd }|| j                  vrMt        j                  | j	                         dj                  |dj                  | j                                    |S )z.Converts a day of week from string returns it.N   z.A day of week value [{}] must be one of: [{}].z, )r   _DAYSr	   r   rE   r   r   )r3   rs   r@   s      r   rt   zDayOfWeek.Convert  sl    LLN2AEDJJ!!

"
"
$
:
A
Adii

+-. . Lr   )rM   rN   rO   rP   r'  r   rt   rQ   rR   s   @r   r  r    s     
;%*
r   r  c                   :     e Zd ZdZd fd	Z fdZd Zd Z xZS )DurationzDuration concept.

  Attributes:
    _default_suffix: string, the time unit suffix if none is specified.
    _subsecond: bool, return floating point values if True.
  c                 J    || _         || _        t        t        |   |fi | y rZ   )_default_suffix
_subsecondr1   r)  r2   )r3   r4   default_suffix	subsecondr5   r6   s        r   r2   zDuration.__init__  s&    )DDO	(D"4262r   c                     | j                   rdj                  | j                         }nd}dj                  t        t        t        |                |t        | j                                     S )z2Appends duration syntax to the original help text.zThe default suffix is `{}`. r   a  {}Must be a string representing an ISO 8601 duration. Syntax is relaxed to ignore case, the leading P and date/time separator T if there is no ambiguity. {}For example, `PT1H` and `1h` are equivalent representations of one hour. {}See $ gcloud topic datetimes for more information.)r+  r   r"   r1   r)  r   r>   )r3   r-  r6   s     r   r   zDuration.BuildHelpText"  sg    5<<


 n n	 vE(D79:ND$$&')*r   c           
      B   |sy	 t        j                  || j                        j                  }| j                  r|S t        |      S # t         j                  $ rB}t        j                  | j                         dj                  |t        |                  d}~ww xY w)z+Converts a duration from string returns it.N)r-  "Failed to parse duration [{}]: {}.)r   ParseDurationr+  total_secondsr,  r   Errorr	   r   rE   r   r   )r3   rs   dr   s       r   rt   zDuration.Convert2  s    )



!5!577D} //Q-s1v-;; )!!

"
"
$
.
5
5mA&() ))s   8A	 
A	 	B=BBc                     t        j                  dj                  |            }t        j                  |      }|j	                  d      r|dd j                         }|S )zDReturns the display string for a duration value, leading PT dropped.z{}sPTr   N)r   r2  r   FormatDurationr   r   )r3   r@   r5  ss       r   rw   zDuration.Display@  sM    ELL/0AQA||D
AB%++-aHr   )r9  F)	rM   rN   rO   rP   r2   r   rt   rw   rQ   rR   s   @r   r)  r)    s    3
* )r   r)  c                   @     e Zd ZdZd fd	Z fdZd Zd Zd Z xZ	S )	TimeStampzTimeStamp concept.

  Attributes:
    _fmt: string, a times.FormatDateTime() format specification.
    _string: bool, normalize value to a string if True
    _tzinfo: datetime.tzinfo, a time zone object, typically times.UTC or
      times.LOCAL.
  c                 |    || _         |xs t        j                  | _        || _        t        t        |   |fi | y rZ   )_fmtr   UTC_tzinfo_stringr1   r;  r2   )r3   r4   fmttzrs   r5   r6   s         r   r2   zTimeStamp.__init__S  s4    DI?DLDL	)T#D3F3r   c                     dj                  t        t        t        |                t        | j                                     S )z3Appends timestamp syntax to the original help text.z{}Must be a string representing an ISO 8601 date/time. Relative durations (prefixed by - or +) may be used to specify offsets from the current time. {}See $ gcloud topic datetimes for more information.)r   r"   r1   r;  r   r>   r   s    r   r   zTimeStamp.BuildHelpTextY  s<    	 vE)T8:;D$$&')	*r   c           
          |sy	 t        j                  || j                        S # t         j                  $ rB}t	        j
                  | j                         dj                  |t        |                  d}~ww xY w)z1Converts a datetime value from string returns it.N)tzinfor1  )	r   ParseDateTimer?  r4  r	   r   rE   r   r   r   s      r   rt   zTimeStamp.Convertc  so    )  ==;; )!!

"
"
$
.
5
5mA&() ))s    & A;=A66A;c                 Z    t        j                  || j                  | j                        S )z0Returns the display string for a datetime value.)rA  rE  )r   FormatDateTimer=  r?  rv   s     r   rw   zTimeStamp.Displayo  s    499T\\JJr   c                 @    | j                   r| j                  |      S |S rZ   )r@  rw   rv   s     r   ry   zTimeStamp.Normalizes  s    "&,,4<<9E9r   )NNF)
rM   rN   rO   rP   r2   r   rt   rw   ry   rQ   rR   s   @r   r;  r;  I  s"    4*
)K:r   r;  c                   .     e Zd ZdZ fdZd Zd Z xZS )SemVerzSemVer concept.c                     dj                  t        t        t        |                t        | j                                     S )z0Appends SemVer syntax to the original help text.z{}Must be a string representing a SemVer number of the form _MAJOR_._MINOR_._PATCH_, where omitted trailing parts default to 0. {}See https://semver.org/ for more information.)r   r"   r1   rK  r   r>   r   s    r   r   zSemVer.BuildHelpTextz  s:    	::@&E&$578D$$&';)*r   c                 d   |sy	 |j                  d      }t        |      dk  r |j                  d       t        |      dk  r dj                  |      }t	        j
                  |      S # t        j                  $ r2}t        j                  | j                         t        |            d}~ww xY w)z0Converts a SemVer object from string returns it.Nr   r&  r   )
r   r   r]   r   r   rK  r   r	   rE   r   )r3   rs   partsr   s       r   rt   zSemVer.Convert  s    Pll3eJNS JNxxf]]6"" P!!$":":"<mA>NOOPs   >A* %A* *B/=-B**B/c                 d    dj                  |j                  |j                  |j                        S )z5Returns the display string for a SemVer object value.z{}.{}.{})r   majorminorpatchrv   s     r   rw   zSemVer.Display  s#    U[[%++u{{CCr   )rM   rN   rO   rP   r   rt   rw   rQ   rR   s   @r   rK  rK  w  s    *PDr   rK  c                   @     e Zd ZdZd fd	Z fdZd Zd Zd Z xZ	S )ListzA list attribute concept.

  Attributes:
    _delim: string, the user specified lit item delimiter character.
    _element: string, the list element type object.
  c                 |    t        t        | 
  |fddi| | j                  | _        |xs t        |      | _        y )Nr   zlist length)r1   rT  r2   r   _delimr   _element)r3   r4   elementr5   r6   s       r   r2   zList.__init__  s9    	$tM]MfM%%DK+vd|DMr   c                    | j                   j                         }|j                  d      rdj                  |dd       }n%|j                  d      rdj                  |dd       }dj                  t	        t
        t        |                | j                   j                  t	        | j                               t	        |            S )z.Appends list syntax to the original help text.Must zEach item m{}r   NA zEach item is a{}z{}Must be a string representing a list of `,` separated {} values. {}{}See $ gcloud topic escaping for details on using alternate delimiters.)	rW  r   r   r   r"   r1   rT  r4   r>   )r3   item_help_textr6   s     r   r   zList.BuildHelpText  s    ]]002N  )&--nQR.@An		"	"4	()001CDn	fE$356MMD$$&'N#	%&r   c                     | j                   j                  |D cg c]  }| j                  j                  |       c}      S c c}w )z.Returns the display string for the list value.)rV  r   rW  rw   )r3   r@   items      r   rw   zList.Display  s8    ;;UKUTT]]2248UKLLKs   "Ac                     | j                   gS z8Returns the list of concepts that this concept marshals.)rW  r<   s    r   MarshalzList.Marshal  s    MM?r   c                    g }	 |j                   }| j                  |      \  }| _        |D ]A  }t        j                  |      }|j                  | j                  j                  |             C | j                  |      }| j                  |       | j!                  |      S # t        j                  $ r:}| j                  sY d}~yt	        j
                  | j                         |      d}~ww xY w)z1Parses the list from dependencies and returns it.N)r@   rA   rB   rC   r	   rD   rE   r   rV  r   DependencyViewFromValuer]   rW  rG   rt   r{   ry   )r3   rF   
list_valuer@   r   itemsr^  item_dependenciess           r   rG   z
List.Parse  s    J)  e U+E4;-EEdK++,=>?  j)JMM*>>*%% ** )]]33

"
"
$a) ))s   B" "C/5C*$C**C/rZ   
rM   rN   rO   rP   r2   r   rw   ra  rG   rQ   rR   s   @r   rT  rT    s"    ,
& M&r   rT  c                   @     e Zd ZdZd fd	Z fdZd Zd Zd Z xZ	S )DictaR  A dict attribute concept.

  Attributes:
    _delim: string, the user specified lit item delimiter character.
    _entries: {string: ConceptType}, the map of concept type names to
      concept type objects.
    _additional: ConceptType, uninstantiated type used for unknown keys.
      If not specified then unknown keys are an error.
  c                     t        t        | 
  |fddi| | j                  | _        i | _        |r |D ]  }|| j
                  |j                  <    | j
                  s|st        }|| _        y )Nr   znumber of entries)	r1   ri  r2   r   rV  _entriesr4   r   _additional)r3   r4   entries
additionalr5   entryr6   s         r   r2   zDict.__init__  sn    	$=1=5;=%%DKDM%$)ejj! ==j!Dr   c                 
   t        j                         }|j                  d       t        t	        j
                  | j                              D ]4  \  }}|j                  dj                  ||j                                      6 | j                  rd}| j                  rd}nd}| j                  d      j                         }|j                  d      rdj                  |d	d
       }n%|j                  d      rdj                  |d	d
       }|j                  dj                  ||             nd}dj                  t        t        t        | #               t        | j                               ||j                               S )z.Appends dict syntax to the original help text.r   r   mayz#Additional _key_ names are allowed.zAny _key_ name is accepted.*rZ  zEach _value_ m{}r   Nr[  zEach _value_ is a{}z```*```::: {} {}
mustzd{}Must be a string representing a list of `,` separated _key_=_value_ pairs. {}_key_ {} be one of:{})r   r   r   r   r   r   rk  r   r   rl  r   r"   r1   ri  r>   r   )r3   r   r   ro  may_mustr!   value_help_textr6   s          r   r   zDict.BuildHelpText  s@   
++-CIIgS]]4==9:
U	ii%%c5+>+>+@AB ;h	4,((-;;=o		#	#G	,,33OAB4GH%%d+/66qr7JK	ii$++D/BCh	77=vE$356D$$&'LLN	8r   c                     | j                   j                  t        t        j                  |      D cg c]0  \  }}dj                  || j                  j                  |            2 c}}            S c c}}w )z.Returns the display string for the dict value.z{}={})rV  r   r   r   r   r   rW  rw   )r3   r@   kvs       r   rw   zDict.Display  sm    ;;F03e0D$F0D1 %,NN1dmm6K6KA6N$O0D$F G H H $Fs   5A4c                 6    | j                   j                         S r`  )rk  valuesr<   s    r   ra  zDict.Marshal  s    ==!!r   c                 F   i }	 |j                   }| j                  |      \  }| _        |D ]  }|j                  dd      \  }}| j                  j                  |      }	|	sP| j                  s3t	        j                  | j                         dj                  |            | j                  |      }	t        j                  |j                   j                  |            }
	 ||
_         |	j)                  |
      ||<    | j+                  |      }| j-                  |       | j/                  |      S # t        j                  $ r:}| j                  sY d}~yt	        j
                  | j                         |      d}~ww xY w# t"        $ r t%        j&                  |      }
Y w xY w)z1Parses the dict from dependencies and returns it.N=r   zUnknown dictionary key [{}].)r@   rA   rB   rC   r	   rD   rE   r   rV  r   rk  r   rl  r   r   r[   marshalled_dependenciesr   r   rc  rG   rt   r{   ry   )r3   rF   
dict_valuer@   r   re  r^  r   valro  rf  s              r   rG   z
Dict.Parse
  s   J)  e U+E4;C#hc3mm$e%%&&(,33C8: :   %))L$H$H$L$L
% M"% $56jo   j)JMM*>>*%%1 ** )]]33

"
"
$a) ))&  M/GGLMs/   D/ E?/E<E7$E77E<?F F r   rg  rR   s   @r   ri  ri    s"    
"8H
"&r   ri  ).rP   
__future__r   r   r   r[   r   r    googlecloudsdk.calliope.conceptsr   rA   #googlecloudsdk.command_lib.conceptsr   r   r	   r
   googlecloudsdk.core.utilr   r   r   r   r   r"   r$   Conceptr&   rT   rp   objectr~   r   r   r   r   r   r   r   r   r  r  r  r)  r;  rK  rT  ri  r9   r   r   <module>r     sj   & '  '  	 	 = 4 C : 5 3 + * 
*Z3 Z3z3Lt|| 3LlE	) E	Pv \1 \1~9&7 9&xk B(k (@!I; !IH1$ 1*( *>YJ. YJx)- ):)& )B' 61) 1h+:* +:\D' D<6&! 6&rY&! Y&r   