o
                         @   sH   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 deZdS )	z6Resource display info for the Calliope display module.    )absolute_import)division)unicode_literals)cache_update_opsc                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zedd Zedd Zedd Zedd Zedd Zedd Zd S )!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                 C   s(   d | _ d | _d | _d | _i | _i | _d S N)_cache_updater_filter_format_flatten_transforms_aliasesself r   A/tmp/google-cloud-sdk/lib/googlecloudsdk/calliope/display_info.py__init__-   s   
zDisplayInfo.__init__c                 C   s   | j s|j| _ | js|j| _| js|j| _| js|j| _|jr-t	|j}|
| j || _|jr@t	|j}|
| j || _dS dS )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   r   r   r   AddLowerDisplayInfo6   s"   	


zDisplayInfo.AddLowerDisplayInfoc                 C      |r|| _ dS dS )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   r   r   r   	AddFormatP      
zDisplayInfo.AddFormatc                 C   r   )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   r   r   r   
AddFlattenY   s   
zDisplayInfo.AddFlattenc                 C   r   )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   r   r   r   	AddFilterd   r    zDisplayInfo.AddFilterc                 C      |r
| j | dS dS )zAdds transforms to the display info, newer values takes precedence.

    Args:
      transforms: A filter/format transforms symbol dict.
    N)r   r   )r   r   r   r   r   AddTransformsm   s   zDisplayInfo.AddTransformsc                    s    d fdd	}|  d|i dS )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              	      s*   z | p|W S  t tfy   | Y S w r   )AttributeError	TypeError)resource	undefineduri_funcr   r   _TransformUri~   s
   z-DisplayInfo.AddUriFunc.<locals>._TransformUriurir   )r&   )r   r,   r-   r   r+   r   
AddUriFuncv   s   zDisplayInfo.AddUriFuncc                 C   r%   )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   r   r   r   
AddAliases   s   zDisplayInfo.AddAliasesc                 C   s   |pt j| _dS )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   r   r   r   AddCacheUpdater   s   zDisplayInfo.AddCacheUpdaterc                 C      | j S r   )r   r   r   r   r   r         zDisplayInfo.cache_updaterc                 C   r3   r   r   r   r   r   r   r      r4   zDisplayInfo.formatc                 C   r3   r   r!   r   r   r   r   r      r4   zDisplayInfo.flattenc                 C   r3   r   r#   r   r   r   r   r      r4   zDisplayInfo.filterc                 C   r3   r   )r   r   r   r   r   r      r4   zDisplayInfo.aliasesc                 C   r3   r   )r   r   r   r   r   r      r4   zDisplayInfo.transformsN)__name__
__module____qualname____doc__r   r   r   r"   r$   r&   r/   r0   r2   propertyr   r   r   r   r   r   r   r   r   r   r      s.    				




r   N)	r8   
__future__r   r   r   googlecloudsdk.core.cacher   objectr   r   r   r   r   <module>   s   