
                        "   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K	r	SSK
Jr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJ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u  r r!Su  r"r#r$r%Su  r&r'r(Sr)  SMS jr* " S S\+5      r, " S S\,5      r- " S S\.5      r/S  r0S!r1\2" S"5      r3S# r4\5\6\6\7\8\Rr                  S$.r:S% r;S& r< " S' S(\.5      r= " S) S*\R|                  S+9r? " S, S-\?\R                  5      rA\	R                  " S.S/9 " S0 S15      5       rC " S2 S3\R|                  S+9rD " S4 S5\R                  \R|                  S+9rF " S6 S7\F\D5      rGS8 rH " S9 S:\F\D5      rI " S; S<\F\D5      rJ " S= S>\F\D5      rKS? rL " S@ SA\R                  5      rNSB rO " SC SD\?\R                  5      rQ " SE SF\?\R                  5      rR\	R                  " S.S/9 " SG SH5      5       rS " SI SJ\R                  5      rT " SK SL\?\R                  5      rVg)Nz0Data objects to support the yaml command schema.    )absolute_import)annotations)division)unicode_literalsN)Callable)Any)messages)actions)arg_parsers)arg_parsers_usage_text)	arg_utils)labels_util)module_util)http_encoding__name____resource_id____relative_name____resource_type__)keyvalue)
arg_objectarg_dictarg_listarg_json)specparamsgroup	file_typec           
        U(       a_  UR                  5       nU=(       d    UR                  5       U[        '   UR                  5       U[        '   UR	                  5       U[
        '   O[        U0nX4[        '    U R                  " S0 UD6$ ! [         a]  nUR                  (       aE  [        SR                  UR                  S   SR                  UR                  5       5      5      5      eUeSnAff = f)aB  Formats a string with all the attributes of the given resource ref.

Args:
  format_string: str, The format string.
  resource_ref: resources.Resource, The resource reference to extract
    attributes from.
  display_name: the display name for the resource.
  display_resource_type:

Returns:
  str, The formatted string.
zKKey [{}] does not exist. Must specify one of the following keys instead: {}r   z, N )AsDictNameNAME_FORMAT_KEYRESOURCE_ID_FORMAT_KEYRelativeNameREL_NAME_FORMAT_KEYRESOURCE_TYPE_FORMAT_KEYformatKeyErrorargsjoinkeys)format_stringresource_refdisplay_namedisplay_resource_typederrs         Dlib/googlecloudsdk/command_lib/util/apis/yaml_command_schema_util.pyFormatResourceAttrStrr4   2   s     A+))+ o , 1 1 3A)668A	,'A 5$!$$	 
xx 228&!dii&93;< < is   8B
 

C1AC,,C1c                      \ rS rSrSrSrg)ErrorU   zBase class for module errors.r    Nr   
__module____qualname____firstlineno____doc____static_attributes__r        r3   r6   r6   U   s    %r>   r6   c                      \ rS rSrSrSrg)InvalidSchemaErrorZ   z+Error for when a yaml command is malformed.r    Nr8   r    r>   r3   r@   r@   Z   s    3r>   r@   c                  H    \ rS rSrSr\S 5       r\S 5       rS	S jrS r	Sr
g)
Hook_   a  Represents a Python code hook declared in the yaml spec.

A code hook points to some python element with a module path, and attribute
path like: package.module:class.attribute.

If arguments are provided, first the function is called with the arguments
and the return value of that is the hook that is used. For example:

googlecloudsdk.calliope.arg_parsers:Duration:lower_bound=1s,upper_bound=1m
c                V    UR                  U5      nU(       a  U R                  U5      $ g)zGets the hook from the spec data.

Args:
  data: The yaml spec
  key: The key to extract the hook path from.

Returns:
  The Python element to call.
N)getFromPath)clsdatar   paths       r3   FromDataHook.FromDatak   s&     88C=D\\$r>   c                4    [        U5      R                  5       $ )zGets the hook from the function path.

Args:
  path: str, The module path to the hook function.

Returns:
  The Python element to call.
)ImportPythonHookGetHook)rH   rJ   s     r3   rG   Hook.FromPath{   s     D!))++r>   Nc                    Xl         X l        g N	attributekwargs)selfrT   rU   s      r3   __init__Hook.__init__   s    NKr>   c                l    U R                   b  U R                  " S0 U R                   D6$ U R                  $ )zUGets the Python element that corresponds to this hook.

Returns:
  A Python element.
r    )rU   rT   rV   s    r3   rO   Hook.GetHook   s.     {{nn+t{{++>>r>   rS   rR   )r   r9   r:   r;   r<   classmethodrK   rG   rW   rO   r=   r    r>   r3   rC   rC   _   s9    	   	, 	,r>   rC   c                   U R                  S5      n[        U5      S:w  a)  [        U5      S:w  a  [        SR                  U 5      5      e [        R
                  " US   S-   US   -   5      nSn[        U5      S:X  a  0 nUS   R                  S	5       Hl  nU(       d  M  UR                  S
5      n[        U5      S:w  a  [        SR                  U 5      5      eUS   R                  5       XFS   R                  5       '   Mn     [        X$5      $ ! [        R                   a  n[        SR                  X5      5      eSnAff = f)a[  Imports the given python hook.

Depending on what it is used for, a hook is a reference to a class, function,
or attribute in Python code.

Args:
  path: str, The path of the hook to import. It must be in the form of:
    package.module:attribute.attribute where the module path is separated from
    the class name and sub attributes by a ':'. Additionally, ":arg=value,..."
    can be appended to call the function with the given args and use the
    return value as the hook.

Raises:
  InvalidSchemaError: If the given module or attribute cannot be loaded.

Returns:
  Hook, the hook configuration.
:      zzInvalid Python hook: [{}]. Hooks must be in the format: package(.module)+:attribute(.attribute)*(:arg=value(,arg=value)*)?r      z&Could not import Python hook: [{}]. {}N,=zKInvalid Python hook: [{}]. Args must be in the form arg=value,arg=value,...)	splitlenr@   r(   r   ImportModuleImportModuleErrorstriprC   )rJ   partsattrerU   arg	arg_partss          r3   rN   rN      s9   & **S/%Z1_Uq
	M	 B##E!HsNU1X$=>D
 &Z1_FQx~~c"))C.i	Y1	 "F4L* 	* &/q\%7%7%9fq\!" # 
d	# 
	&	& B
077@B BBs   "D E#D==Estore_true_false)store
store_trueappendc                >   U (       d  g[        U [        5      (       a;  U [        :X  a  [        R                  $ U [
        ;   a  U $ [        R                  U 5      $ U R                  S5      nU(       a  [        R                  " U40 UD6$ [        S[        U 5      -   5      e)aO  Parse the action out of the argument spec.

Args:
  action: The argument action spec data.
  flag_name: str, The effective flag name.

Raises:
  ValueError: If the spec is invalid.

Returns:
  The action to use as argparse accepts it. It will either be a class that
  implements action, or it will be a str of a builtin argparse type.
N
deprecatedzUnknown value for action: )
isinstancestrTRUE_FALSE_ACTIONr   StoreTrueFalseActionSTATIC_ACTIONSrC   rG   rF   r
   DeprecationAction
ValueError)action	flag_namedeprecations      r3   ParseActionr~      s     
""---	>	!m]]6""

<(+$$Y>+>>/#f+=>>r>   )ru   intlongfloatboolbytesc                b   U [         :X  a  [        R                  U5      $ U [        :X  a  [        R                  S5      $ U [        :X  a  [        R                  U5      $ U [        :X  a  [        R                  U5      $ [        R                  U S5      =n(       a  U$ [        R                  U 5      $ )zParses type from string.

Args:
  arg_type: str, string representation of type
  data: dict, raw argument data

Returns:
  The type to use as argparse accepts it.
z,googlecloudsdk.calliope.arg_parsers:ArgList:N)
ARG_OBJECT	ArgObjectrK   ARG_LISTrC   rG   ARG_JSONArgJSON	FILE_TYPEFileContentsBUILTIN_TYPESrF   )arg_typerI   builtin_types      r3   _ParseTypeFromStrr      s     d##8==GHH8D!!9  &&$((488|8==""r>   c                   ^  [        U 4S j[        [        [        4 5       5      nT R	                  S5      =n(       a  UnOU(       a  [
        nOSnU(       a-  U[
        :w  a#  T R	                  S5      n[        SU SU S35      eU(       d  U(       d  g[        U[        5      (       a  [        U;   a  [        R                  T 5      $ [        U[        5      (       a  [        UT 5      $ [        S[        U5      -   5      e)	zParse the action out of the argument spec.

Args:
  data: dict, raw arugment data

Raises:
  ValueError: If the spec is invalid.
  InvalidSchemaError: If spec and non arg_object type are provided.

Returns:
  The type to use as argparse accepts it.
c              3  ,   >#    U  H	  oT;   v   M     g 7frR   r    ).0r   rI   s     r3   	<genexpr>ParseType.<locals>.<genexpr>  s     C-BcTk-Bs   typeNarg_namezEOnly flags with type arg_object may contain a spec declaration. Flag z
 has type z1. Update the type or remove the spec declaration.zUnknown value for type: )anySPECPARAMSGROUPrF   r   r@   rt   dictARG_DICTArgDictrK   ru   r   rz   )rI   contains_specspecified_typer   r   s   `    r3   	ParseTyper     s     CdFE-BCC-xx''^'HHHx:-xx
#H
	zH: .'	'( (
 
-(D!!h(&:D!!(C  Xt,,-H=>>r>   c                  .    \ rS rSrSrS r\S 5       rSrg)Choicei1  z3Holds information about a single enum choice value.c                X   US   U l         [        U R                   [        5      (       a  U R                   R                  5       U l         SU;   a  US   U l        O%[
        R                  " U R                   5      U l        UR                  S5      U l        UR                  S5      U l	        g )N	arg_value
enum_value	help_texthidden)
r   rt   ru   lowerr   r   ChoiceToEnumNamerF   r   r   )rV   rI   s     r3   rW   Choice.__init__4  s}    +&DN$..#&&~~++-dnt\*do!224>>BdoXXk*DN((8$DKr>   c                l    U(       d  0 $ U Vs0 s H  o"R                   UR                  _M     sn$ s  snf )a  Converts a list of choices into a map for easy value lookup.

Args:
  choices: [Choice], The choices.

Returns:
  {arg_value: enum_value}, A mapping of user input to the value that should
  be used. All arg_values have already been converted to lowercase for
  comparison.
)r   r   )rH   choicescs      r3   ToChoiceMapChoice.ToChoiceMap@  s/     i/67w!KK%w777s    1)r   r   r   r   N)	r   r9   r:   r;   r<   rW   r\   r   r=   r    r>   r3   r   r   1  s    ;
% 8 8r>   r   c                  <    \ rS rSrSr\R                  S 5       rSrg)TypeGeneratoriQ  z-Interface for generating a type from a field.c                    g)zGenerates a type from a field.Nr    rV   fields     r3   GenerateTypeTypeGenerator.GenerateTypeT      r>   r    N)	r   r9   r:   r;   r<   abcabstractmethodr   r=   r    r>   r3   r   r   Q  s    5) )r>   r   )	metaclassc                  .    \ rS rSrSr\S 5       rS rSrg)r   iY  z0Holds information about a file content argument.c                    AU " 5       $ )z&Creates a FileContents from yaml data.r    rH   rI   s     r3   rK   FileContents.FromData\  s    
 	5Lr>   c                2   U(       a(  UR                   [        R                  R                  :X  a  [        R
                  " SS9$ UR                   [        R                  R                  :X  a  [        R
                  " SS9$ [        SUR                   S35      e)NF)binaryTzConflicting types for field: zB. Only string and bytes fields are supported when using file_type.)	variantapitools_messagesVariantSTRINGr   r   BYTESr@   namer   s     r3   r   FileContents.GenerateTyped  s|    EMM%6%>%>%E%EE%%U33}})11777%%T22)%** 6N N r>   r    N	r   r9   r:   r;   r<   r\   rK   r   r=   r    r>   r3   r   r   Y  s    8 	r>   r   T)frozenc                  x    \ rS rSr% Sr\  SS j5       rS\S'   S\S'   S\S	'   S
\S'   S\S'   S\S'   S\S'   Srg)
_FieldSpecip  zCHolds information about a field and type that is generated from it.Nc           
     `   U=(       d    UR                   n[        R                  " U5      nXR                   :w  a  [        SU SUR                    35      e[	        U[
        5      (       a  UR                  U5      n	OUn	U " UUU=(       d    UU	UR                  Ub  UUS9$ UR                  US9$ )aU  Creates a _FieldSpec from user input.

If value is not provided in yaml schema by user, the value is defaulted
to a value derived from the apitools field.

Args:
  field: apitools field instance
  api_field: The name of the field under the repeated message that the value
    should be put.
  field_type: The type of the field if specified by user.
  arg_name: The name of the key in the dict.
  required: True if the key is required.
  hidden: True if the help text should be hidden.

Returns:
  _FieldSpec instance

Raises:
  ValueError: if the field contradicts the values provided by the user
zExpected to receive field z	 but got )r   	api_fieldr   
field_typerepeatedrequiredr   )	r   r   GetChildFieldNamerz   rt   r   r   r   r   )
rH   r   r   r   r   r   r   
field_namechild_field_namegenerated_field_types
             r3   FromUserData_FieldSpec.FromUserDatat  s    2 (ejjJ 22:>::%&'7&8 9  *m,,'44U;'--'%1  8=~~ r>   zapitools_messages.Fieldr   ru   r   r   Callable[[str], Any] | Noner   r   r   r   zbool | Noner   r    )NNNNF)	r   r9   r:   r;   r<   r\   r   __annotations__r=   r    r>   r3   r   r   p  sF    K<@!- -^ 
! .-))..
r>   r   c                  <    \ rS rSrSr\R                  S 5       rSrg)EquitableTypei  a`  Wrapper that deteremines if two message fields of same type are equal.

This is needed because the old message may contain ouptut only fields the
user is not able to specify. For example, a message field may contain output
only field `uid` that the user is not able to specify. Message(foo=bar)
should still "match" existing Message(foo=bar, uid=baz).
c                    g)DChecks if new value matches existing value based on what user input.Nr    rV   existing_value	new_values      r3   MatchesEquitableType.Matches  r   r>   r    N)	r   r9   r:   r;   r<   r   r   r   r=   r    r>   r3   r   r     s#     O Or>   r   c                  V   ^  \ rS rSrSrU 4S jrS r\R                  S 5       r	Sr
U =r$ )_FieldSpecTypei  a  Wrapper that holds the arg type and information about the type.

Interface allows users to parse string into arg_type and then parse value
into correct apitools field.

Attributes:
  field: apitools field instance
  api_field: str, name of the field where value should be mapped in message.
  arg_name: str, name of key in dict.
  repeated: bool, whether the field is repeated.
  required: bool, whether the field value is required.
c                   > [         [        U ]  US9  UR                  U l        UR                  U l        UR
                  U l        UR                  U l        UR                  U l        g N)r   )superr   rW   r   r   r   r   r   rV   r   
field_spec	__class__s      r3   rW   _FieldSpecType.__init__  sV    	.$(((;!!DJ))DN''DM''DM''DMr>   c                x    Uc  U R                   (       a  / nOUn[        R                  " XR                  U5        g)zSets field in a message after value is parsed into correct type.

Args:
  message_instance: apitools message instance we are parsing value into
  value: value we are parsing into apitools message
N)r   r   SetFieldInMessager   )rV   message_instancer   field_values       r3   ParseIntoMessage_FieldSpecType.ParseIntoMessage  s0     }kk..+7r>   c                    g)zBParses arg_value into apitools message using field specs provided.Nr    )rV   r   s     r3   __call___FieldSpecType.__call__  r   r>   )r   r   r   r   r   )r   r9   r:   r;   r<   rW   r   r   r   r   r=   __classcell__r   s   @r3   r   r     s.    (7 M Mr>   r   c                  <   ^  \ rS rSrSrSU 4S jjrS rS rSrU =r	$ )
_FieldTypei  zxType that converts string into apitools field instance.

Attributes:
  choices: list[Choice], list of valid user inputs
c                :   > [         [        U ]
  " S0 UD6  Xl        g Nr    )r   r   rW   r   )rV   r   rU   r   s      r3   rW   _FieldType.__init__  s    	*d$.v.Lr>   c                    U R                  U5      n[        R                  " U R                  X R                  U R
                  S9$ )z*Converts string into apitools field value.)r   r   )r   r   ConvertValuer   r   r   )rV   r   parsed_arg_values      r3   r   _FieldType.__call__  s9    }}Y/!!

$}} r>   c                    X:X  a  gUb  Uc  g[        U[        5      (       a  UOU/n[        U[        5      (       a  UOU/n[        U5      [        U5      :w  a  gU H
  nXT;  d  M
    g   gr   TF)rt   listre   )rV   r   r   new_val_listexisting_val_listvals         r3   r   _FieldType.Matches  sx    "		9#4 !+9d ; ;9)L+5nd+K+K-. 
<C 122		%  r>   )r   rR   
r   r9   r:   r;   r<   rW   r   r   r=   r   r   s   @r3   r   r     s     r>   r   c                    [         R                  " XR                  5      n[         R                  " XR                  5      nUR                  X45      $ )r   )r   GetFieldValueFromMessager   r   )r   r   r   existing_field	new_fields        r3   _SubFieldMatchesr  	  sE    55**,.00%%')			N	66r>   c                  D   ^  \ rS rSrSrU 4S jrS rS rS rS r	Sr
U =r$ )	_MessageFieldTypei  zType that converts string input into apitools message.

Attributes:
  field_specs: list[_FieldSpecType], list of message's fields
c                :   > [         [        U ]
  " S0 UD6  Xl        g r   )r   r  rW   field_specs)rV   r  rU   r   s      r3   rW   _MessageFieldType.__init__  s    	
T+5f5"r>   c                    U R                   R                  5       nU R                   H/  nUR                  UR                  5      nUR                  X$5        M1     U$ )z<Iterates through fields and adds fields to message instance.)r   r   r  rF   r   r   )rV   r   r   r   r   s        r3   _ParseFieldsIntoMessage)_MessageFieldType._ParseFieldsIntoMessage  sN    zz($$mmH--.e 08 % r>   c                    U R                  U5      n[        U[        5      (       a!  U Vs/ s H  o0R                  U5      PM     sn$ U R                  U5      $ s  snf )z&Converts string into apitools message.)r   rt   r  r  )rV   r   r   rs       r3   r   _MessageFieldType.__call__%  sW    }}Y/"D))7GH7G!**1-7GHH))*:;; Is   Ac                l   ^^ U H,  m[        UU4S jU R                   5       5      nU(       d  M,    g   g)r   c              3  >   >#    U  H  n[        TTU5      v   M     g 7frR   )r  )r   r   new_valr  s     r3   r   1_MessageFieldType._ContainsVal.<locals>.<genexpr>0  s$      2 0 %S'488 0s   TF)allr  )rV   r  
all_valuesmatchesr  s    `  @r3   _ContainsVal_MessageFieldType._ContainsVal-  s7     2 $ 0 02 2g		  r>   c                    X:X  a  gUb  Uc  g[        U[        5      (       a  UOU/n[        U[        5      (       a  UOU/n[        U5      [        U5      :w  a  gU H  nU R                  XS5      (       a  M    g   gr   )rt   r  re   r  )rV   r   r   r  r  r  s         r3   r   _MessageFieldType.Matches7  s    "		9#4 ,6nd+K+K-. !+It!<!<I# 
\!22w::   r>   )r  )r   r9   r:   r;   r<   rW   r  r   r  r   r=   r   r   s   @r3   r  r    s&    #< r>   r  c                  8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )_AdditionalPropsTypeiL  a  Type converts string into list of apitools message instances for map field.

Type function returns a list of apitools messages with key, value fields ie
[Message(key=key1, value=value1), Message(key=key2, value=value2), etc].
The list of messages is how apitools specifies map fields.

Attributes:
  key_spec: _FieldSpecType, specifes expected type of key field
  value_spec: _FieldSpecType, specifies expected type of value field
c                F   > [         [        U ]
  " S0 UD6  Xl        X l        g r   )r   r#  rW   key_spec
value_spec)rV   r%  r&  rU   r   s       r3   rW   _AdditionalPropsType.__init__X  s     	
.88M Or>   c                2   U R                  U5      n/ n[        UR                  5       5       Hf  u  pEU R                  R	                  5       nU R
                  R                  Xd5        U R                  R                  Xe5        UR                  U5        Mh     U$ rR   )	r   sorteditemsr   r   r%  r   r&  rq   )rV   r   r   r	   kvr   s          r3   r   _AdditionalPropsType.__call__]  s~    }}Y/H '--/0*
mm$$%59
oo&&'7;oo&'	 1
 Or>   c                N   X:X  a  gUb  Uc  g[        U5      [        U5      :w  a  gU Vs0 s H  o3R                  UR                  _M     nnU HN  nUR                  U;  a    gU R                  R	                  XCR                     UR                  5      (       a  MN    g   gs  snf )NTF)re   r   r   r&  r   )rV   r   r   r  sub_field_maps        r3   r   _AdditionalPropsType.Matchesj  s    "		9#4	^	I	. '5&4sn   		%__$$]77%;SYYGG	 
 s    B")r%  r&  r  r   s   @r3   r#  r#  L  s    	!
 r>   r#  c                  $    \ rS rSrSrS rS rSrg)_MapFieldTypei}  zCType converts string into apitools additional props field instance.c                    U R                  U5      nU R                  R                  5       nU R                   R                  X25        U$ )zBParses arg_value into additional props field of apitools messages.)r   r   r   r   )rV   r   additional_props_fieldparent_messages       r3   r   _MapFieldType.__call__  s9    !]]95ZZ__&NMM"">Jr>   c                H    X:X  a  gUb  Uc  g[        XU R                  5      $ r   )r  r   r   s      r3   r   _MapFieldType.Matches  s*    "		9#4nGGr>   r    N)r   r9   r:   r;   r<   r   r   r=   r    r>   r3   r2  r2  }  s    KHr>   r2  c                    [         R                  R                  U R                  5      nU(       d  [	        SU R
                  -   5      eU$ )zReturns the input type for the apitools field.

Args:
  field: apitools field instance

Returns:
  Type function for apitools field input.

Raises:
  InvalidSchemaError: if the field type is not listed in arg_utils.TYPES
zUnknown type for field: )r   TYPESrF   r   r@   r   )r   r   s     r3   _GetFieldValueTyper;    s9     __  /(	
7%**D
EE	/r>   c                      \ rS rSrSr\S 5       r\S 5       r\SS j5       r\SS j5       r	   SS jr
S	 rS
 rSS jrSS jrSS jrSS jrSS jrSrg)r   i  z>A wrapper to bind an ArgObject argument to a message or field.c                ^    UR                  S5      =n(       a  U[        :w  a  [        U5      $ g)!Creates ArgObject from yaml data.r   N)rF   r   r   )rH   rI   	data_types      r3   _FieldTypeFromDataArgObject._FieldTypeFromData  s,     XXf%%	%9
+Bt_r>   c                    / nU Ho  n[         R                  XR=(       d    US9nUR                  (       d.  UR                  (       a  UR	                  UR                  5        M^  UR                  U5        Mq     U$ )z,Creates ArgObject types from yaml spec data.)parent_field)r   rK   r   r   extendrq   )rH   params_datar   rC  r   
field_datar   s          r3   _SpecFromDataArgObject._SpecFromData  sd     D!
%%
#< & >j
 !!jooJOO$J " Kr>   Nc                x    U(       a  U(       d  U$ U S3nUR                  U5      (       a  U[        U5      S $ U$ )r>  .N)
startswithre   )rH   r   rC  prefixs       r3   _RelativeApiFieldArgObject._RelativeApiField  sC     y~QFF##s6{|$$r>   c           
     <   UR                  [        5      =n(       a  UnOUnUR                  S5      nUR                  [        5      =(       d    UR                  [        5      =nb  U R	                  XvU5      nOSnUR                  S5      n	UR                  S5      (       d3  U(       d,  UR                  S5      =(       d    U	n
[        SU
 SU
 S35      eU " U R                  Xc5      U	UR                  S	5      UR                  S
5      U R                  U5      UUS9$ )r>  r   N	json_namemutexr   zapi_field is required for z: Add api_field to z to generate a valid ArgObject.r   r   r   rP  r   r   r   r   disable_key_description)rF   r   r   r   rG  r@   rM  r@  )rH   rI   rS  rC  r   
group_datar   r   r   rP  r   s              r3   rK   ArgObject.FromData  s    ujj{+I..(@JNN4,@@Mv,?dd
 {+I>>'""9
+8yh&xj 1&Z'FH 
 ''	@..-~~h'))*5 7 r>   c                X    Xl         X l        X0l        X@l        XPl        X`l        Xpl        g rR   rR  )rV   r   rP  r   r   r   r   rS  s           r3   rW   ArgObject.__init__  s(     NNNK OI#: r>   c                P    UR                   (       a  [        R                  " 5       $ g)zvReturns the correct argument action.

Args:
  field: apitools field instance

Returns:
  str, argument action string.
ro   )r   r   FlattenActionr   s     r3   ActionArgObject.Action  s     ~~&&((r>   c                   ^ [        U R                  S9nU R                  =(       d    / n[        U4S jU 5       U5      $ )z4Returns first spec field that matches the api_field.)rS  c              3  J   >#    U  H  oR                   T:X  d  M  Uv   M     g 7frR   )r   )r   fr   s     r3   r   2ArgObject._GetFieldTypeFromSpec.<locals>.<genexpr>  s     =DqKK9$<Ds   #	#)r   rS  r   next)rV   r   default_typer   s    `  r3   _GetFieldTypeFromSpecArgObject._GetFieldTypeFromSpec
  s6     $ < <>L99?D=D=|LLr>   c                p    [         R                  " X5      nU R                  U5      nUR                  XCSS9$ )aC  Retrieves the the type of the field from messsage.

Args:
  message: Apitools message class
  api_field: str, field path of message
  is_label_field: bool, whether field is part of labels map field

Returns:
  _FieldSpecType, Type function that returns apitools message
    instance or list of instances from string value.
F)is_label_fieldis_root)r   GetFieldFromMessagerb  r   )rV   messager   re  r^  arg_objs         r3   _GenerateSubFieldTypeArgObject._GenerateSubFieldType  sA     	%%g9A((3G	%   9 9r>   c           
        UR                   =n(       a  [        SU SU R                   S35      e [        R                  " UR
                  R                  [        R                  5      nUR                  S:H  n[        R                  X@R                  S9nU R                  UR                  [        US9nU R                  UR                  [         US9n["        R$                  " UUU R&                  UR(                  UU R*                  S	S
9n	[-        U	UUUS9n
[/        U
US9$ ! [        R                   a2    [        SR                  UR                  [        R                  S95      ef = f)a
  Returns function that parses apitools map fields from string.

Map fields are proto fields with type `map<...>` that generate
apitools message with an additionalProperties field

Args:
  field_spec: _FieldSpec, information about the field
  is_root: whether the type function is for the root level of the message

Returns:
  type function that takes string like 'foo=bar' or '{"foo": "bar"}' and
    creates an apitools message additionalProperties field
Raises:
  InvalidSchemaError: if type is specified for a map field
Field type z  is not supported for map field (. Remove the type declaration from spec.zV{name} message does not contain field "{props}". Remove "{props}" from api field name.)r   propslabels)r   )re  T)key_type
value_typer   r   
root_levelrS  allow_key_onlyr   r   r%  r&  r   r   )r   r@   r   r   rg  r   r   ADDITIONAL_PROPSUnknownFieldErrorr(   r   r   r   rP  rj  KEYVALUEr   r   r   r   rS  r#  r2  )rV   r   rf  r   r4  re  props_field_specrq  rr  ri  additional_prop_spec_types              r3   _GenerateMapTypeArgObject._GenerateMapType"  s      ***z*
|#C^^DF 	(<<




!;!; =  ((H4N!.. / 9))##S * IH++##U> , KJ ##..   $ < <G !5#	! * E && ++16''.. ,2 , s   9D" "AE(c                :   UR                   =n(       a  [        SU SU R                   S35      eU R                  b&  U R                   Vs/ s H  oDR                  PM     nnOTSS1nUR                  R
                  R                  5        Vs/ s H!  nUR                  U;  d  M  UR                  PM#     nnU Vs/ s H)  nU R                  UR                  R
                  U5      PM+     nnU Vs/ s H!  oDR                  (       d  M  UR                  PM#     n	n[        R                  " U Vs0 s H  oDR                  U_M     snU R                  U	UR                  UR                  UU R                   SS9n
[#        U
UUS9$ s  snf s  snf s  snf s  snf s  snf )	a  Returns function that parses apitools message fields from string.

Args:
  field_spec: _FieldSpec, information about the field
  is_root: whether the _MessageFieldType is for the root level of
    the message

Returns:
  _MessageFieldType that takes string like 'foo=bar' or '{"foo": "bar"}' and
  creates an apitools message like Message(foo=bar) or [Message(foo=bar)]

Raises:
  InvalidSchemaError: if type is specified for a message field
rm  z$ is not supported for message field rn  
createTime
updateTimeT)r   r   required_keysr   r   rs  rS  rt  r   r   r  )r   r@   r   r   r   r   
all_fieldsr   rj  r   r   r   r   r   r   r   rS  r  )rV   r   rf  r   r^  field_namesoutput_only_fieldsr   r  r   ri  s              r3   _GenerateMessageTypeArgObject._GenerateMessageType`  s     ***z*
|#G^^DF 
 yy*.))4)Q[[)k4k(,7$**//::</<QVV-- !&&<  /  D 	"":#3#3#8#8$?  
 %0>Kq::


KH>##%01[jj!m[1..$$   $ < <G ! !/ 5/
 ?1s*   FF	%F	;0F1F	F/Fc                ,   U(       a5  UR                   [        :X  a!  [        R                  n[        R                  nOfU(       a5  UR                   [
        :X  a!  [        R                  n[        R                  nO*UR                  =(       d    [        UR                  5      nSn[        R                  " UU R                  =(       d    UUR                  UR                  S[!        U[        R"                  5      (       + U R$                  S9n['        UUSS9$ )az  Returns _FieldType that parses apitools field from string.

Args:
  field_spec: _FieldSpec, information about the field
  is_label_field: bool, whether or not the field is for a labels map field.
    If true, supplies default validation and help text.

Returns:
  _FieldType that takes string like '1' or ['1'] and parses it
  into 1 or [1] depending on the apitools field type
NF)rr  r   r   r   rs  enable_file_uploadrS  r   r   r   )r   ry  r   KEY_FORMAT_VALIDATORKEY_FORMAT_HELPrz  VALUE_FORMAT_VALIDATORVALUE_FORMAT_HELPr   r;  r   r   r   r   r   r   rt   r   rS  r   )rV   r   re  rr  default_help_textri  s         r3   _GenerateFieldTypeArgObject._GenerateFieldType  s     *--433j%55	J//5855j%77((P,>z?O?O,Pj##..5$5$$  :{'?'?@@ $ < <	G  r>   c                   [         R                  XR                  U R                  U R                  U R
                  S9n[        R                  " U5      nU[        R                  R                  :X  a  U R                  XB5      $ U[        R                  R                  :X  a  U R                  XB5      $ U R                  XC5      $ )a  Generates a _FieldSpecType to parse the argument.

Args:
  field: apitools field instance we are generating ArgObject for
  is_root: bool, whether this is the first level of the ArgObject
    we are generating for.
  is_label_field: bool, whether the field is for labels map field

Returns:
  _FieldSpecType, Type function that returns apitools message
  instance or list of instances from string value.
)r   r   r   r   )r   r   rP  r   r   r   r   GetFieldType	FieldTypeMAPr}  MESSAGEr  r  )rV   r   rf  re  r   field_variations         r3   r   ArgObject.GenerateType  s     ((4??.. ) 6J  ,,U3O)--111"":77	I//77	7&&z;;$$Z@@r>   )r   rS  r   r   r   rP  r   rR   )FN)NNNNNNF)F)T)TF)r   r9   r:   r;   r<   r\   r@  rG  rM  rK   rW   rZ  rb  rj  r}  r  r  r   r=   r    r>   r3   r   r     s    F      ! !F @D26',
;M9"<|0!d#JAr>   r   c                   [         R                  " XR                  5      nUR                  =(       d    [	        U5      n[
        R                  UUR                  UR                  UR                  S9n[        UUUR                  5       S9$ )zRetrieves the the type of the field from message.

Args:
  message: Apitools message class
  user_field_spec: ArgDictFieldSpec, specifies the api field

Returns:
  _FieldType, type function that returns apitools field class
)r   r   r   r  )r   rg  r   r   r;  r   r   r   r   r   	ChoiceMap)rh  user_field_specr   r   r   s        r3   _GetArgDictFieldTyper    s     
'
'1J1J
K%''D+=e+D(&&''))''	 ' )* 
'')
+ +r>   c                  :    \ rS rSrSr\S 5       rS rS rS r	Sr
g)	r   i  a  A wrapper to bind an ArgDict argument to a message.

The non-flat mode has one dict per message. When the field is repeated, you
can repeat the message by repeating the flag. For example, given a message
with fields foo and bar, it looks like:

--arg foo=1,bar=2 --arg foo=3,bar=4

The Action method below is used later during argument generation to tell
argparse to allow repeats of the dictionary and to append them.
c                4   US   nUR                  S5      nUS   [           nUS    Vs/ s H  n[        R                  U5      PM     nnUR                  S5      (       a+  [	        U5      S:w  a  [        S5      e[        X#US   US	   S
9$ U " X#U5      $ s  snf )Nr   r   r   r   flattenr_   z;Flattened ArgDicts must have exactly two items in the spec.r   ra   r   r   r%  r&  )rF   r   ArgDictFieldSpecrK   re   r@   FlattenedArgDict)rH   rI   r   r   r   r1   fieldss          r3   rK   ArgDict.FromData  s    [!Ixx
#HF|H%H4<V4DE4Dq''*4DFE||I	V	 IK 	K!94 4 yF++ Fs   Bc                (    Xl         X l        X0l        g rR   r   r   r  )rV   r   r   r  s       r3   rW   ArgDict.__init__  s    NMKr>   c                    g)Nrq   r    rZ   s    r3   rZ  ArgDict.Action  s    r>   c                   [         R                  XR                  U R                  S9nU R                   Vs/ s H  n[        UR                  U5      PM     nnU Vs/ s H!  o3R                  (       d  M  UR                  PM#     nn[        R                  " U Vs0 s H  o3R                  U_M     snUS9n[        UUUS9$ s  snf s  snf s  snf )a  Generates an argparse type function to use to parse the argument.

The return of the type function will be an instance of the given message
with the fields filled in.

Args:
  field: apitools field instance we are generating ArgObject for

Raises:
  InvalidSchemaError: If a type for a field could not be determined.

Returns:
  _MessageFieldType, The type function that parses the ArgDict and returns
  a message instance.
r   r   )r   r  r  )r   r   r   r   r  r  r   r   r   r   r  )rV   r   r   r^  r  r   r   s          r3   r   ArgDict.GenerateType  s      (( ) AJ@DL1'

A6KL$/>Kq::


KH>""%01[jj!m[1 H ! ! M> 2s    CC5CCr  N)r   r9   r:   r;   r<   r\   rK   rW   rZ  r   r=   r    r>   r3   r   r     s*    
 , ,!r>   r   c                  $    \ rS rSrSrS rS rSrg)r  i,  a6  A wrapper to bind an ArgDict argument to a message with a key/value pair.

The flat mode has one dict corresponding to a repeated field. For example,
given a message with fields key and value, it looks like:

--arg a=b,c=d

Which would generate 2 instances of the message:
[{key=a, value=b}, {key=c, value=d}]
c                4    Xl         X l        X0l        X@l        g rR   r  )rV   r   r   r%  r&  s        r3   rW   FlattenedArgDict.__init__8  s    NMM Or>   c                   [         R                  XR                  U R                  S9n[	        UR
                  U R                  5      n[	        UR
                  U R                  5      n[        R                  " X4S9n[        UUUUS9$ )a  Generates an argparse type function to use to parse the argument.

The return of the type function will be a list of instances of the given
message with the fields filled in.

Args:
  field: apitools field instance we are generating ArgObject for

Raises:
  InvalidSchemaError: If a type for a field could not be determined.

Returns:
  _AdditionalPropsType, The type function that parses the ArgDict
    and returns a list of message instances.
r  )rq  rr  ru  )r   r   r   r   r  r   r%  r&  r   r   r#  )rV   r   r   rq  rr  r   s         r3   r   FlattenedArgDict.GenerateType?  sx      (( ) AJ#EJJ>H%ejj$//BJ""HLH	 r>   r  N)r   r9   r:   r;   r<   rW   r   r=   r    r>   r3   r  r  ,  s    	!r>   r  c                  b    \ rS rSr% Sr\S 5       rS\S'   S\S'   S\S'   S	\S
'   S\S'   S rSr	g)r  i\  at  Attributes about the fields that make up an ArgDict spec.

Attributes:
  api_field: The name of the field under the repeated message that the value
    should be put.
  arg_name: The name of the key in the dict.
  field_type: The argparse type of the value of this field.
  required: True if the key is required.
  choices: A static map of choice to value the user types.
c           	         UR                  S5      nU(       a  U Vs/ s H  n[        U5      PM     snOS nU " US   UR                  S5      [        U5      UR                  SS5      US9$ s  snf )Nr   r   r   r   T)r   r   r   r   r   )rF   r   r   )rH   rI   data_choicesr1   r   s        r3   rK   ArgDictFieldSpec.FromDatai  sj    88I&L3?,/,Qvay,/TG{#*%T?*d+  0s   A,z
str | Noner   r   r   r   r   r   zlist[Choice] | Noner   c                @    [         R                  U R                  5      $ rR   )r   r   r   rZ   s    r3   r  ArgDictFieldSpec.ChoiceMap{  s    dll++r>   r    N)
r   r9   r:   r;   r<   r\   rK   r   r  r=   r    r>   r3   r  r  \  s?    	 	 	 )).,r>   r  c                  8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )_ArgJSONTypei  z>Parse json into apitools type but preserve arg_json help text.c                   > [         [        U ]  US9  UR                  U l        UR                  U l        [
        R                  " UR                  5      U l        g r   )r   r  rW   r   r   r   r  r   r   s      r3   rW   _ArgJSONType.__init__  sG    	,&&9!!DJ''DM,,Z-=-=>DOr>   c                   [        U[        5      (       a2  U R                  (       a!  U Vs/ s H  o R                  U5      PM     sn$ U R                  [
        R                  R                  :X  a+  [        U[        5      (       d  [        R                  " S5      e[
        R                  " U R                  R                  U5      $ s  snf )Nz(Expecting map format i.e. {"foo": "bar"})rt   r  r   _EncodeInputr   r   r  JSONr   r   ArgumentTypeErrorEncodeToMessager   r   )rV   r   r,  s      r3   r  _ArgJSONType._EncodeInput  s     %4==,12Eq"E229..333ud##))
46 6 $$TZZ__e<< 3s   Cc                    U R                  U5      n U R                  U5      $ ! [        R                   a!  n[        R                  " SU SU 35      eS nAff = f)NzBad value [z]: )r   r  r   r  )rV   r   r   rk   s       r3   r   _ArgJSONType.__call__  s_    }}Y/K/00(( K))K	{#aS*IJJKs   $ AAA)r   r   r   )
r   r9   r:   r;   r<   rW   r  r   r=   r   r   s   @r3   r  r    s    F?=K Kr>   r  c                  .    \ rS rSrSr\S 5       rS rSrg)r   i  z3A wrapper to bind an ArgJSON argument to a message.c                    AU " 5       $ )zCreates ArgJSON from yaml data.r    r   s     r3   rK   ArgJSON.FromData  s     	5Lr>   c                    [         R                  " U5      nU[         R                  R                  :w  a)  U[         R                  R                  :w  a  [        S5      e[        R                  U5      n[        [        R                  " 5       US9$ )NzbInvalid type: arg_json cannot be used for non-struct field types.Recommend changing to arg_object.rv  )r   r  r  r  
JSON_VALUEr@   r   r   r  r   r   )rV   r   r   r   s       r3   r   ArgJSON.GenerateType  sv     ''.Ji))...i))444./ / ((/J!4!4!6:NNr>   r    Nr   r    r>   r3   r   r     s    ; 
Or>   r   )NN)Wr<   
__future__r   r   r   r   r   collections.abcr   dataclassestypingr   apitools.base.protorpcliter	   r   googlecloudsdk.callioper
   r   r   
usage_text$googlecloudsdk.command_lib.util.apisr   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   googlecloudsdk.core.utilr   r#   r$   r&   r'   ry  rz  r   r   r   r   r   r   r   r   r4   	Exceptionr6   r@   objectrC   rN   rv   	frozensetrx   r~   ru   r   r   r   Encoder   r   r   r   ABCMetar   FileTyper   	dataclassr   r   DefaultArgTypeWrapperr   r   r  r  r#  r2  r;  ArgObjectTyper   r  RepeatedMessageBindableTyper   r  r  r  ArgJSONTyper   r    r>   r3   <module>r     s`    7 ' "  ' 
 $   D + / H : < + 2 * ) . 
U,6 (
Hh/ fe	 EI04 FI 
 
46 4n,^ ' <=?B !!#0#?L8V 8@)ckk )=)"4"4 . d#9 9 $9xOckk O&MZ55 &MR" "J77 7t.>= .bHNM H($kA	'' kA\	+0@!mYBB @!F-}i&K&K -` d#, , $,DK:33 K<OmY22 Or>   