
    o                     r    d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlZ G d dej                        Z
y)	zJSON format resource printer.    )absolute_import)division)unicode_literalsN)resource_printer_basec                   >     e Zd ZdZdZ fdZd ZddZ fdZ xZ	S )JsonPrintera  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                     t        t        | 
  |ddi| d| _        | j                  | _        dt        j                  z  | _        y )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   zJsonPrinter.__init__4   sC    	+t%tOOODK++DO.EEEDL    c                 |    t        j                  |dt        j                  dd      }t	        j
                  |      S )NF),z: T)ensure_asciiindent
separators	sort_keys)jsondumpsr   r   six	text_type)r   resourcedatas      r   __DumpzJsonPrinter.__Dump:   s6    ::$;;D ==r   c                    d| _         | j                  |      }|rd| j                  | j                  z   }d| _        |j	                  d      D ]/  }| j
                  j                  ||z          d| j                  z   }1 y| j                  | j                  k7  r,| j
                  j                  d       | j                  | _        | j
                  j                  |       | j
                  j                  d       y)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   
_AddRecordzJsonPrinter._AddRecordH   s     DK[[ F//DLL0ido,,t$$			D()4<<'	 % 
D11	1		 //
iioof
iioodr   c                    | j                   r| j                  j                  d       nE| j                  | j                  k7  r,| j                  j                  d       | j                  | _        t
        t        |           y)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   r4   zJsonPrinter.Finish`   sV    {{
iioof	D11	1
iioog--do	+t#%r   )T)
__name__
__module____qualname____doc__r   r   r)   r2   r4   __classcell__)r   s   @r   r   r      s*    ( F0& &r   r   )r8   
__future__r   r   r   r   googlecloudsdk.core.resourcer   r!   ResourcePrinterr    r   r   <module>r>      s1     $ &  '  > 
K&'77 K&r   