o
    €Ï  ã                   @   sf   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 	ej
¡G dd„ dejƒƒZdS )	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                   @   s>   e Zd ZdZejdd„ ƒZdd„ Zejddd„ƒZd	d
„ Z	dS )Ú	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                 C   ó   dS )zÅReturns 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Ústringr   r   úG/tmp/google-cloud-sdk/lib/googlecloudsdk/core/cache/completion_cache.pyÚStringToRowE   ó   zCompleter.StringToRowc                 C   s<   t |ƒ}t|ƒ| jk r|dg| jt|ƒ  7 }dd„ |D ƒS )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.
    Ú c                 S   s    g | ]}d |v r
|n|d  ‘qS )Ú*r   )Ú.0Úcr   r   r   Ú
<listcomp>a   s     z+Completer.RowToTemplate.<locals>.<listcomp>)ÚlistÚlenÚcolumns)r	   ÚrowÚrow_templater   r   r   ÚRowToTemplateS   s   zCompleter.RowToTemplateNc                 C   r   )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_infor   r   r   ÚRowToStringc   r   zCompleter.RowToStringc                    s4   ˆ  |¡}ˆ |¡}ˆ |ˆ ¡}‡ ‡fdd„|D ƒS )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.
    c                    s   g | ]}ˆ  |ˆ ¡‘qS r   )r   )r   r   ©r   r	   r   r   r      s    z&Completer.Complete.<locals>.<listcomp>)r   r   ÚSelect)r	   Úprefixr   r   r   Úrowsr   r   r   ÚCompleteq   s   

zCompleter.Complete)N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚabcÚabstractmethodr   r   r   r   r   r   r   r   r   :   s    	
r   )r#   Ú
__future__r   r   r   r$   Úgooglecloudsdk.core.cacher   ÚsixÚadd_metaclassÚABCMetaÚUpdaterr   r   r   r   r   Ú<module>   s   
