
                             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Jr  SSKJ	r	  SSK
r
 " S	 S
\R                  5      r " S S\5      r " S S\5      rg)zCSV resource printer.    )absolute_import)division)unicode_literals)resource_printer_base)resource_transform)encodingNc                   <   ^  \ rS rSrSrU 4S jrS rSS jrSrU =r	$ )
CsvPrinter   a  A printer for printing CSV data.

[Comma Separated Values](http://www.rfc-editor.org/rfc/rfc4180.txt) with no
keys. This format requires a projection to define the values to be printed.

To use *\n* or *\t* as an attribute value please escape the *\* with your
shell's escape sequence, example *separator="\\n"* for bash.

Printer attributes:
  delimiter="string": The string printed between list value items,
    default ";".
  no-heading: Disables the initial key name heading record.
  separator="string": The string printed between values, default ",".
  terminator="string": The string printed after each record, default
    "\n" (newline).
c                 \  > [         [        U ]
  " USSS.UD6  SU l        U R                  R                  SS5      U l        U R                  R                  SS5      (       a  S OSU l        U R                  R                  S	S
5      U l        U R                  R                  SS5      U l	        g )NT)
by_columnsnon_empty_projection_requiredF	delimiter;zno-quoter   "	separator,
terminator
)
superr
   __init___heading_printed
attributesget
_delimiter_quote
_separator_terminatorselfargskwargs	__class__s      /lib/googlecloudsdk/core/resource/csv_printer.pyr   CsvPrinter.__init__/   s    	*d$dtCG/'-/ "Doo))+s;DO//--j!<<$#DKoo))+s;DO**<>D    c                    U(       a  U R                   (       d  U$ U R                  U;   db  U R                   U;   dR  U R                  U;   dB  U R                  U;   d2  US   R	                  5       (       d  US   R	                  5       (       d  U$ U R                   UR                  U R                   U R                   S-  5      -   U R                   -   $ )zReturns field quoted by self._quote if necessary.

The Python 2.7 csv module does not support unicode "yet". What are they
waiting for?

Args:
  field: The unicode string to quote.

Returns:
  field quoted by self._quote if necessary.
r      )r   r   r   r   isspacereplace)r    fields     r$   _QuoteFieldCsvPrinter._QuoteField9   s     lOOu$KK5 OOu$%!H%)"3"3"5"5lKKMM$++t{{Q78KK r&   c                    U R                   (       d  SU l         SU R                  ;  a  U R                  (       a  U R                  nOOU R                  R	                  5       nU(       a.  U R                  U5       Vs/ s H  oDR                  5       PM     nnU(       ap  U R                  R                  U R                  R                  U R                  U5       Vs/ s H  nU R                  U5      PM     sn5      U R                  -   5        / nU R                  U5       GH  nUc  SnGOw[        U[        5      (       a  U R                  R                  [!        ["        R$                  " U5      5       V	V
s/ s HN  u  pU R                  SR'                  [(        R*                  " U	5      [(        R*                  " U
5      5      5      PMP     sn
n	5      nO[        U[,        5      (       aX  U R                  R                  U Vs/ s H0  oD(       a%  U R                  [(        R*                  " U5      5      OSPM2     sn5      nO`[        U[.        5      (       a&  U R                  [0        R2                  " U5      5      nO%U R                  [(        R*                  " U5      5      nUR5                  U5        GM     U R                  R                  U R                  R                  U5      U R                  -   5        gs  snf s  snf s  sn
n	f s  snf )a$  Prints the current record as CSV.

Printer attributes:
  noheading: bool, Disable the initial key name heading record.

Args:
  record: A list of JSON-serializable object columns.
  delimit: bool, Print resource delimiters -- ignored.

Raises:
  ToolException: A data value has a type error.
Tz
no-headingN z{0}={1})r   r   _headingcolumn_attributesLabelsRemoveHiddenColumnslower_outwriter   joinr-   r   
isinstancedictr   sortedsix	iteritemsformatr   Decodelistfloatr   TransformFloatappend)r    recorddelimitlabelsxlabellinecolvalkvs              r$   
_AddRecordCsvPrinter._AddRecordQ   sW   "   "d	T__	,====&))002&)-)A)A&)IJ)IAggi)IFJ
))//oo""#77?$?e ""5)?$  ##$%
 D''/	c4  oo""  c 2353 i.."HOOA$68 9356 c4  oo""HKL1QThooa01B>LNc5!!1@@EFxs34
kk# 0  	IIOODOO((.1A1AAB1 K$5
 Ms   ;K:K?7AL7L

r   r   r   r   r   )F)
__name__
__module____qualname____firstlineno____doc__r   r-   rN   __static_attributes____classcell__r#   s   @r$   r
   r
      s    "?01C 1Cr&   r
   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )ValuePrinter   a  A printer for printing value data.

CSV with no heading and <TAB> separator instead of <COMMA>. Used to retrieve
individual resource values. This format requires a projection to define the
value(s) to be printed.

To use *\n* or *\t* as an attribute value please escape the *\* with your
shell's escape sequence, example *separator="\\n"* for bash.

Printer attributes:
  delimiter="string": The string printed between list value items,
    default ";".
  quote: "..." quote values that contain delimiter, separator or terminator
    strings.
  separator="string": The string printed between values, default
    "\t" (tab).
  terminator="string": The string printed after each record, default
    "\n" (newline).
c                 V  > [         [        U ]
  " U0 UD6  SU l        U R                  R                  SS5      U l        U R                  R                  SS5      (       a  SOS U l        U R                  R                  SS5      U l        U R                  R                  S	S
5      U l	        g )NTr   r   quoter   r   r   	r   r   )
r   rZ   r   r   r   r   r   r   r   r   r   s      r$   r   ValuePrinter.__init__   s    	,&77 Doo))+s;DO,,Wa88#dDKoo))+t<DO**<>Dr&   rP   rQ   rR   rS   rT   rU   r   rV   rW   rX   s   @r$   rZ   rZ      s    (? ?r&   rZ   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )
GetPrinter   zA printer for printing value data with transforms disabled.

Equivalent to the *value[no-transforms]* format. Default transforms are
not applied to the displayed values.
c                 2   > [         [        U ]
  " USS0UD6  g )Nignore_default_transformsT)r   rb   r   r   s      r$   r   GetPrinter.__init__   s#    	*d$d /d /'-/r&    r`   rX   s   @r$   rb   rb      s    / /r&   rb   )rU   
__future__r   r   r   googlecloudsdk.core.resourcer   r   googlecloudsdk.core.utilr   r<   ResourcePrinterr
   rZ   rb   rg   r&   r$   <module>rl      sO      &  ' > ; - 
eC&66 eCP?: ?<	/ 	/r&   