o
    ^i                     @   s   d Z ddlZddlZddlZddlmZ ddlmZ dd ejD Z	dddZ
G d	d
 d
ejZdd Zedkr@ee
  dS dS )zA tool to parse and pretty-print JSON5.

Usage:

    $ echo '{foo:"bar"}' | python -m json5
    {
        foo: 'bar',
    }
    $ echo '{foo:"bar"}' | python -m json5 --as-json
    {
        "foo": "bar"
    }
    N)Host)__version__c                 C   s   i | ]}|j |qS  )value).0qr   r   E/home/ubuntu/hpml_nyu/venv/lib/python3.10/site-packages/json5/tool.py
<dictcomp>$   s    r	   c                 C   s   |pt  }t|| }|jr|t dS |jr|j}n|jdkr&|j }n|	|j}|j
dkr5d |_
nzt|j
|_
W n	 tyF   Y nw |jrVd|_d|_tjjj|_tj||jd}tj||j
|j|jt|j d}|| dS )Nr   -NoneTF)strict)indent
quote_keystrailing_commasquote_style)r   _parse_argsversionprintr   cmdfilestdinreadread_text_filer   int
ValueErroras_jsonr   r   json5
QuoteStyleALWAYS_DOUBLEr   r   loadsr   dumpsQUOTE_STYLES)argvhostargsinpobjsr   r   r   main'   s>   





r(   c                       s<   e Zd ZdZ fddZdddZdd	 Zdd
dZ  ZS )_HostedArgumentParserz5An argument parser that plays nicely w/ host objects.c                    s   || _ t jdi | d S )Nr   )r#   super__init__)selfr#   kwargs	__class__r   r   r+   S   s   z_HostedArgumentParser.__init__r   Nc                 C   s"   |r
|  || jj t| d S N)_print_messager#   stderrsysexit)r,   statusmessager   r   r   r4   W   s   z_HostedArgumentParser.exitc                 C   sJ   | j jd| j d| j jd | j jd| j jd | dd| d d S )	Nzusage:  )endr   z    -h/--help for help
r      zerror: 
)r#   r   usager2   r4   )r,   r6   r   r   r   error\   s   z_HostedArgumentParser.errorc                 C   s   | j j|  |d d S )Nr9   )r#   r   format_help)r,   r   r   r   r   
print_helpa   s   z _HostedArgumentParser.print_help)r   Nr0   )	__name__
__module____qualname____doc__r+   r4   r=   r?   __classcell__r   r   r.   r   r)   P   s    
r)   c                 C   s  d}t | d|ttjd}|jddddt dd	 |jd
dddd |jddddddd |jddddd |jddddd |jddd d!d" |jd#ddd$d |jd%d&dd'd( |jd)ddd*d |jd+d,dd-d( |jd.d/d0t d1d2 |jd3d4d5d6d7d8 ||S )9Nzjson5 [options] [FILE]
r   )progr<   descriptionformatter_classz-Vz	--version
store_truezshow JSON5 library version ())actionhelpz-cSTRr   z:inline json5 string to read instead of reading from a file)metavardestrK   z	--as-jsonr   store_constTFz:output as JSON (same as --quote-keys --no-trailing-commas))rN   rJ   constdefaultrK   z--indentr      z0amount to indent each line (default is 4 spaces))rN   rQ   rK   z--quote-keyszquote all object keys)rJ   rQ   rK   z--no-quote-keysstore_falser   zBdon't quote object keys that are identifiers (this is the default))rJ   rN   rK   z--trailing-commaszUadd commas after the last item in multi-line objects and arrays (this is the default)z--no-trailing-commasr   zEdo not add commas after the last item in multi-line lists and objects)rN   rJ   rK   z--strictz@Do not allow control characters (\x00-\x1f) in strings (default)z--no-strictr   z/Allow control characters (\x00-\x1f) in stringsz--quote-stylestorealways_doublez\Controls how strings are encoded. By default they are always double-quoted ("always_double"))rJ   rQ   choicesrK   r   FILE?r
   z`optional file to read JSON5 document from; if not specified or "-", will read from stdin instead)rM   nargsrQ   rK   )	r)   rC   argparseRawDescriptionHelpFormatteradd_argumentr   r!   keys
parse_args)r#   r"   r<   parserr   r   r   r   e   s   

	r   __main__)NN)rC   rZ   r3   r   
json5.hostr   json5.versionr   r   r!   r(   ArgumentParserr)   r   r@   r4   r   r   r   r   <module>   s   
)`