U cf @sZddlmZddlmZmZddlmZmZmZm Z ddl m Z ddl m Z mZGdddZed krVdd lZdd lZejd d Zejd dddejdddedddeZddlmZeZeddZz(ejdkrejZ neej!Z WnFe"k r<Z#z&e$dejde#e%dW5d Z#[#XYnXej$ee ej&dddd S) )Path)loadsdumps)AnyCallableOptionalUnion)Text)JSONHighlighterNullHighlighterc @seZdZdZdeedeefeeeeeee e ge fedd ddZ e de edeefeeeeeee e ge fedd d d Z ed d dZdS)JSONa_A renderable which pretty prints JSON. Args: json (str): JSON encoded data. indent (Union[None, int, str], optional): Number of characters to indent by. Defaults to 2. highlight (bool, optional): Enable highlighting. Defaults to True. skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False. ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False. check_circular (bool, optional): Check for circular references. Defaults to True. allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True. default (Callable, optional): A callable that converts values that can not be encoded in to something that can be JSON encoded. Defaults to None. sort_keys (bool, optional): Sort dictionary keys. Defaults to False. TFN) jsonindent highlight skip_keys ensure_asciicheck_circular allow_nandefault sort_keysreturnc CsNt|} t| ||||||| d}|r*tnt} | ||_d|j_d|j_dS)NrskipkeysrrrrrT)rrr r textno_wrapoverflow) selfrrrrrrrrrdata highlighterr!C/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/rich/json.py__init__s   z JSON.__init__) rrrrrrrrrrc CsP||} t|||||||| d} |r,tnt} | | | _d| j_d| j_| S)a|Encodes a JSON object from arbitrary data. Args: data (Any): An object that may be encoded in to JSON indent (Union[None, int, str], optional): Number of characters to indent by. Defaults to 2. highlight (bool, optional): Enable highlighting. Defaults to True. default (Callable, optional): Optional callable which will be called for objects that cannot be serialized. Defaults to None. skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False. ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False. check_circular (bool, optional): Check for circular references. Defaults to True. allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True. default (Callable, optional): A callable that converts values that can not be encoded in to something that can be JSON encoded. Defaults to None. sort_keys (bool, optional): Sort dictionary keys. Defaults to False. Returns: JSON: New JSON object from the given data. rTN)__new__rr r rrr) clsrrrrrrrrrZ json_instancerr r!r!r" from_data5s    zJSON.from_data)rcCs|jS)N)r)rr!r!r"__rich__esz JSON.__rich__)rTFFTTNF)rTFFTTNF)__name__ __module__ __qualname____doc__strrintboolrrrr# classmethodr&r r'r!r!r!r"r sV   /r __main__NzPretty print json) descriptionpathPATHzpath to file, or - for stdin)metavarhelpz-iz--indentZSPACESzNumber of spaces in an indentr)r4typer5r)ConsoleT)stderr-zUnable to read z; )r) soft_wrap)'pathlibrrrrtypingrrrrrr r r r r r(argparsesysArgumentParserparser add_argumentr- parse_argsargspip._vendor.rich.consoler7consoleZ error_consoler2stdinreadZ json_data read_text Exceptionerrorprintexitrr!r!r!r"sD  `