
                             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Jr  SSK	J
r
  SSKr " S	 S
\
R                  5      r " S S\5      r " S S\5      r " S S\5      rg)z2Classes for runtime handling of concept arguments.    )absolute_import)division)unicode_literals)parser_errors)util)
exceptionsNc                       \ rS rSrSrSrg)Error   z%Base class for errors in this module. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       0lib/googlecloudsdk/calliope/concepts/handlers.pyr
   r
      s    -r   r
   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )
ParseError   z#Raised if a concept fails to parse.c                 N   > SR                  X5      n[        [        U ]  U5        g )NzError parsing [{}].
{})formatsuperr   __init__)selfpresentation_namemessagemsg	__class__s       r   r   ParseError.__init__"   s#    
#
*
*+<
FC	*d$S)r   r   r   r   r   r   r   r   r   __classcell__r    s   @r   r   r      s    +* *r   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )RepeatedConceptName'   zGRaised when adding a concept if one with the given name already exists.c                 N   > SR                  U5      n[        [        U ]  U5        g )NzRepeated concept name [{}].)r   r   r&   r   )r   concept_namer   r    s      r   r   RepeatedConceptName.__init__*   s#    
'
.
.|
<C	
t-c2r   r   r"   r$   s   @r   r&   r&   '   s    O3 3r   r&   c                   @    \ rS rSrSrS rS rSS jrS rS r	S r
S	rg
)RuntimeHandler/   zA handler to hold information about all concept arguments in a command.

The handler is assigned to 'CONCEPTS' in the argparse namespace and has an
attribute to match the name of each concept argument in lower snake case.
c                 .    S U l         0 U l        / U l        g N)parsed_args_arg_name_lookup_all_conceptsr   s    r   r   RuntimeHandler.__init__6   s    DDDr   c                     U R                   $ )z=Basically a lazy property to use during lazy concept parsing.)r0   r3   s    r   
ParsedArgsRuntimeHandler.ParsedArgs<   s    r   c                   ^^^ SSK Jm   " UUU4S jS[        5      n[        U T5      (       a  [	        T5      e[        U TU" UR                  U R                  5      5        U R                  R                  TUTS.5        [        R                  " UR                  5       H'  u  pVX R                  [        R                  " U5      '   M)     g)ah  Adds a concept handler for a given concept.

Args:
  name: str, the name to be used for the presentation spec.
  concept_info: ConceptInfo, the object that holds dependencies of the
    concept.
  required: bool, True if the concept must be parseable, False if not.

Raises:
  RepeatedConceptName: If the given "name" has already been used with a
    concept.
r   )conceptsc                   0   > \ rS rSrSrS rU UU4S jrSrg),RuntimeHandler.AddConcept.<locals>.LazyParseQ   zBClass provided when accessing a concept to lazily parse from args.c                     Xl         X l        g r/   )parse
arg_getter)r   r>   r?   s      r   r   5RuntimeHandler.AddConcept.<locals>.LazyParse.__init__T   s    
$r   c                    >  U R                  U R                  5       5      $ ! TR                   a1  nT(       a   [        T[        R
                  " U5      5      e S nAg S nAff = fr/   )r>   r?   InitializationErrorr   six	text_type)r   er9   namerequireds     r   Parse2RuntimeHandler.AddConcept.<locals>.LazyParse.ParseX   sP    	DOO-.
.++ 	T3==#344	s   " A#'AA#)r?   r>   N)r   r   r   r   r   r   rH   r   )r9   rF   rG   s   r   	LazyParser;   Q   s    N% r   rJ   )rF   concept_inforG   N) googlecloudsdk.calliope.conceptsr9   objecthasattrr&   setattrrH   r6   r2   appendrC   	iteritemsattribute_to_args_mapr1   r   NormalizeFormat)r   rF   rK   rG   rJ   _arg_namer9   s    ` `   @r   
AddConceptRuntimeHandler.AddConcept@   s     : F  tT%%D$	,"4"4dooFG$ 
 }}\%G%GH>JD00:; Ir   c                 `    U R                   R                  [        R                  " U5      5      $ r/   )r1   getr   rS   )r   rU   s     r   ArgNameToConceptInfo#RuntimeHandler.ArgNameToConceptInfok   s$      $$T%9%9(%CDDr   c                 P    U R                    H  nUS   R                  5         M     g )NrK   )r2   
ClearCache)r   concept_detailss     r   ResetRuntimeHandler.Resetn   s#    --n%002 .r   c                      [        X5      $ ! [         a&    [        R                  " SR	                  U5      5      ef = f)a  Returns the value of the argument registered for dest.

Based on argparse.Namespace.GetValue().

Args:
  dest: The dest of a registered argument.

Raises:
  UnknownDestinationException: If no arg is registered for dest.

Returns:
  The value of the argument registered for dest.
z/No registered concept arg for destination [{}].)getattrAttributeErrorr   UnknownDestinationExceptionr   )r   dests     r   GetValueRuntimeHandler.GetValuer   sG    JT   J55
;
B
B4
HJ JJs   
 0=)r2   r1   r0   N)T)r   r   r   r   r   r   r6   rV   rZ   r_   rf   r   r   r   r   r,   r,   /   s)    )KVE3Jr   r,   )r   
__future__r   r   r   googlecloudsdk.callioper   rL   r   googlecloudsdk.corer   rC   r
   r   r&   rM   r,   r   r   r   <module>rk      sY    9 &  ' 1 1 * 
.J .* *3% 3UJV UJr   