
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlZ ej                  ej                         G d dej                               Zy)	a  The Cloud SDK completion cache.

A completion cache is a persistent cache that stores the current list of names
for resources visible to the caller.  The cache generates lists of resources
that match prefixes and/or patterns, suitable for command line completers. The
name representation is resource specific.  See core.resource.resource_style for
details.

Refer to the resource_cache module for a detailed description of resource
parsing and representation.

    +---------------------------+
    | completion cache          |
    | +-----------------------+ |
    | | completer             | |
    | +-----------------------+ |
    |           ...             |
    +---------------------------+

A completion cache is implemented as an extended ResourceCache object that
contains Completer objects.  A Completer object:

* has a Complete() method that returns resource strings matching a pattern
* has methods to convert between strings and parameter tuples
* has an underlying ResourceCache Collection object that holds parameter tuples
* derives from resource_cache.Updater to update the collection parameter tuples

This module is resource agnostic.  All resource specific information is
encapsulated in resource specific Completer objects.
    )absolute_import)division)unicode_literalsN)resource_cachec                   f    e Zd ZdZej
                  d        Zd Zej
                  dd       Zd Z	y)	CompleteraN  A completion cache resource string completer.

  Along with the Complete() method, a completer has two main functions, each
  handled by a mixin:
  (1) Convert between resource string and parameter tuple representations.
  (2) Retrieve the current list of resources for the collection. See
      resource_cache.Updater for details.
  c                      y)zReturns the row representation of string.

    May fill in some column values

    Args:
      string: The resource string representation.

    Returns:
      The row representation of string.
    N )selfstrings     1lib/googlecloudsdk/core/cache/completion_cache.pyStringToRowzCompleter.StringToRowE        	    c                     t        |      }t        |      | j                  k  r|dg| j                  t        |      z
  z  z  }|D cg c]  }d|v r|n|dz    c}S c c}w )a   Returns the row template of row for the Resource.Complete method.

    By default all parameters are treated as prefixes.

    Args:
      row: The resource parameter tuple.

    Returns:
      The row template of row for the Resource.Complete method.
     *)listlencolumns)r   rowrow_templatecs       r   RowToTemplatezCompleter.RowToTemplateS   sb     9L
3x$,,rddllSX566l0<=1Aq3w&===s   ANc                      y)a  Returns the string representation of row.

    Args:
      row: The resource parameter tuple.
      parameter_info: A ParamaterInfo object for accessing parameter values in
        the program state.

    Returns:
      The string representation of row.
    Nr
   )r   r   parameter_infos      r   RowToStringzCompleter.RowToStringc   r   r   c                     | j                  |      }| j                  |      }| j                  ||      }|D cg c]  }| j                  ||       c}S c c}w )a  Returns the list of strings matching prefix.

    Args:
      prefix: The resource prefix string to match.
      parameter_info: A ParamaterInfo object for accessing parameter values in
        the program state.

    Returns:
      The list of strings matching prefix.
    )r   r   Selectr   )r   prefixr   r   r   rowss         r   CompletezCompleter.Completeq   sY     

6
"C%%c*L;;|^4D=ABTcDS.1TBBBs   A)N)
__name__
__module____qualname____doc__abcabstractmethodr   r   r   r"   r
   r   r   r   r   :   sF     	 	>  	 	Cr   r   )r&   
__future__r   r   r   r'   googlecloudsdk.core.cacher   sixadd_metaclassABCMetaUpdaterr   r
   r   r   <module>r/      sV    > '  ' 
 4 
 3;;DC&& DC  DCr   