
    o                     r    S 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r " S S\R                  5      r
g)	zJSON format resource printer.    )absolute_import)division)unicode_literalsN)resource_printer_basec                   L   ^  \ rS rSrSrSrU 4S jrS rS	S jrU 4S jr	Sr
U =r$ )
JsonPrinter   a  Prints resource records as a JSON list.

[JSON](http://www.json.org), JavaScript Object Notation.

Printer attributes:
  no-undefined: Does not display resource data items with null values.

Attributes:
  _buffer: Buffer stream for record item indentation.
  _delimiter: Delimiter string before the next record.
  _empty: True if no records were output.
  _indent: Resource item indentation.
z[
c                    > [         [        U ]
  " USS0UD6  SU l        U R                  U l        S[        R                  -  U l        g )Nretain_none_valuesT )	superr   __init___empty_BEGIN_DELIMITER
_delimiterr   STRUCTURED_INDENTATION_indent)selfargskwargs	__class__s      0lib/googlecloudsdk/core/resource/json_printer.pyr   JsonPrinter.__init__4   sC    	+t%tOOODK++DO.EEEDL    c                 z    [         R                  " US[        R                  SSS9n[        R
                  " U5      $ )NF),z: T)ensure_asciiindent
separators	sort_keys)jsondumpsr   r   six	text_type)r   resourcedatas      r   __DumpJsonPrinter.__Dump:   s6    ::$;;D ==r   c                    SU l         U R                  U5      nU(       ae  U R                  U R                  -   nSU l        UR	                  S5       H/  nU R
                  R                  XE-   5        SU R                  -   nM1     gU R                  U R                  :w  a,  U R
                  R                  S5        U R                  U l        U R
                  R                  U5        U R
                  R                  S5        g)zPrints one element of a JSON-serializable Python object resource list.

Allows intermingled delimit=True and delimit=False.

Args:
  record: A JSON-serializable object.
  delimit: Dump one record if False, used by PrintSingleRecord().
Fz,


]
N)r   _JsonPrinter__Dumpr   r   split_outwriter   )r   recorddelimitoutput	delimiterlines         r   
_AddRecordJsonPrinter._AddRecordH   s     DK[[ F//DLL0ido,,t$$			()4<<'	 % 
D11	1		 //
iioof
iioodr   c                   > U R                   (       a  U R                  R                  S5        OFU R                  U R                  :w  a,  U R                  R                  S5        U R                  U l        [
        [        U ]  5         g)z@Prints the final delimiter and preps for the next resource list.z[]
r+   N)r   r.   r/   r   r   r   r   Finish)r   r   s    r   r8   JsonPrinter.Finish`   sV    {{
iioof	D11	1
iioog--do	+t#%r   )r   r   r   )T)__name__
__module____qualname____firstlineno____doc__r   r   r,   r5   r8   __static_attributes____classcell__)r   s   @r   r   r      s*    ( F0& &r   r   )r>   
__future__r   r   r   r!   googlecloudsdk.core.resourcer   r#   ResourcePrinterr    r   r   <module>rE      s1     $ &  '  > 
K&'77 K&r   