B
    !²ô`Þ	  ã               @   sV   d Z ddlmZ ddlmZ ddlmZ ddlZddlZedƒZedƒZ	dd	d
„Z
dS )a»  A module providing a function for serializing JSON values with Infinity.

Python provides no way to override how json.dumps serializes
Infinity/-Infinity/NaN; if allow_nan is true, it encodes them as
Infinity/-Infinity/NaN, in violation of the JSON spec and in violation
of what JSON.parse accepts. If it's false, it throws a ValueError,
Neither subclassing JSONEncoder nor passing a function in the |default|
keyword argument overrides this.
é    )Úabsolute_import)Údivision)Úprint_functionNÚinfz-infúutf-8c                sÆ   t | tƒr| S t | tƒrD| tkr$dS | tkr0dS t | ¡r>dS | S n~t | tƒrX|  ˆ ¡S t | t	t
fƒrx‡ fdd„| D ƒS t | tƒr˜‡ fdd„t| ƒD ƒS t | tƒr¾t ‡ fdd„|  ¡ D ƒ¡S | S d	S )
aƒ  Makes Python object appropriate for JSON serialization.

    - Replaces instances of Infinity/-Infinity/NaN with strings.
    - Turns byte strings into unicode strings.
    - Turns sets into sorted lists.
    - Turns tuples into lists.

    Args:
      obj: Python data structure.
      encoding: Charset used to decode byte strings.

    Returns:
      Unicode JSON data structure.
    ÚInfinityz	-InfinityÚNaNc                s   g | ]}t |ˆ ƒ‘qS © )ÚCleanse)Ú.0Úi)Úencodingr	   úL/home/dcms/DCMS/lib/python3.7/site-packages/tensorboard/backend/json_util.pyú
<listcomp>C   s    zCleanse.<locals>.<listcomp>c                s   g | ]}t |ˆ ƒ‘qS r	   )r
   )r   r   )r   r	   r   r   E   s    c             3   s&   | ]\}}t |ˆ ƒt |ˆ ƒfV  qd S )N)r
   )r   ÚkÚv)r   r	   r   ú	<genexpr>H   s    zCleanse.<locals>.<genexpr>N)Ú
isinstanceÚintÚfloatÚ	_INFINITYÚ_NEGATIVE_INFINITYÚmathÚisnanÚbytesÚdecodeÚlistÚtupleÚsetÚsortedÚdictÚcollectionsÚOrderedDictÚitems)Úobjr   r	   )r   r   r
   &   s(    






r
   )r   )Ú__doc__Ú
__future__r   r   r   r!   r   r   r   r   r
   r	   r	   r	   r   Ú<module>   s   