
    4d                        S r SSKJr  SSKJr  SSKJr  SSKrSSK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S
KJr  SSKrSSKJr  SrSrSrS rS r " S S\5      r " S S\5      r " S S\R6                  5      rg)zTable format resource printer.    )absolute_import)division)unicode_literalsN)
properties)console_attr)resource_printer_base)resource_projection_spec)resource_transform)range      
   c                    U c  g[        U [        R                  5      (       a  U $ [        U [        R                  5      (       a  [        R
                  " U 5      $ [        U [        5      (       a  [        R                  " U 5      $ [        U S5      (       a  [        R                  " U 5      $ [        R                  " U SS9$ )z7Represents value as a JSON string if it's not a string. __str__T)	sort_keys)
isinstancer   	Colorizersixstring_typesDecodefloatr
   TransformFloathasattr	text_typejsondumpsvalues    1lib/googlecloudsdk/core/resource/table_printer.py
_Stringifyr!   +   s    
]%//00L%))**u%%%,,U33ui  ==::et,,    c                 f    [        U [        R                  [        45      (       a  U $ [        S5      $ )zFRepresents value as a number, or infinity if it is not a valid number.inf)r   r   integer_typesr   r   s    r    _Numifyr&   ;   s)    ))5122L	ur"   c                   0    \ rS rSrSrS rS rS rS rSr	g)	_JustifyB   av  Represents a string object for justification using display width.

Attributes:
  _adjust: The justification width adjustment. The builtin justification
    functions use len() which counts characters, but some character encodings
    require console_attr.DisplayWidth() which returns the encoded character
    display width.
  _string: The output encoded string to justify.
c                     [         R                  " X!R                  5       SS9U l        UR	                  U R                  5      [        U R                  5      -
  U l        g )NF)encodingescape)r   SafeTextGetEncoding_stringDisplayWidthlen_adjust)selfattrstrings      r    __init___Justify.__init__M   sF    (())+E;DL$$T\\2S5FFDLr"   c                 P    U R                   R                  XR                  -
  5      $ N)r/   ljustr2   r3   widths     r    r:   _Justify.ljustR       <<ell233r"   c                 P    U R                   R                  XR                  -
  5      $ r9   )r/   rjustr2   r;   s     r    r@   _Justify.rjustU   r>   r"   c                 P    U R                   R                  XR                  -
  5      $ r9   )r/   centerr2   r;   s     r    rC   _Justify.centerX   s    <<u||344r"   )r2   r/   N)
__name__
__module____qualname____firstlineno____doc__r6   r:   r@   rC   __static_attributes__ r"   r    r(   r(   B   s    G
445r"   r(   c                       \ rS rSrSrS rSrg)	SubFormat\   a5  A sub format object.

Attributes:
  index: The parent column index.
  hidden: Column is projected but not displayed.
  printer: The nested printer object.
  out: The nested printer output stream.
  rows: The nested format aggregate rows if the parent has no columns.
  wrap: If column text should be wrapped.
c                 N    Xl         X l        X0l        X@l        / U l        XPl        g r9   )indexhiddenprinteroutrowswrap)r3   rP   rQ   rR   rS   rU   s         r    r6   SubFormat.__init__h   s"    JKLHDIIr"   )rQ   rP   rS   rR   rT   rU   N)rE   rF   rG   rH   rI   r6   rJ   rK   r"   r    rM   rM   \   s    	r"   rM   c                   f   ^  \ rS rSrSrU 4S jrSS jrS r SS jrS r	S r
U 4S	 jrS
 rSrU =r$ )TablePrinterq   a  A printer for printing human-readable tables.

Aligned left-adjusted columns with optional title, column headings and
sorting. This format requires a projection to define the table columns. The
default column headings are the disambiguated right hand components of the
column keys in ANGRY_SNAKE_CASE. For example, the projection keys
(first.name, last.name) produce the default column heading
('NAME', 'LAST_NAME').

If *--page-size*=_N_ is specified then output is grouped into tables with
at most _N_ rows. Headings, alignment and sorting are done per-page. The
title, if any, is printed before the first table.

If screen reader option is True, you may observe flattened list output instead
of a table with columns. Please refer to $ gcloud topic accessibility to turn
it off.

Printer attributes:
  all-box: Prints a box around the entire table and each cell, including the
    title if any.
  box: Prints a box around the entire table and the title cells if any.
  format=_FORMAT-STRING_: Prints the key data indented by 4 spaces using
    _FORMAT-STRING_ which can reference any of the supported formats.
  no-heading: Disables the column headings.
  margin=N: Right hand side padding when one or more columns are wrapped.
  pad=N: Sets the column horizontal pad to _N_ spaces. The default is 1 for
    box, 2 otherwise.
  title=_TITLE_: Prints a centered _TITLE_ at the top of the table, within
    the table box if *box* is enabled.

Attributes:
  _optional: True if at least one column is optional. An optional column is
    not displayed if it contains no data.
  _page_count: The output page count, incremented before each page.
  _rows: The list of all resource columns indexed by row.
  _visible: Ordered list of visible column indexes.
  _wrap: True if at least one column can be text wrapped.
c           
      n  > / U l         [        [        U ]  " USSS.UD6  SnS H  nX@R                  ;   d  M  Un  O   U R
                  (       d  [        R                  " US9U l        U R
                  R                  5       U l	        SU l
        SU l        / U l        SU l        SnSU l        U R                  (       Ga  U R                  R!                  5        H  nUR"                  R$                  (       d  UR"                  R&                  (       a  SnOSU l        UR"                  R(                  (       a  SU l        UR"                  R*                  (       d  M  SU l        M     [.        R0                  " U R                  R2                  S9nSnU R                  R!                  5        H  nUR"                  R$                  (       al  U R                  (       a  U R4                  O[6        R8                  " 5       n	Sn
U R;                  UR"                  R$                  U	U R
                  US	9nSU l        OSn	SnUR"                  R*                  n
U R                  R=                  [?        XR"                  R&                  XU
5      5        US
-  nM     SU l         U(       d  SU l        SU l        gU R                  (       ax  U R                  (       df  / U l         U R                   HN  nUR&                  (       a  M  URB                  (       a  M)  U R@                  R=                  URD                  5        MP     ggg)zCreates a new TablePrinter.T)
by_columnsnon_empty_projection_requiredN)asciizutf-8win)r+   r   F)symbols)rS   r   defaultsr   )#_rowssuperrX   r6   
attributes_console_attrr   GetConsoleAttrGetControlSequenceIndicator_csi_page_count	_optional_subformats_has_subprinters
_aggregatecolumn_attributesColumns	attribute	subformatrQ   optionalrU   _wrapr	   ProjectionSpecr_   _outioStringIOPrinterappendrM   _visiblerR   rP   )r3   argskwargsr+   namehas_subformatscolr`   rP   rS   rU   rR   rp   	__class__s                r    r6   TablePrinter.__init__   s   DJ	,&	$dNFLNH)		  * '66Id"">>@DID DND!DNDO''//1#==""cmm&:&:.!$/==!!$.==$* 2 *88((002he''//1#==""!__		"++-#$LLmm%%--	 ! !'
 #'$
#'##$e]]117F	H
# 2$ DMddo			$//dm'')	(9(9(9
--

y
/ ( #2	r"   c                 :    U R                   R                  U5        g)zAdds a list of columns.

Output delayed until Finish().

Args:
  record: A JSON-serializable object.
  delimit: Prints resource delimiters if True.
N)ra   rx   )r3   recorddelimits      r    
_AddRecordTablePrinter._AddRecord   s     	JJfr"   c                     U R                   (       a  U(       d  U$ / nU R                    H  nUR                  X   5        M     U$ )z%Return the visible list items in row.)ry   rx   )r3   rowvisiblerP   s       r    _VisibleTablePrinter._Visible   s6    ==jGnnSZ  Nr"   c                    SnSnSnU[        U5      :  a  U R                  (       aJ  XS R                  U R                  5      (       a(  U R                  R	                  XS 5      nXXW-    nXW-  nO&U[
        R                  " X   5      -  nXB:  a  OUS-  nU[        U5      :  a  M  U(       d,  U[        XS 5      [        XS R                  5       5      -
  -  n[        R                  " SU5      nU(       a%  UR                  5       U::  a  UR                  5       nOlSn	[        R                  " SU5       HF  n
U
R                  5       U:  a  U(       a  U
R                  5       U::  a  Un	  OU
R                  5       n	MH     U	(       a  U	nU(       d  USU R                  5       nOUSU nXS nU(       a=  X`R                  R                  5       :w  a   XR                  R                  5       -  nXl-   nX4$ )z3Helper function to get next line of wrappable text.r   r   Nr   z\nz\s+)r1   rg   
startswithrd   GetControlSequenceLenr   GetCharacterDisplayWidthlstripresearchendfinditerstartrstripGetFontCode)r3   s	max_widthinclude_all_whitespacecurrent_widthsplitprefix
seq_lengthfirst_newlinemax_whitespacer	next_lineremaining_values                r    _GetNextLineAndRemainder%TablePrinter._GetNextLineAndRemainder   s    MEF
#a&.	qy++DII66''==aiH
+,>>qxHH$

 #a&. "s1V9~AfI$4$4$6 777e IIeQ'M**,5!e n{{61%!557U?#	U(:"N
 & 
!FU)""$iFU)iiO&..::<<%%1133i0o%%r"   c                     / nU R                   (       aA  U R                    H1  nUR                  (       d  M  UR                  UR                  5        M3     U$ r9   )rj   rR   rx   rP   )r3   subsrp   s      r    _GetSubformatIndexes!TablePrinter._GetSubformatIndexes  sC    D'')
++ioo
& ( Kr"   c                     SU R                   ;  aW  U R                  (       a  U R                  $ U R                  (       a)  U R                  U R                  R	                  5       5      $ g )N
no-heading)rc   _headingrm   r   Labelsr3   s    r    _GetVisibleLabelsTablePrinter._GetVisibleLabels&  sI    4??*	}}!!}}T33::<==r"   c                 -  >^=^> U R                   (       d  gU R                  (       a  SU l        U R                   H  nU R                    H4  nX!R                     nU(       d  M  UR
                  R                  USS9  M6     UR
                  R                  5         UR
                  R                  5       (       d  M  SU l        M     gSU R                  ;   nU(       d  SU R                  ;   a  U R                  R                  5       nSnO"SnU R                  R                  S[        5      nU R                   nU R                  (       Ga7  / n/ n	U R                  R                  5        H<  u  pU	(       d  UnWU:w  a  UR!                  S	X45        / n	UnU	R#                  U
5        M>     U	(       a  UR!                  S	U	W45        U H  u  pU(       a  [%        U5      n[%        U	5       Hc  n['        U5       VVs/ s H   u  p[)        X-   5      [+        X-   5      X4PM"     nnnUR-                  5         U VVs/ s H	  u      no"PM     nnnMe     U(       d  M  [%        U5      nM     U R                  R/                  5       nOSn[0        R2                  R4                  R6                  R9                  5       nU(       Ga  U R                  R                  S
5      nUb6  U R:                  R=                  U5        U R:                  R=                  S5        U R>                  (       a  Sn/ n['        U RA                  U R                  RC                  5       5      5       H6  u  nnURD                  RF                  (       d  UR#                  U5        M4  SnM8     U(       a  U(       d  SU l        gUU l$        U RK                  5       nU RM                  5       n['        U5       GHF  u  pU(       a  U R:                  R=                  S5        [O        [Q        U5      5       H  nU RH                  b  UU RH                  ;  a  M"  UU;   a  M*  [R        RT                  " [+        UU   5      5      nU(       aH  U[Q        U5      :  a9  UU   (       a/  U R:                  R=                  SRW                  UU   U5      5        OU R:                  R=                  U5        U R:                  R=                  S5        M     U R                  (       d  GM%  U R                   GH  nUR
                  (       d  M  UR
                  R                  X!R                     5        URX                  R[                  5       n['        UR]                  S5      SS 5       HF  u  nnU(       d  U R:                  R=                  S5        U R:                  R=                  US-   5        MH     URX                  R_                  S	5        URX                  Ra                  S	5        U R:                  R=                  S5        GM     GMI     / U l         [b        [d        U ]  5         gU VVs/ s H  o" Vs/ s H  n[+        U5      PM     snPM      nnnU Rf                  (       d  / U l         U RH                  (       a1  U Vs/ s H  o RA                  U5      PM     nnU RA                  U5      n/ nSU R                  ;  a  U Rh                  (       a  U Rh                  nO=U R                  (       a*  U RA                  U R                  Rk                  5       5      nOSnU(       a  U R                  (       an  / n U R                   HX  nUR
                  (       a  M  UR                  [Q        U5      :  d  M1  U R#                  [+        UUR                     5      5        MZ     U /nOU Vs/ s H  n[+        U5      PM     sn/nS	/[m        S UU-    5       5      -  n!U HC  n['        U5       H1  u  nn[m        U!U   U R                  Ro                  U5      5      U!U'   M3     ME     U R>                  (       a  Sn/ n['        U RA                  U R                  RC                  5       5      5       H@  u  nnURD                  RF                  (       a
  U!U   (       a  UR#                  U5        M>  SnMB     U(       av  U(       d  SU l        gUU l$        U Vs/ s H  o RA                  U5      PM     nnU RA                  U5      nU(       a  U RA                  US	   5      /O/ nU RA                  U!5      n!U(       aC  ['        US	   5       H1  u  nn[m        U!U   U R                  Ro                  U5      5      U!U'   M3     U R                  (       a  ['        U R                  RC                  5       5       H[  u  nnURD                  Rp                  (       d  M#  U!U   URD                  Rp                  :  d  MB  URD                  Rp                  U!U'   M]     0 n"['        U RA                  U R                  RC                  5       5      5       Hp  u  nnURD                  Rr                  (       d  M#  [u        URD                  Rr                  [v        5      (       a  [x        U"U'   MW  URD                  Rr                  U"U'   Mr     U"(       GaA  [Q        U RA                  U R                  RC                  5       5      5      n#U#S-
  U-  n$U(       a  [z        U#S-   -  U#U-  S-  -   n$U$U R                  R                  SS	5      -  n$U R                  R                  SU R                  R}                  5       S	   5      n%U%U$-
  n&U&[        U!5      :  a  [        ['        U!5       VV's/ s H  u  nn'UU";  d  M  U'PM     sn'n5      n(U&U(-
  n)['        U!5       H;  u  nn'UU";   d  M  [        U"U   U!U   5      n*[m        U)[Q        U"5      -  U*5      U!U'   M=     U R                  S::  a  U R                  R                  S
5      OSnUGb=  U(       a  UR                  nS	m>Sn+[O        [Q        U!5      5       H,  nT>U!U   -  m>U(       a  WUR                  U!U   U+-   -  -  nSn+M.     T>U R                  Ro                  U5      :  a  U"(       d  U R                  Ro                  U5      [Q        U!5      -   S-
  [Q        U!5      -  n,T>[Q        U!5      U,-  -  m>U(       a  WUR                  [Q        U!5      -  U,-  -  n[O        [Q        U!5      5       H  nU!U==   U,-  ss'   M     U(       a  T>S[Q        U!5      -  S-
  -  m>WUR                  -  nU R:                  R=                  U5        U R:                  R=                  S5        SRW                  UR                  [        U R                  U5      R                  T>5      UR                  5      nOGT>U[Q        U!5      S-
  -  -  m>[        U R                  U5      R                  T>5      R                  5       nU R:                  R=                  U5        U R:                  R=                  S5        U(       Ga   U(       a  UR                  OUR                  n-UR                  n.UR                  n/Sn0Sn1Sn2[O        [Q        U!5      5       HT  nUR                  U!U   S-   -  nU0U-U-   -  n0UR                  n-U1U.U-   -  n1UR                  n.U2U/U-   -  n2UR                  n/MV     U0U(       a  UR                  OUR                  -  n0U1UR                  -  n1U2UR                  -  n2U R:                  R=                  U05        U R:                  R=                  S5        U(       a  / nUS	   n/ n[O        [Q        U5      5       HC  nUR#                  UR                  5        UR#                  X.   R                  U!U   5      5        ME     UR#                  UR                  5        U R:                  R=                  SR                  U5      5        U R:                  R=                  S5        U R:                  R=                  U15        U R:                  R=                  S5        Sn3U=(       a[    U R                  =(       aH    [        U R                   Vs/ s H'  nUR                  (       + =(       a    UR
                  PM)     sn5      n4UU-    GHX  nU3(       a  Sn3OU(       a{  U4(       a7  U R:                  R=                  W05        U R:                  R=                  S5        O=U(       a6  U R:                  R=                  W15        U R:                  R=                  S5        Sn5U5(       a  M  S	n,Sn5[O        [Q        U5      5       GH  nU!U   m>U(       a(  U R:                  R=                  UR                  S-   5        U(       a  UU   OS m=X.   n6[u        U6[        R                  5      n7U R                  Ro                  U65      T>:  d  S[R        RT                  " U65      ;   a  U R                  [R        RT                  " U65      T>U7S9u  n8n9U7(       a[  [        R                  " U8U6R                  U6R                  5      n[        R                  " U9U6R                  U6R                  5      X.'   OU8nU9X.'   U9(       a  Sn5OU6nSX.'   U7(       as  U,(       a   U R:                  R=                  SU,-  5        S	n,UR                  U R:                  U=U>4S jS9  U(       a!  U R:                  R=                  SU-  5        GM  Un,GM  T=" [        U R                  U5      T>5      n:U(       a<  U R:                  R=                  U:5        U R:                  R=                  SU-  5        GM  U:R                  5       (       a  U,(       a   U R:                  R=                  SU,-  5        S	n,U:R                  5       n;U R:                  R=                  U;5        X`R                  Ro                  U:5      -   U R                  Ro                  U;5      -
  n,GM  U,X`R                  Ro                  U:5      -   -  n,GM     U(       a%  U R:                  R=                  UR                  5        U R                   (       Gab  U R:                  R=                  S5        U(       a  / nGMf  U5(       Ga2  U(       a6  U R:                  R=                  W25        U R:                  R=                  S5        U R                   R                  S	5      n<U R                   H  nUR
                  (       d  M  UR
                  R                  U<UR                     5        URX                  R[                  5       nUR]                  S5      SS  H$  nU R:                  R=                  SU-   S-   5        M&     URX                  R_                  S	5        URX                  Ra                  S	5        M     OU R:                  R=                  S5        U5(       d  GM  GM[     U(       a=  U4(       d6  U R:                  R=                  W25        U R:                  R=                  S5        [b        [d        U ]  5         gs  snnf s  snnf s  snf s  snnf s  snf s  snf s  snf s  sn'nf s  snf )zPrints the table.NT)intermediateFzall-boxboxr   padr   titlez


z{0}: {1}r   c              3   8   #    U  H  n[        U5      v   M     g 7fr9   )r1   ).0xs     r    	<genexpr>&TablePrinter.Finish.<locals>.<genexpr>  s     :>a3q66>s   r   marginr<      z	{0}{1}{2}r    c                 $    U R                  U5      $ r9   )r:   )r   ws     r    <lambda>%TablePrinter.Finish.<locals>.<lambda>r  s    
r"   )r   c                    > T" U T5      $ r9   rK   )r   justifyr<   s    r    r   r     s    WQ5Fr"   )r   z    )[ra   rl   _emptyrj   rP   rR   PrintFinishResourcesWerePrintedrc   rd   GetBoxLineCharactersget_TABLE_COLUMN_PADrm   Orderinsertrx   reversed	enumerater&   r!   sort
Alignmentsr   VALUESaccessibilityscreen_readerGetBoolrt   writeri   r   rn   ro   rq   ry   r   r   r   r1   r   r   formatrS   getvaluer   truncateseekrb   rX   rk   r   r   maxr0   r<   rU   r   bool
_MIN_WIDTH_BOX_CHAR_LENGTHGetTermSizesumminrh   drhdlvr(   rC   r   vrurhdvhhuvluljoinanyrQ   r   r   r   _color_justifyRenderstrippop)@r3   rp   r   r   all_boxr   table_column_padrT   groupskeys	key_indexkey_reversereversekeyi	decorated_alignr   r   rq   r   r~   labelsr   jcontentnested_outputklinecellheadingcells
col_widthsrU   visible_colstable_paddingtable_widthtotal_col_width	col_widthnon_wrappable_widthavailable_width	min_widthsepr   t_sepm_sepb_sept_rulem_ruleb_rulefirsthas_visible_subformatsrow_finishedr   is_colorizer
cell_value	remainderr   strippedr   r   r<   r   s@                                                                @@r    r   TablePrinter.Finish/  s   :: dk'')::C'&V##F#>  	  "1133$+ (  4??*G%4??*335cc,,U4EF ::D
 fd$($:$:$@$@$B
 )'k!
--D?
+$'I %C 
a$)!-$
 $$D>C%.t_6%461  ):ch+?H%4  6
..
*34),!Q3#)$4$	 "
 7$$ " $$//1ee %%33AAIIKMoo!!'*e						 
MM$0088:;=FAs''NN1H= DK!$-%%'f&&(d dO&!
))//$
s3xA]]&1DMM+A$YMM*SV"45'CKF1IIIOOJ--fQiABIIOOG$
))//$
 ! ++i   %%c//&:;'mm446m&}':':4'@"'EF'!T))//$'		t, G
 mm$$Q'mm  #iiood# ,# $< djL$&( ;??$3#.#$Z#.$D?  dj }},01DSmmC Dd1mmE"e G4??*	!!t55<<>?	%++i$$$3v;)Fll:fY__&=>? , G'39:64j&6:;'s:4'>:::JcN&!SJqM4+=+=+J+J3+OP
1 #  ~~hgdmmD,B,B,J,J,LMN&!S}}%%A
..
(	 O
 
$+
.23dsc"d3e$184==,-b]]:.
gaj)&!SJqM4+=+=+J+J3+OP
1 *d44<<>?&!S==:a=3==3F3F#F----*Q- @ DDMM$*@*@*H*H*JKL3				cmm(($//$q'MM&&$q' M t'='='E'E'GHIl#a'+;;m	q 01++a/0 	 t**8Q77mOO''(,(:(:(F(F(H(KMk#m3o	3z?	*!,5j,A#
,A.1i} ,A#
  *,??%j1LAy$YDGZ]3I3t9 <iHJqM 2 -1,<,<,ADOO(tE	vvecS_%!A
#%%:a=3./
/$	 &
 
##007	7""//6ZH1L:Z3&&
#%%#j/)C/
/$s:'A
Q-3
- (	S_$q((				!!EET''/66u=suuF 	!S_q%899**E299%@GGI
iiood
iiood cff366effeffefffS_%!uu
1)*%$,%$,%$, & %SVV+fff
iioof
iiood	ajs3xA
++cee

++cfmmJqM2
3 ! 	CEE		'						
 E  -T%5%5 -#**	,*Y 

49#4#4
4*	,;- ~	!
))//&
!
))//$

))//&
!
))//$
ls3xAQ-%IIOOCEECK( %E!H+B'f!#A|'='=>,  --a058cmmA&&$($A$Aa % %B %N!J	!++J!**Md#--i1::Ncf  d cf"lDCFiioocCi(cKK		+FKGiiooc$445$cHT%7%7>FEiiooe$iiooc$445		c	*hiiooh'"%7%7%D%DU%KK$$11(;<  %(:(:(G(G(NNNce !f 
))//#%%
 :::
))//$
Giioof%iiood#

q!A!--	"""!!'')//(:; ) 6 6 8)//5cr:D))//&4-$"67 ; &&q)""1% . ))//$
[  r #					,$&m
6 5V /? 2( ;, 4F#
j	,sV   9'A[
8A[

	A[A[#A[A[>A[ %A[%!A[*
2A[*
C.A[0[A[c                     U =R                   S-  sl         U R                  5         U R                  R                  S5        / U l        g)z)Flushes the current resource page output.r   r   N)rh   r   rt   r   ra   r   s    r    PageTablePrinter.Page  s3    KKMIIOODDJr"   )rl   rd   rg   r   rk   ri   rh   ra   rj   ry   rr   )T)F)rE   rF   rG   rH   rI   r6   r   r   r   r   r   r   r"  rJ   __classcell__)r   s   @r    rX   rX   q   s?    %N<0|	 7<0&dO'b r"   rX   )rI   
__future__r   r   r   ru   r   r   googlecloudsdk.corer   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer   r	   r
   r   	six.movesr   r   r   r   r!   r&   objectr(   rM   ResourcePrinterrX   rK   r"   r    <module>r,     s}    % &  ' 	  	 * 4 > A ; 
     
- 5v 54 *T	(88 T	r"   