
                         N    d Z ddlmZ ddlmZ ddlmZ ddlmZ  G d de      Zy)	z6Resource display info for the Calliope display module.    )absolute_import)division)unicode_literals)cache_update_opsc                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zed        Zed        Zed        Zed        Zed        Zed        Zy)DisplayInfoa  Display info accumulator for priming Displayer.

  "legacy" logic will be dropped when the incremental Command class refactor
  is complete.

  NOTICE: If you add an attribute:
    (1) document it
    (2) handle it in AddLowerDisplayInfo()

  Attributes:
    cache_updater: A resource_cache.Updater class that will be instantiated and
      called to update the cache to reflect the resources returned by the
      calling command.
    filter: The default filter string. args.filter takes precedence.
    flatten: The default flatten string. args.flatten takes precedence.
    format: The default format string. args.format takes precedence.
    transforms: The filter/format transforms symbol dict.
    aliases: The resource name alias dict.
  c                 X    d | _         d | _        d | _        d | _        i | _        i | _        y N)_cache_updater_filter_format_flatten_transforms_aliasesselfs    +lib/googlecloudsdk/calliope/display_info.py__init__zDisplayInfo.__init__-   s.    DDLDLDMDDM    c                    | j                   s|j                  | _         | j                  s|j                  | _        | j                  s|j
                  | _        | j                  s|j                  | _        |j                  r7t        |j                        }|j                  | j                         || _        |j                  r8t        |j                        }|j                  | j                         || _        yy)zAdd lower precedence display_info to the object.

    This method is called by calliope to propagate CLI low precedence parent
    info to its high precedence children.

    Args:
      display_info: The low precedence DisplayInfo object to add.
    N)r   cache_updaterr   filterr   formatr   flatten
transformsdictupdater   aliasesr   )r   display_infor   r   s       r   AddLowerDisplayInfozDisplayInfo.AddLowerDisplayInfo6   s     (66d<<!((dl<<!((dl=="**dm//0j(#d\))*gnnT]]#dm r   c                     |r|| _         yy)zAdds a format to the display info, newer info takes precedence.

    Args:
      format: The default format string. args.format takes precedence.
    Nr   )r   r   s     r   	AddFormatzDisplayInfo.AddFormatP        dl r   c                     |r|| _         yy)a+  Adds a flatten to the display info, newer info takes precedence.

    Args:
      flatten: [str], The list of flatten strings to use by default; e.g.
        ['fieldA.fieldB', 'fieldC.fieldD']. Flatten strings provided by
        args.flatten take precedence if the --flatten flag is specified.
    Nr   )r   r   s     r   
AddFlattenzDisplayInfo.AddFlattenY   s     dm r   c                     |r|| _         yy)zAdds a filter to the display info, newer info takes precedence.

    Args:
      filter: The default filter string. args.filter takes precedence.
    Nr   )r   r   s     r   	AddFilterzDisplayInfo.AddFilterd   r$   r   c                 @    |r| j                   j                  |       yy)zAdds transforms to the display info, newer values takes precedence.

    Args:
      transforms: A filter/format transforms symbol dict.
    N)r   r   )r   r   s     r   AddTransformszDisplayInfo.AddTransformsm   s      
j) r   c                 8    dfd	}| j                  d|i       y)zAdds a uri transform to the display info using uri_func.

    Args:
      uri_func: func(resource), A function that returns the uri for a resource
        object.
    Nc                 L    	  |       xs |S # t         t        f$ r |cY S w xY wr
   )AttributeError	TypeError)resource	undefineduri_funcs     r   _TransformUriz-DisplayInfo.AddUriFunc.<locals>._TransformUri~   s2    !.Y.i( s    ##urir
   )r,   )r   r3   r4   s    ` r   
AddUriFunczDisplayInfo.AddUriFuncv   s     	}-.r   c                 @    |r| j                   j                  |       yy)a7  Adds aliases to the display info, newer values takes precedence.

    Args:
      aliases: {str: parsed_key} The resource name alias dict that maps short
        names to parsed keys. The parsed key for 'abc.xyz' is ['abc', 'xyz'].
        See the resource_lex.Lexer.Key() docstring for parsed key details.
    N)r   r   )r   r   s     r   
AddAliaseszDisplayInfo.AddAliases   s     
mm7# r   c                 6    |xs t         j                  | _        y)a  Adds a cache_updater to the display info, newer values takes precedence.

    The cache updater is called to update the resource cache for CreateCommand,
    DeleteCommand and ListCommand commands.

    Args:
      cache_updater: A resource_cache.Updater class that will be instantiated
        and called to update the cache to reflect the resources returned by the
        calling command. None disables cache update.
    N)r   NoCacheUpdaterr   )r   r   s     r   AddCacheUpdaterzDisplayInfo.AddCacheUpdater   s     (J+;+J+JDr   c                     | j                   S r
   )r   r   s    r   r   zDisplayInfo.cache_updater   s    r   c                     | j                   S r
   r"   r   s    r   r   zDisplayInfo.format       <<r   c                     | j                   S r
   r&   r   s    r   r   zDisplayInfo.flatten       ==r   c                     | j                   S r
   r)   r   s    r   r   zDisplayInfo.filter   r>   r   c                     | j                   S r
   )r   r   s    r   r   zDisplayInfo.aliases   r@   r   c                     | j                   S r
   )r   r   s    r   r   zDisplayInfo.transforms   s    r   N)__name__
__module____qualname____doc__r   r    r#   r'   r*   r,   r6   r8   r;   propertyr   r   r   r   r   r    r   r   r   r      s    (4	*/ 	$K            r   r   N)	rG   
__future__r   r   r   googlecloudsdk.core.cacher   objectr   rI   r   r   <module>rM      s$    = &  ' 6\& \r   