o
    o                     @   sZ   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 dej	Z
dS )	zJSON format resource printer.    )absolute_import)division)unicode_literalsN)resource_printer_basec                       sB   e Zd ZdZdZ fddZdd Zddd	Z fd
dZ  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                    s8   t t| j|ddi| d| _| j| _dtj | _d S )Nretain_none_valuesT )	superr   __init___empty_BEGIN_DELIMITER
_delimiterr   STRUCTURED_INDENTATION_indent)selfargskwargs	__class__ F/tmp/google-cloud-sdk/lib/googlecloudsdk/core/resource/json_printer.pyr
   4   s   zJsonPrinter.__init__c                 C   s    t j|dtjddd}t|S )NF),z: T)ensure_asciiindent
separators	sort_keys)jsondumpsr   r   six	text_type)r   resourcedatar   r   r   __Dump:   s   
zJsonPrinter.__DumpTc                 C   s   d| _ | |}|r*| j| j }d| _|dD ]}| j||  d| j }qdS | j| jkr:| jd | j| _| j| | jd dS )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liner   r   r   
_AddRecordH   s   	
zJsonPrinter._AddRecordc                    sF   | j r
| jd n| j| jkr| jd | j| _tt|   dS )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   r   r   r/   `   s   zJsonPrinter.Finish)T)
__name__
__module____qualname____doc__r   r
   r%   r.   r/   __classcell__r   r   r   r   r      s    
r   )r3   
__future__r   r   r   r   googlecloudsdk.core.resourcer   r   ResourcePrinterr   r   r   r   r   <module>   s   