
    )                        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rSSKJr	  SSKJ
r
  SS	KJr  SS
KJr  Sr " S S\	R                   5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rS r " S S\5      rg)a  Resource printer base class.

Each printer has three main attributes, all accessible as strings in the
--format='NAME[ATTRIBUTES](PROJECTION)' option:

  NAME: str, The printer name.

  [ATTRIBUTES]: str, An optional [no-]name[=value] list of attributes. Unknown
    attributes are silently ignored. Attributes are added to a printer local
    dict indexed by name.

  (PROJECTION): str, List of resource names to be included in the output
    resource. Unknown names are silently ignored. Resource names are
    '.'-separated key identifiers with an implicit top level resource name.

Example:

  gcloud compute instances list       --format='table[box](name, networkInterfaces[0].networkIP)'
    )absolute_import)division)print_function)unicode_literalsN)
exceptions)log)
console_io)resource_property   c                       \ rS rSrSrSrg)Error6   zExceptions for this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       9lib/googlecloudsdk/core/resource/resource_printer_base.pyr   r   6   s    #r   r   c                       \ rS rSrSrSrg)ProjectionRequiredError:   z-Format missing required projection exception.r   Nr   r   r   r   r   r   :   s    5r   r   c                       \ rS rSrSrS rSrg)_ResourceMarker>   z2A marker that can be injected into resource lists.c                     g)zMCalled by ResourcePrinter.Addrecord().

Args:
  printer: The printer object.
Nr   selfprinters     r   Act_ResourceMarker.ActA   s     	r   r   Nr   r   r   r   r   r#   r   r   r   r   r   r   >   s
    :	r   r   c                       \ rS rSrSrS rSrg)FinishMarkerJ   zA resource list Finish marker.c                 $    UR                  5         g N)Finishr    s     r   r#   FinishMarker.ActM   s    NNr   r   Nr%   r   r   r   r'   r'   J   s
    &r   r'   c                       \ rS rSrSrS rSrg)
PageMarkerQ   zA resource list Page marker.c                 $    UR                  5         g r*   )Pager    s     r   r#   PageMarker.ActT   s    LLNr   r   Nr%   r   r   r   r.   r.   Q   s
    $r   r.   c                 "    [        U [        5      $ )z.Returns True if resource is a _ResourceMarker.)
isinstancer   )resources    r   IsResourceMarkerr6   X   s    	Ho	..r   c                   x    \ rS rSrSr    SS jrS rS rS rSS jr	SS	 jr
S
 rS rS rS rSS jrS rSrg)ResourcePrinter]   aC  Base class for printing JSON-serializable Python objects.

Attributes:
  attributes: Optional printer attribute dict indexed by attribute name.
  column_attributes: Projection column attributes.
  _console_attr: The console attributes. May be ignored by some printers.
  _empty: True if there are no records.
  _heading: The list of column heading label strings.
  _name: Format name.
  _non_empty_projection_required: True if the printer requires a non-empty
    projection.
  _out: Output stream.
  _process_record: The function called to process each record passed to
    AddRecord() before calling _AddRecord(). It is called like this:
      record = process_record(record)
  _printer: The resource_printer.Printer method for nested formats.
  _is_column_visible: List of Boolean values indicating if indexed column is
    visible
Nc                 4   SSK Jn  Xl        SU l        SU l        X l        Xpl        U=(       d    [        R                  U l	        Xl
        SU l        SU l        U(       d  UR                  5       nU=(       d    UR                  U l        UR!                  U5        UR#                  U5        UR%                  5       nU(       a  UR'                  5       =(       d    0 U l        Xl        SU R(                  ;   a[  [        R,                  R/                  SR1                  UR3                  5       5      5        UR/                  [        R,                  5        O0 U l        SU l        SU R(                  ;   a  Sn
UR5                  U
5        S	U R(                  ;   a    U R                  R7                  5       U l	        S
U R(                  ;   a5  Uc2  U R                  U l        [:        R<                  " 5       U l	        SU l        U R?                  5         g! [8         a     Nbf = f)a  Constructor.

Args:
  out: The output stream, log.out if None. If the 'private' attribute is set
    and the output stream is a log._ConsoleWriter then the underlying stream
    is used instead to disable output to the log file.
  name: The format name.
  projector: Optional resource Projector.
  by_columns: True if AddRecord() expects a list of columns.
  ignore_default_transforms: Ignore default projection transforms if True.
  process_record: The function called to process each record passed to
    AddRecord() before calling _AddRecord(). It is called like this:
      record = process_record(record)
  non_empty_projection_required: True if the printer requires a non-empty
    projection.
  printer: The resource_printer.Printer method for nested formats.
  console_attr: The console attributes for the output stream. Ignored by
    some printers. If None then printers that require it will initialize it
    to match out.
  retain_none_values: Retain resurce dict entries with None values.
r   )resource_projectorTNFdebugz{0} format projection:zno-undefinedprivatepager) googlecloudsdk.core.resourcer;   _console_attr_empty_heading_name_non_empty_projection_requiredr   out_out_printer_pager
_pager_outCompileEvaluate_process_recordSetByColumnsSetIgnoreDefaultTransforms
Projection
Attributes
attributescolumn_attributesstatusPrintformatNameSetRetainNoneValuesGetConsoleWriterStreamAttributeErrorioStringIO_SetVisibleColumns)r!   rE   name	projector
by_columnsignore_default_transformsprocess_recordnon_empty_projection_requiredr"   console_attrretain_none_valuesr;   
projections                r   __init__ResourcePrinter.__init__r   s   4 @ &DKDMJ*G'swwDIMDKDO$,,.i)?Y-?-?D:&(()BC%%'J"--/52do)	DOO	#

1889JKL$do#d( !!"45DOO#II446	 $//!ck		do++-didk  s   H
 

HHc                     U R                   (       aJ  U R                   R                  5        Vs/ s H  nUR                  R                  (       + PM      snU l        gSU l        gs  snf )z@Sets visible columns list if column attributes have been loaded.N)rR   Columns	attributehidden_is_column_visible)r!   columns     r   r\   "ResourcePrinter._SetVisibleColumns   sZ     ..668!8f %%
%8!d
 !%d!s   %A$c                     U R                   (       d  U R                  5         U R                   (       a6  [        U5       VVs/ s H  u  p#U R                   U   (       d  M  UPM     snn$ U$ s  snnf )z.Returns a list of visible columns given a row.)rl   r\   	enumerate)r!   rowicols       r   RemoveHiddenColumns#ResourcePrinter.RemoveHiddenColumns   sS    ""
 )#Mfa$2I2I!2LcMMj Ns   A+A+c                     Xl         g)zOverrides the default heading.

If the printer does not support headings then this is a no-op.

Args:
  heading: List of column heading strings that overrides the default
    heading.
N)rB   )r!   headings     r   
AddHeadingResourcePrinter.AddHeading   s	     Mr   c                     g)zyFormat specific AddRecord().

Args:
  record: A JSON-serializable object.
  delimit: Prints resource delimiters if True.
Nr   r!   recorddelimits      r   
_AddRecordResourcePrinter._AddRecord   s     	r   c                     [        U5      (       a  UR                  U 5        gSU l        U R                  U R	                  U5      U5        g)aC  Adds a record for printing.

Streaming formats (e.g., YAML) can print results at each AddRecord() call.
Non-streaming formats (e.g., JSON, table(...)) may cache data at each
AddRecord() call and not print until Finish() is called.

Args:
  record: A JSON-serializable object.
  delimit: Prints resource delimiters if True.
FN)r6   r#   rA   r~   rL   r{   s      r   	AddRecordResourcePrinter.AddRecord   s;     jjdk
ood**62G<r   c                     U R                   (       aK  U R                  (       a9   [        R                  " U R                  R	                  5       U R
                  S9  ggg! [         a     gf = f)zWPrints the results for non-streaming formats.

Must be called via super if overridden.
)rE   N)rH   rF   r	   MoregetvaluerI   rY   r!   s    r   r+   ResourcePrinter.Finish   sP    
 {{tyy		**,$//B !{  s   7A 
A+*A+c                 $    U R                   (       + $ )zEReturns True if some resource items were printed or printer disabled.)rA   r   s    r   ResourcesWerePrinted$ResourcePrinter.ResourcesWerePrinted   s    {{?r   c                     g)z3Flushes intermediate results for streaming formats.Nr   r   s    r   r1   ResourcePrinter.Page  s    r   c                 D    U R                  USS9  U R                  5         g)zIPrint one record by itself.

Args:
  record: A JSON-serializable object.
Fr}   N)r   r+   )r!   r|   s     r   PrintSingleRecord!ResourcePrinter.PrintSingleRecord  s     	NN65N)KKMr   c                    SU R                   ;   a  SU l        gU R                  (       aT  U R                  (       a  U R                  R	                  5       (       d$  [        SR                  U R                  5      5      e U(       aL  U(       d  [        R                  " U5      (       d  U R                  XS9  OU H  nU R                  U5        M     U(       d  U R                  5         gg! U(       d  U R                  5         f f = f)a  Prints resources using printer.AddRecord() and printer.Finish().

Args:
  resources: A singleton or list of JSON-serializable Python objects.
  single: If True then resources is a single item and not a list.
    For example, use this to print a single object as JSON.
  intermediate: This is an intermediate call, do not call Finish().

Raises:
  ProjectionRequiredError: If the projection is empty and the format
    requires a non-empty projection.
disableFNztFormat [{0}] requires a non-empty projection. Use key parameters to specify a projection like so `{0}(foo, bar.baz)`r   )rQ   rA   rD   rR   ri   r   rU   rC   r
   
IsListLiker   r+   )r!   	resourcessingleintermediater5   s        r   rT   ResourcePrinter.Print  s     DOO#dk**""$*@*@*H*H*J*J# A6$** 		*55i@@
...
9#hNN8$ $  \ s   ?AC+ +Dc                 &    U R                   " U0 UD6$ )zBCalls the resource_printer.Printer() method (for nested printers).)rG   )r!   argskwargss      r   PrinterResourcePrinter.Printer3  s    ==$)&))r   )r@   rA   rB   rl   rC   rD   rF   rH   rI   rG   rL   rQ   rR   )
NNNFFNFNNF)T)FF)r   r   r   r   r   rf   r\   rt   rx   r~   r   r+   r   r1   r   rT   r   r   r   r   r   r8   r8   ]   sV    ( FK?C<@5:EN%		="
	#J*r   r8   )r   
__future__r   r   r   r   rZ   googlecloudsdk.corer   core_exceptionsr   googlecloudsdk.core.consoler	   r?   r
   STRUCTURED_INDENTATIONr   r   objectr   r'   r.   r6   r8   r   r   r   <module>r      s    * '  % ' 	 = # 2 :  $O!! $6e 6		f 		?  /
X*f X*r   