
                         t   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
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rSr " S S\R,                  5      r " S S\5      r " S S\5      rS rS rS r " S S\5      r " S S\5      r " S S\	R>                  5      r S r!g) z'The meta cache command library support.    )absolute_import)division)unicode_literals)	apis_util)parser_completer)walker)
completers)
exceptions)module_util)	resources)
file_cache)resource_cacheNzresource://c                       \ rS rSrSrSrg)Error'   zBase cache exception. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       1lib/googlecloudsdk/command_lib/meta/cache_util.pyr   r   '   s    r   r   c                       \ rS rSrSrSrg)NoTablesMatched+   z$No table names matched the patterns.r   Nr   r   r   r   r   r   +   s    ,r   r   c                   f    \ rS rSrSr\R                  \R                  S.r	S
S jr
S rS rS rSrg	)GetCache/   zBContext manager for opening a cache given a cache identifier name.)fileresourcec                 *    Xl         X l        SU l        g)a  Constructor.

Args:
  name: The cache name to operate on. May be prefixed by "resource://" for
    resource cache names or "file://" for persistent file cache names. If
    only the prefix is specified then the default cache name for that prefix
    is used.
  create: Creates the persistent cache if it exists if True.

Raises:
  CacheNotFound: If the cache does not exist.

Returns:
  The cache object.
N)_name_create_cache)selfnamecreates      r   __init__GetCache.__init__7   s      JLDKr   c                 r     U" X R                   S9$ ! [        R                   a  n[        U5      eS nAff = f)N)r*   )r&   cache_exceptionsr   )r(   cache_classr)   es       r   
_OpenCacheGetCache._OpenCacheK   s5    ll33!! !Hns    616c                    U R                   (       a  [        R                  " U R                  5       Hp  u  pU R                   R	                  US-   5      (       d  M*  U R                   [        U5      S-   S  nU(       d  S nU R                  X#5      U l        U R                  s  $    U R                  [        R                  U R                   5      U l        U R                  $ )Nz://   )
r%   six	iteritems_TYPES
startswithlenr1   r'   r   ResourceCache)r(   cache_idr/   r)   s       r   	__enter__GetCache.__enter__Q   s    zz#&==#=
(::  E!122CMA-./$D:$+
 $> //.">">

KDK;;r   c                 :    U R                   R                  US L S9  g )N)commit)r'   Close)r(   typvalue	tracebacks       r   __exit__GetCache.__exit__^   s    KKSD[)r   )r'   r&   r%   N)F)r   r   r   r   r   r   Cacher   r:   r7   r+   r1   r<   rD   r   r   r   r   r    r    /   s4    J  ..&
(*r   r    c                  ~     [         R                  " 5         g! [        R                   a  n [        U 5      eSn A ff = f)z8Deletes the resource cache regardless of implementation.N)r   Deleter.   r   )r0   s    r   rH   rH   b   s9     
 
		 
(Ns    <7<c                 V    U R                  SS[        SR                  [        5      S9  g)z-Adds the persistent cache flag to the parser.z--cache
CACHE_NAMEzThe cache name to operate on. May be prefixed by "{}" for resource cache names. If only the prefix is specified then the default cache name for that prefix is used.)metavardefaulthelpN)add_argument_CACHE_RI_DEFAULTformat)parsers    r   AddCacheFlagrR   k   s0    ::@&!;#  %r   c                    Sn U R                  5        HG  nU[        R                  :X  a    O3UR                  R	                  S5      (       d  M;  UR                  nMI      U(       d  [        U 5      (       a  SnU$ ! [
         a     N'f = f)z0Returns the completer type name given its class.N	Completerfunction)mror	   ResourceCompleterr   endswithAttributeErrorcallable)completer_classcompleter_typets      r   _GetCompleterTyper^   w   s|    .	  "	
j**	*	
		[	)	)	 # 
H_55N		 
 		s   (A; A; A; ;
BBc                       \ rS rSrS rSrg)_CompleterModule   c                 P    Xl         X l        X0l        X@l        / U l        0 U l        g N)module_path
collectionapi_versiontypeattachments_attachments_dict)r(   rd   re   rf   r\   s        r   r+   _CompleterModule.__init__   s(    " O"IDDr   )ri   rf   rh   re   rd   rg   Nr   r   r   r   r+   r   r   r   r   r`   r`      s     r   r`   c                       \ rS rSrS rSrg)_CompleterAttachment   c                     Xl         / U l        g rc   )command	arguments)r(   rp   s     r   r+   _CompleterAttachment.__init__   s    LDNr   )rq   rp   Nrk   r   r   r   rm   rm      s    r   rm   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )_CompleterModuleGenerator   z#Constructs a CLI command dict tree.c                 :   > [         [        U ]  U5        0 U l        g rc   )superrt   r+   _modules_dict)r(   cli	__class__s     r   r+   "_CompleterModuleGenerator.__init__   s    	
#T3C8Dr   c           	         S nUR                   n[        UR                  UR                  -   US9 GH  n UR                  nSnSn	[        U[        R                  5      (       a  UR                  n[        R                  " U5      n
[        U[        5      (       a"   U" 5       n UR                  n UR                  n	UR(                  (       a  UR(                  S   nOUR*                  R-                  SS5      nU R.                  R1                  U
5      nU(       d#  [3        U
UU	[5        U5      S9nXR.                  U
'   S	R7                  UR9                  5       5      nUR:                  R1                  U5      nU(       d5  [=        U5      nUUR:                  U'   UR>                  RA                  U5        URB                  RA                  U5        GM     U R.                  $ ! [
         a     GM  f = f! [
         a     GNPf = f! [
         a     GNTf = f! [        R                   ["        R$                  4 a  nSR'                  U5      n SnAGNSnAff = f)
a)  Visits each command in the CLI command tree to construct the module list.

Args:
  command: group/command CommandCommon info.
  parent: The parent Visit() return value, None at the top level.
  is_group: True if command is a group, otherwise its is a command.

Returns:
  The subtree module list.
c                 "    U R                  5       $ rc   )__repr__)actions    r   
_ActionKey3_CompleterModuleGenerator.Visit.<locals>._ActionKey   s    __r   )keyNz	ERROR: {}r   _-)rd   re   rf   r\    )"aisorted	flag_argspositional_args	completerrY   
isinstancer   ArgumentCompleterr[   r   GetModulePathrg   re   rf   r   UnknownAPIErrorr   InvalidCollectionExceptionrP   option_stringsdestreplacerx   getr`   r^   joinGetPathri   rm   rh   appendrq   )r(   rp   parentis_groupr   argsargr[   re   rf   rd   r   r0   r)   modulecommand_path
attachments                    r   Visit_CompleterModuleGenerator.Visit   s    ::Ddnnt';';;L-- jk	O%5%G%G	H	H)99--o>k	OT	*	*	-%')"--J#//K 
		!!!$xxS)!!%%k2f!#!#,_=	
 +1;'XXgoo/0l++//=j),7
1;  .!!*-!!$'Y MZ U        ))446 	-"))!,*	-se   G"H%G42H"
G10G14
H>HHH
HHHH$I:II)rx   )	r   r   r   r   r   r+   r   r   __classcell__)rz   s   @r   rt   rt      s    += =r   rt   c                 b    [        [        U 5      R                  5       R                  5       5      $ )z@Returns the list of all attached CompleterModule objects in cli.)listrt   Walkvalues)ry   s    r   ListAttachedCompletersr      s%    	',113::<	==r   )"r   
__future__r   r   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   googlecloudsdk.command_lib.utilr	   googlecloudsdk.corer
   r   r   googlecloudsdk.core.cacher.   r   r   r5   rO   r   r   objectr    rH   rR   r^   r`   rm   Walkerrt   r   r   r   r   <module>r      s     . &  ' 1 4 * 6 * + ) D 0 4 
 " J -e -0*v 0*f	%  v  6 D DN>r   