+L iIddlZddlZddlZddlZddlmZddlmZmZddl m Z ddl m Z Gdde ZeZdZd Zed zZd Zdd Zdd ZddZddZddZddZdZy)N)Path)validate_coerce_fig_to_dictvalidate_coerce_output_type) get_module)ImageUriValidatorcZeZdZdZdZedZejdZedZ y) JsonConfig)jsonorjsonautocd|_y)Nr _default_engineselfs U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/plotly/io/_json.py__init__zJsonConfig.__init__s %c|jSNrrs rdefault_enginezJsonConfig.default_engines###rc|tjvr*tdjtj||dk(r|j ||_y)Nz9Supported JSON engines include {valid} Received {val})validvalr )r _valid_engines ValueErrorformatvalidate_orjsonr)rrs rrzJsonConfig.default_enginesY j// /LSS$33T  (?  ""rc4td}| tdy)Nr z-The orjson engine requires the orjson package)rr)clsr s rrzJsonConfig.validate_orjson&s"H% >LM M rN) __name__ __module__ __qualname__rrpropertyrsetter classmethodrrrr r sP/N&$$ # #NNrr c|dvry|S)zM This is used to ultimately *encode* into strict JSON, see `encode` )Infinityz -InfinityNaNNr')consts rcoerce_to_strictr,0s  00 r))z\u003e)/z\u002f))u
z\u2028)u
z\u2029cL|}|D]\}}||vs |j||}|Sr)replace)json_str_swapout unsafe_char safe_chars r_safer7Gs: C"'6 Y # ++k95C6 Jrc*tdd}|tj}|dk(r|d}nd}n|dvrtd|ztd d td d td d td d d}|dk(r;i}|rd|d<nd|d<ddlm}t tj|fd|i|tS|dk(rtj|j|jz}|r||jz} |j} t |j||j#dt$Sy#t $rY=wxYw#t&$rYnwxYwt)|dd|}t |j||j#dt$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: %szsage.allFnumpypandasz PIL.Image)sage_allnppdimageindent),: separatorsr)PlotlyJSONEncoderr )optionutf8) numpy_alloweddatetime_allowedmodules)rconfigrr_plotly_utils.utilsrHr7r dumps _swap_jsonr rOPT_NON_STR_KEYSOPT_SERIALIZE_NUMPY OPT_INDENT_2to_plotly_jsonAttributeErrordecode _swap_orjson TypeErrorclean_to_json_compatible) plotly_objectprettyenginer rMoptsrHcleaneds rto_json_plotlyr`Os<d 3F~&&   FF ) )2V;<<zu=e4u5KU; G DN",D 9 JJ} D*; Dt Dj   8 ""$&&)C)CC  F'' 'D )88:M   ]4 8??G        + !   V\\'$\7>>vF UUs$6D8/E8 EE EEct||}|r)|jdgD]}|jddt|||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 datauidN)r\r])rgetpopr`)figvalidater\ remove_uidsr]fig_dicttraces rto_jsonrksON+39H\\&"- #E IIeT " # (6& AArc&t|||||}t|tr t|}nt|tr|}nd}| |j |y|j|y#t $rYnwxYwt dj|)a Convert a figure to JSON and write it to a file or writeable object. Note: A figure converted to JSON with one version of Plotly.py may not be compatible with another version. 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 )rgr\rhr]NzX The 'file' argument '{file}' is not a string, pathlib.Path object, or file descriptor. )file) rk isinstancestrrwriterVrr write_text)rfrmrgr\rhr]r2paths r write_jsonrssL hv;vH $Dz D$  |  JJx  !     FF  sA)) A54A5ctdd}t|ttfs%t dj t |||tj}|dk(r|d}nd}n|dvrt d |z|dk(r'tj|j|}|St|tr|jd }tj|}|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 Tr9zr from_json_plotly requires a string or bytes argument but received value of type {typ} Received value: {value})typvaluer r r;r<zutf-8)rrnrobytesrrtyperNrr rloadsrWr )rvr]r value_dicts rfrom_json_plotlyr{-s6d 3F ec5\ * %v$u+UvC  ~&&   FF ) )2V;<< ""$\\%(   eU #LL)EZZ& rcJt||}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]rir rfs r from_jsonrls0P f5H &k 2C h\ 2C Jrct|tr t|}nt|tr|}nd}||j}n|j }t ||||S)a Construct a figure from the JSON contents of a local file or readable Python object. Note: A figure converted to JSON with one version of Plotly.py may not be compatible with another version. 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])rnror read_textreadr)rmr~r}r]rrr2s r read_jsonrseJ$Dz D$  >>#99; |V rc B t|tttfr|St|tr.|j Dcic]\}}|t |fi|c}}St|ttfr|r|Dcgc]}t |fi|c}S|jdd}|jdd}|jdi}|d}|d}|d} |d} |2||jvr t|S||jvr t|S|||jjjur td St||jr|r)|j j"d vr|j%|S|j j"d k(r|j'|j)S|j j"d k(r|j)S|j j"d k(r2|j)}n!t||j*r t|S| d|| j,us|| j.uryt|| j0| j2fr$|r3|j j"d vr|j%|j4S|j j"d k(rt|| j0rot7j85t7j:dt<|j?|j@jCj)} dddn|jCj)} |s/tEtG D]} | | jI| | < S |jC}|s |jISt|tNjNr|S |j)Scc}}wcc}w#1swYxYw#tJtLf$rYhwxYw#tJtLf$rYNwxYw#tL$rYnwxYwt|tPjRr t|S| +t|| jTrtWjX|S |j[}n#tL$rYnwxYwt|tr4|j Dcic]\}}|t |fi|c}}Scc}}wt|ttfr!|r|Dcgc]}t |fi|c}Scc}w|S)NrKFrLrMr?r@rArBnan)biufMUOignore).rnintfloatrodictitemsrZlisttuplerdRRZZmacoremaskedndarraydtypekindascontiguousarraydatetime_as_stringtolist datetime64NaTNASeries DatetimeIndexvalueswarningscatch_warnings simplefilter FutureWarningarraydt to_pydatetimerangelen isoformatrYrVdatetimedecimalDecimalImagerpil_image_to_urirU) objkwargskvrKrLrMr?r@rArB dt_valuesrs rrZrZs #UC() #tEHYY[QTQ+A888QQ C$ ' CFGa,Q9&9G GJJ6Mzz"4e<jjB'Gz"H B B G E (++ :  HKK s8O ~ "%%**## #<  RZZ (3G!G++C003&,,S188::3&zz|#3&jjl R]] +s8O ~ "&&=C255L bii)9)9: ;3G!G++CJJ773&c299-!002N --h F%'HHSVV-A-A-C$D$K$K$M NN !$ 1 1 3 : : 2@'0|'='='? ! @!  !  ==? " C** +  zz|kRH\NN, ~ &   >*       #w'Sz ZU[[9 11#66   "    #tEHYY[QTQ+A888QQQ C$ ' CFGa,Q9&9G GG JsmO!8O'$AO,O8$P P",O58P  P  PP" P.-P.R R! R!S"T)FN)TFTNr)FigureFN)r rrrpathlibrplotly.io._utilsrr_plotly_utils.optional_importsr_plotly_utils.basevalidatorsrobjectr rNr,rQrXr7r`rkrsr{rrrZr'rrrs U5: NN>    ]V@/BdI"X<~1h;|xr