
    -PhI                         d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZ  G d de          Z e            Zd Zd	Zed
z   Zd ZddZddZddZddZddZddZd ZdS )    N)Path)validate_coerce_fig_to_dictvalidate_coerce_output_type)
get_module)ImageUriValidatorc                   d    e Zd ZdZd Zed             Zej        d             Zed             Z	dS )
JsonConfig)jsonorjsonautoc                     d| _         d S )Nr   _default_engineselfs    O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/plotly/io/_json.py__init__zJsonConfig.__init__   s    %    c                     | j         S Nr   r   s    r   default_enginezJsonConfig.default_engine   s    ##r   c                     |t           j        vr.t          d                    t           j        |                    |dk    r|                                  || _        d S )Nz9Supported JSON engines include {valid}
    Received {val})validvalr   )r	   _valid_engines
ValueErrorformatvalidate_orjsonr   )r   r   s     r   r   zJsonConfig.default_engine   sg    j///%%+V*2KQTV%U%U  
 (??  """"r   c                 F    t          d          }|t          d          d S )Nr   z-The orjson engine requires the orjson package)r   r   )clsr   s     r   r   zJsonConfig.validate_orjson%   s*    H%%>LMMM >r   N)
__name__
__module____qualname__r   r   propertyr   setterclassmethodr    r   r   r	   r	      s        /N& & & $ $ X$ 
# 
# 
# N N [N N Nr   r	   c                     | dv rdS | S )zM
    This is used to ultimately *encode* into strict JSON, see `encode`

    )Infinityz	-InfinityNaNNr'   )consts    r   coerce_to_strictr,   /   s     000tr   ))<z\u003c)>z\u003e)/z\u002f))u    z\u2028)u    z\u2029c                 N    | }|D ]\  }}||v r|                     ||          } |S r   )replace)json_str_swapoutunsafe_char	safe_chars        r   _safer7   F   s?    
C"' 6 6Y#++k955CJr   Fc                    t          dd          }|t          j        }|dk    r|d}nd}n|dvrt          d|z            t          d	d
          t          dd
          t          dd
          t          dd
          d}|dk    r<i }|rd|d<   nd|d<   ddlm} t          t          j        | fd|i|t                    S |dk    rt                                           |j        |j        z  }|r
||j        z  }	 |                                 } n# t           $ r Y nw xY w	 t          |                    | |                              d          t$                    S # t&          $ r Y nw xY wt)          | dd|          }t          |                    ||                              d          t$                    S dS )a  
    Convert a plotly/Dash object to a JSON string representation

    Parameters
    ----------
    plotly_object:
        A plotly/Dash object represented as a dict, graph_object, or Dash component

    pretty: bool (default False)
        True if JSON representation should be pretty-printed, False if
        representation should be as compact as possible.

    engine: str (default None)
        The JSON encoding engine to use. One of:
          - "json" for an engine based on the built-in Python json module
          - "orjson" for a faster engine that requires the orjson package
          - "auto" for the "orjson" engine if available, otherwise "json"
        If not specified, the default engine is set to the current value of
        plotly.io.json.config.default_engine.

    Returns
    -------
    str
        Representation of input object as a JSON string

    See Also
    --------
    to_json : Convert a plotly Figure to JSON with validation
    r   Tshould_loadNr   r
   r   r
   Invalid json engine: %szsage.allFnumpypandasz	PIL.Image)sage_allnppdimage   indent),:
separatorsr   )PlotlyJSONEncoderr    )optionutf8)numpy_alloweddatetime_allowedmodules)r   configr   r   _plotly_utils.utilsrH   r7   r
   dumps
_swap_jsonr	   r   OPT_NON_STR_KEYSOPT_SERIALIZE_NUMPYOPT_INDENT_2to_plotly_jsonAttributeErrordecode_swap_orjson	TypeErrorclean_to_json_compatible)plotly_objectprettyenginer   rM   optsrH   cleaneds           r   to_json_plotlyr`   N   sV   < d333F ~&FFFF	)	)	)2V;<<< zu===e444u555KU;;;	 G  	,DNN ",D999999J}DD*;DtDDj
 
 	
 
8		""$$$&)CC 	(F''D	)88::MM 	 	 	D		]488??GG    	 	 	D	 +!	
 
 
 V\\'$\77>>vFFUUU7 
	s$   D 
D&%D&*<E' '
E43E4Tc                     t          | |          }|r/|                    dg           D ]}|                    dd           t          |||          S )a  
    Convert a figure to a JSON string representation

    Parameters
    ----------
    fig:
        Figure object or dict representing a figure

    validate: bool (default True)
        True if the figure should be validated before being converted to
        JSON, False otherwise.

    pretty: bool (default False)
        True if JSON representation should be pretty-printed, False if
        representation should be as compact as possible.

    remove_uids: bool (default True)
        True if trace UIDs should be omitted from the JSON representation

    engine: str (default None)
        The JSON encoding engine to use. One of:
          - "json" for an engine based on the built-in Python json module
          - "orjson" for a faster engine that requires the orjson package
          - "auto" for the "orjson" engine if available, otherwise "json"
        If not specified, the default engine is set to the current value of
        plotly.io.json.config.default_engine.

    Returns
    -------
    str
        Representation of figure as a JSON string

    See Also
    --------
    to_json_plotly : Convert an arbitrary plotly graph_object or Dash component to JSON
    datauidN)r\   r]   )r   getpopr`   )figvalidater\   remove_uidsr]   fig_dicttraces          r   to_jsonrk      sg    N +399H  #\\&"-- 	# 	#EIIeT""""(6&AAAAr   c                 p   t          | ||||          }t          |t                    rt          |          }nt          |t                    r|}nd}|K	 |                    |           dS # t
          $ r Y nw xY wt          d                    |                    |                    |           dS )a+  
    Convert a figure to JSON and write it to a file or writeable
    object

    Parameters
    ----------
    fig:
        Figure object or dict representing a figure

    file: str or writeable
        A string representing a local file path or a writeable object
        (e.g. a pathlib.Path object or an open file descriptor)

    pretty: bool (default False)
        True if JSON representation should be pretty-printed, False if
        representation should be as compact as possible.

    remove_uids: bool (default True)
        True if trace UIDs should be omitted from the JSON representation

    engine: str (default None)
        The JSON encoding engine to use. One of:
          - "json" for an engine based on the built-in Python json module
          - "orjson" for a faster engine that requires the orjson package
          - "auto" for the "orjson" engine if available, otherwise "json"
        If not specified, the default engine is set to the current value of
        plotly.io.json.config.default_engine.
    Returns
    -------
    None
    )rg   r\   rh   r]   NzX
The 'file' argument '{file}' is not a string, pathlib.Path object, or file descriptor.
)file)	rk   
isinstancestrr   writerV   r   r   
write_text)rf   rm   rg   r\   rh   r]   r2   paths           r   
write_jsonrs      s    H hv;v  H $ 	Dzz	D$		   |	JJx   F 	 	 	D	
F   
 
 	
 	!!!!!s   A. .
A;:A;c                    t          dd          }t          | t          t          f          s1t	          d                    t          |           |                     |t          j        }|dk    r|d}nd}n|d	vrt	          d
|z            |dk    r/t          
                                 |                    |           }n>t          | t                    r|                     d          } t          j        |           }|S )a  
    Parse JSON string using the specified JSON engine

    Parameters
    ----------
    value: str or bytes
        A JSON string or bytes object

    engine: str (default None)
        The JSON decoding engine to use. One of:
          - if "json", parse JSON using built in json module
          - if "orjson", parse using the faster orjson module, requires the orjson
            package
          - if "auto" use orjson module if available, otherwise use the json module

        If not specified, the default engine is set to the current value of
        plotly.io.json.config.default_engine.

    Returns
    -------
    dict

    See Also
    --------
    from_json_plotly : Parse JSON with plotly conventions into a dict
    r   Tr9   zr
from_json_plotly requires a string or bytes argument but received value of type {typ}
    Received value: {value})typvalueNr   r
   r;   r<   zutf-8)r   rn   ro   bytesr   r   typerN   r   r	   r   loadsrW   r
   )rv   r]   r   
value_dicts       r   from_json_plotlyr{   ,  s   6 d333F ec5\** 
%vKKu  &    
 
 	
 ~&FFFF	)	)	)2V;<<<""$$$\\%((

 eU## 	*LL))EZ&&
r   Figurec                 `    t          | |          }t          |          } |||          }|S )a  
    Construct a figure from a JSON string

    Parameters
    ----------
    value: str or bytes
        String or bytes object containing the JSON representation of a figure

    output_type: type or str (default 'Figure')
        The output figure type or type name.
        One of:  graph_objs.Figure, 'Figure', graph_objs.FigureWidget, 'FigureWidget'

    skip_invalid: bool (default False)
        False if invalid figure properties should result in an exception.
        True if invalid figure properties should be silently ignored.

    engine: str (default None)
        The JSON decoding engine to use. One of:
          - if "json", parse JSON using built in json module
          - if "orjson", parse using the faster orjson module, requires the orjson
            package
          - if "auto" use orjson module if available, otherwise use the json module

        If not specified, the default engine is set to the current value of
        plotly.io.json.config.default_engine.

    Raises
    ------
    ValueError
        if value is not a string, or if skip_invalid=False and value contains
        invalid figure properties

    Returns
    -------
    Figure or FigureWidget
    )r]   )skip_invalid)r{   r   )rv   output_typer~   r]   ri   r    rf   s          r   	from_jsonr   m  sA    P  f555H &k
2
2C #h\
2
2
2CJr   c                 &   t          | t                    }t          | t                    rt          |           }nt          | t                    r| }nd}||                                }n|                                 }t          ||||          S )a  
    Construct a figure from the JSON contents of a local file or readable
    Python object

    Parameters
    ----------
    file: str or readable
       A string containing the path to a local file or a read-able Python
       object (e.g. a pathlib.Path object or an open file descriptor)

    output_type: type or str (default 'Figure')
        The output figure type or type name.
        One of:  graph_objs.Figure, 'Figure', graph_objs.FigureWidget, 'FigureWidget'

    skip_invalid: bool (default False)
        False if invalid figure properties should result in an exception.
        True if invalid figure properties should be silently ignored.

    engine: str (default None)
        The JSON decoding engine to use. One of:
          - if "json", parse JSON using built in json module
          - if "orjson", parse using the faster orjson module, requires the orjson
            package
          - if "auto" use orjson module if available, otherwise use the json module

        If not specified, the default engine is set to the current value of
        plotly.io.json.config.default_engine.

    Returns
    -------
    Figure or FigureWidget
    N)r~   r   r]   )rn   ro   r   	read_textreadr   )rm   r   r~   r]   file_is_strrr   r2   s          r   	read_jsonr     s    J T3''K$ 	Dzz	D$		   >>##99;; |V   r   c                 
   t          | t          t          t          f          r| S t          | t                    r fd|                                 D             S t          | t          t          f          r| rfd| D             S                     dd          }                    dd          }                    di           }|d         }|d         }|d	         }|d
         }|0| |j	        v rt          |           S | |j
        v rt          |           S | | |j        j        j        u rt          d          S t          | |j                  r|r#| j        j        dv r|                    |           S | j        j        dk    r'|                    |                                           S | j        j        dk    r|                                 S | j        j        dk    r|                                 } n$t          | |j                  rt          |           S |j| |j        u s	| |j        u rd S t          | |j        |j        f          r9|r(| j        j        dv r|                    | j                  S | j        j        dk    rt          | |j                  rt5          j                    5  t5          j        dt:                     |                    | j                                                                                   }	d d d            n# 1 swxY w Y   n&|                                                                  }	|s<tC          tE          |	                    D ]}
|	|
         #                                |	|
<    |	S 	 |                                  } n# tH          tJ          f$ r Y nw xY w|s,	 | #                                S # tH          tJ          f$ r Y n w xY wt          | tL          j&                  r| S 	 |                                 S # tJ          $ r Y nw xY wt          | tN          j(                  rt          |           S |)t          | |j)                  rtU          j+        |           S 	 | ,                                } n# tJ          $ r Y nw xY wt          | t                    r fd|                                 D             S t          | t          t          f          r| rfd| D             S | S )Nc                 2    i | ]\  }}|t          |fi S r'   rZ   .0kvkwargss      r   
<dictcomp>z,clean_to_json_compatible.<locals>.<dictcomp>  0    QQQTQ+A8888QQQr   c                 *    g | ]}t          |fi S r'   r   r   r   r   s     r   
<listcomp>z,clean_to_json_compatible.<locals>.<listcomp>  *    GGGa,Q99&99GGGr   rK   FrL   rM   r?   r@   rA   rB   nan)biufMUOignorec                 2    i | ]\  }}|t          |fi S r'   r   r   s      r   r   z,clean_to_json_compatible.<locals>.<dictcomp>R  r   r   c                 *    g | ]}t          |fi S r'   r   r   s     r   r   z,clean_to_json_compatible.<locals>.<listcomp>V  r   r   )-rn   intfloatro   dictitemslisttuplerd   RRZZmacoremaskedndarraydtypekindascontiguousarraydatetime_as_stringtolist
datetime64NaTNASeriesDatetimeIndexvalueswarningscatch_warningssimplefilterFutureWarningarraydtto_pydatetimerangelen	isoformatrY   rV   datetimedecimalDecimalImager   pil_image_to_urirU   )objr   rK   rL   rM   r?   r@   rA   rB   	dt_valuesr   s    `         r   rZ   rZ     s   
 #UC()) 
#t HQQQQSYY[[QQQQ	C$	'	' H 	HGGGG3GGGG JJ66Mzz"4e<<jjB''Gz"H	B	BGE (+::HKs88O 
~"%*###<<RZ(( 	 	#3G!G!G++C0003&&,,S1188:::3&&zz||#3&&jjllR]++ 	s88O 
~"&==C25LL4bi)9:;; 	! !3G!G!G++CJ7773&&c29-- =!022 N N -hFFF %'HHSV-A-A-C-C$D$D$K$K$M$M		N N N N N N N N N N N N N N N !$ 1 1 3 3 : : < <I' @ #3y>>22 @ @'0|'='='?'?	!   !!~&     	==??">* 	 	 	D		C*	+	+ 
zz||    #w'' Szz ZU[99 1#666  ""    #t HQQQQSYY[[QQQQ	C$	'	' H 	HGGGG3GGGGJs[   4ALL LN! !N54N5;O O#"O#P 
P$#P$<R 
RR)FN)TFTNr   )r|   FN)r
   r   r   r   pathlibr   plotly.io._utilsr   r   _plotly_utils.optional_importsr   _plotly_utils.basevalidatorsr   objectr	   rN   r,   rQ   rX   r7   r`   rk   rs   r{   r   r   rZ   r'   r   r   <module>r      s             U U U U U U U U 5 5 5 5 5 5 : : : : : :
N N N N N N N N< 
	 	 	

     ]V ]V ]V ]V@/B /B /B /BdI" I" I" I"X> > > >B1 1 1 1h< < < <~x x x x xr   