
    6Dh                     8   S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKJr  S SKJr  S SKJr  S SKJr  S SKrS SKJrJr  S SKJr  S SKJr  \" S	5      rS
r\ V s0 s H  o U _M     sn r\R;                  SS05        S rS rS r S#S jr! " S S\"5      r#\#" 5       r$C# " S S\"5      r%\%" 5       r&C%\S 5       r'S r(S r)\RT                  " 5       r+SSS.r,\ RZ                  S 5       r.S r/S r0\!" SSSS9S  5       r1S$S! jr2 S$S" jr3gs  sn f )%    N)contextmanager)copy)Path)which)
PLOTLY_DIRensure_writable_plotly_dir)validate_coerce_fig_to_dict)
get_modulepsutil)pngjpegwebpsvgpdfepsjpgr   c           
      ~    [        SR                  [        U 5      U [        [        R                  5       5      S95      e)Nz
Invalid value of type {typ} receive as an image format specification.
    Received value: {v}

An image format must be specified as one of the following string values:
    {valid_formats})typvvalid_formats)
ValueErrorformattypesortedformat_conversionskeys)vals    A/var/www/html/env/lib/python3.13/site-packages/plotly/io/_orca.pyraise_format_value_errorr   !   s?    
	
 vS	S7I7N7N7P0Q  
	 	    c                     U c  g[        U [        5      (       a  U (       d  [        U 5        U R                  5       n U S   S:X  a  U SS n U [        ;  a  [        U 5        [        U    $ )a|  
Validate / coerce a user specified image format, and raise an informative
exception if format is invalid.

Parameters
----------
fmt
    A value that may or may not be a valid image format string.

Returns
-------
str or None
    A valid image format string as supported by orca. This may not
    be identical to the input image designation. For example,
    the resulting string will always be lower case and  'jpg' is
    converted to 'jpeg'.

    If the input format value is None, then no exception is raised and
    None is returned.

Raises
------
ValueError
    if the input `fmt` cannot be interpreted as a valid image format.
Nr   .   )
isinstancestrr   lowerr   fmts    r   validate_coerce_formatr)   .   sj    8 { c3s % ))+C 1v}!"g $$ % c""r    c                      [         R                   " 5       n U R                  [         R                  [         R                  S5        U R	                  S5        U R                  5       u  pU R                  5         U$ )zS
Use the socket module to find an open port.

Returns
-------
int
    An open port
r#   ) r   )socket
setsockopt
SOL_SOCKETSO_REUSEADDRbindgetsocknameclose)s_ports      r   find_open_portr6   a   sQ     	ALL""F$7$7;FF7OmmoGAGGIKr       
   `  c                    ^ ^^ UUU 4S jnU$ )Nc                 N   >^  [         R                  " T 5      U UUU4S j5       nU$ )Nc                  V  > [         R                   " 5       n  T" U 0 UD6$ ! [         a{  n[         R                   " 5       U-
  nUS-  T:  a  [        ST S35      Ue[        R                  " T	T5      n[        SUS SU S35        [         R                  " U5         S nAOS nAff = fM  )Ni  zRetry limit of z milliseconds reached.zRetrying in z.2fz seconds due to z...)time	ExceptionTimeoutErrorrandomuniformprintsleep)
argskwargs
start_timeeelapsed_time	wait_timefunc	max_delaymax_waitmin_waits
         r   wrapper)retry.<locals>.decorator.<locals>.wrapperu   s    J*000  	*#'99;#;L#d*i7*-i[8NO ! !'x BIL37Gs#NOJJy))	* s   ! 
B&A1B!!B&)	functoolswraps)rJ   rN   rK   rL   rM   s   ` r   	decoratorretry.<locals>.decoratort   s%    			* 
	*" r     )rM   rL   rK   rR   s   ``` r   retryrU   s   s    * r    c                      \ rS rSrSrS rS%S jr0 4S jrS%S jrS r	\
S 5       r\R                  S	 5       r\
S
 5       r\R                  S 5       r\
S 5       r\R                  S 5       r\
S 5       r\R                  S 5       r\
S 5       r\R                  S 5       r\
S 5       r\R                  S 5       r\
S 5       r\R                  S 5       r\
S 5       r\R                  S 5       r\
S 5       r\R                  S 5       r\
S 5       r\R                  S 5       r\
S 5       r\R                  S 5       r\
S 5       r\R                  S 5       r\
S  5       r\
S! 5       rS" rS#rg$)&
OrcaConfig   a   
Singleton object containing the current user defined configuration
properties for orca.

These parameters may optionally be saved to the user's ~/.plotly
directory using the `save` method, in which case they are automatically
restored in future sessions.
c                    0 U l         [        R                  R                  [        R                  R	                  [
        R                  5      5      n[        R                  R                  US5      U l        U R                  SS9  [        R                  R                  U R                  S5      nU[        R                  R                  [        S5      S.U l        g )Npackage_dataF)warnzplotly.min.js.orca)plotlyjsconfig_file)_propsospathdirnameabspathplotly__file__joinpackage_dirreloadr   
_constants)selfroot_dirr]   s      r   __init__OrcaConfig.__init__   s      77??277??6??#CD77<<.A 	 77<< 0 0/B 77<<
G<
r    c                 6    0 U l         U(       a  [        5         gg)zA
Reset all orca configuration properties to their default values
N)r_   reset_status)rj   reset_servers     r   restore_defaultsOrcaConfig.restore_defaults   s     N r    c                 T   [        U[        5      (       d"  [        SR                  [	        U5      US95      e[        U5      nUR                  U5        U H*  nX@R                  ;  d  M  [        SR                  US95      e   UR                  5        H  u  pE[        XU5        M     g)a`  
Update one or more properties from a dict or from input keyword
arguments.

Parameters
----------
d: dict
    Dictionary from property names to new property values.

kwargs
    Named argument value pairs where the name is a configuration
    property name and the value is the new property value.

Returns
-------
None

Examples
--------
Update configuration properties using a dictionary

>>> import plotly.io as pio
>>> pio.orca.config.update({'timeout': 30, 'default_format': 'svg'})

Update configuration properties using keyword arguments

>>> pio.orca.config.update(timeout=30, default_format='svg'})
zi
The first argument to update must be a dict, but received value of type {typ}l
    Received value: {val}r   r   zInvalid property name: {k})kN)
r$   dictr   r   r   r   updater_   itemssetattr)rj   drE   updatesru   r   s         r   rw   OrcaConfig.update   s    < !T"" $VQQ $ 	  q'v A# !=!D!Dq!D!IJJ 
 MMODADQ $r    c                    [         R                  R                  U R                  5      (       ao   [	        U R                  S5       nUR                  5       nSSS5         [        R                  " W5      nUR                  5        H  u  pVX`R                  U'   M     gU(       a.  [        R                  " SR                  U R                  S95        gg! , (       d  f       N= f!   U(       a-  [        R                  " SR                  U R                  S95         g= f! [         a7    U(       a-  [        R                  " SR                  U R                  S95         gf = f)a  
Reload orca settings from ~/.plotly/.orca, if any.

Note: Settings are loaded automatically when plotly is imported.
This method is only needed if the setting are changed by some outside
process (e.g. a text editor) during an interactive session.

Parameters
----------
warn: bool
    If True, raise informative warnings if settings cannot be restored.
    If False, do not raise warnings if setting cannot be restored.

Returns
-------
None
rNz0Unable to read orca configuration file at {path}ra   z3Orca configuration file at {path} is not valid JSONz+Orca configuration file at {path} not found)r`   ra   existsr^   openreadwarningsr[   r   jsonloadsr   rx   r_   )rj   r[   forca_str
orca_propsru   r   s          r   rh   OrcaConfig.reload   s-   $ 77>>$**++$**C0A vvxH 1
!ZZ1
 #((*!"A + MM//5v)) 06 0 ; 10MM44:F!%!1!1 5; 5 
  MM77=v!%!1!1 8> 8 s;   C% CC%  D  
C"C% "C% %6D >E! E!c                    [        5       (       a@  [        U R                  S5       n[        R                  " U R
                  USS9  SSS5        g[        R                  " SR                  U R                  S95        g! , (       d  f       g= f)z
Attempt to save current settings to disk, so that they are
automatically restored for future sessions.

This operation requires write access to the path returned by
in the `config_file` property.

Returns
-------
None
w   )indentNz3Failed to write orca configuration file at '{path}'r   )	r   r   r^   r   dumpr_   r   r[   r   )rj   r   s     r   saveOrcaConfig.save$  so     &''d&&,		$++q3 -, MM77=v)) 8> 8 -,s   !A>>
Bc                 :    U R                   R                  SS5      $ )z
The server URL to use for an external orca server, or None if orca
should be managed locally

Overrides executable, port, timeout, mathjax, topojson,
and mapbox_access_token

Returns
-------
str or None

server_urlNr_   getrj   s    r   r   OrcaConfig.server_url;  s     {{|T22r    c                    Uc  U R                   R                  SS 5        g [        U[        5      (       d"  [	        SR                  [        U5      US95      eUR                  S5      (       d  UR                  S5      (       d  SU-   n[        5         S U l	        S U l
        S U l        S U l        S U l        S U l        XR                   S'   g )Nr   zf
The server_url property must be a string, but received value of type {typ}.
    Received value: {val}rt   zhttp://zhttps://)r_   popr$   r%   r   r   r   
startswithshutdown_server
executabler5   timeoutmathjaxtopojsonmapbox_access_tokenrj   r   s     r   r   r   J  s     ;KKOOL$/#s###VS	s $   ~~i((
1K1Kc/C	#' $'L!r    c                 :    U R                   R                  SS5      $ )z
The specific port to use to communicate with the orca server, or
None if the port is to be chosen automatically.

If an orca server is active, the port in use is stored in the
plotly.io.orca.status.port property.

Returns
-------
int or None
r5   Nr   r   s    r   r5   OrcaConfig.porte  s     {{vt,,r    c                     Uc  U R                   R                  SS 5        g [        U[        5      (       d"  [	        SR                  [        U5      US95      eXR                   S'   g )Nr5   zb
The port property must be an integer, but received value of type {typ}.
    Received value: {val}rt   r_   r   r$   intr   r   r   r   s     r   r5   r   t  sc     ;KKOOFD)#s###VS	s $   "Fr    c                 f    U R                   R                  SS/5      nUc  gSR                  U5      $ )a  
The name or full path of the orca executable.

 - If a name (e.g. 'orca'), then it should be the name of an orca
   executable on the PATH. The directories on the PATH can be
   displayed by running the following command:

   >>> import os
   >>> print(os.environ.get('PATH').replace(os.pathsep, os.linesep))

 - If a full path (e.g. '/path/to/orca'), then
   it should be the full path to an orca executable. In this case
   the executable does not need to reside on the PATH.

If an orca server has been validated, then the full path to the
validated orca executable is stored in the
plotly.io.orca.status.executable property.

Returns
-------
str
executable_listorcaN )r_   r   rf   rj   r   s     r   r   OrcaConfig.executable  s3    0 ++//*;fXF"88O,,r    c                    Uc  U R                   R                  SS 5        O][        U[        5      (       d"  [	        SR                  [        U5      US95      e[        U[        5      (       a  U/nXR                   S'   [        5         g )Nr   zf
The executable property must be a string, but received value of type {typ}.
    Received value: {val}rt   r   )r_   r   r$   r%   r   r   r   ro   r   s     r   r   r     s|     ;KKOOL$/c3'' #V I3 $   #s##e-0KK)* 	r    c                 :    U R                   R                  SS5      $ )a  
The number of seconds of inactivity required before the orca server
is shut down.

For example, if timeout is set to 20, then the orca
server will shutdown once is has not been used for at least
20 seconds. If timeout is set to None, then the server will not be
automatically shut down due to inactivity.

Regardless of the value of timeout, a running orca server may be
manually shut down like this:

>>> import plotly.io as pio
>>> pio.orca.shutdown_server()

Returns
-------
int or float or None
r   Nr   r   s    r   r   OrcaConfig.timeout  s    * {{y$//r    c                     Uc  U R                   R                  SS 5        OK[        U[        [        45      (       d"  [        SR                  [        U5      US95      eXR                   S'   [        5         g )Nr   zc
The timeout property must be a number, but received value of type {typ}.
    Received value: {val}rt   )	r_   r   r$   r   floatr   r   r   r   r   s     r   r   r     sl     ;KKOOIt,cC<00 #V I3 $   &)KK	" 	r    c                 :    U R                   R                  SS5      $ )z
The default width to use on image export. This value is only
applied if no width value is supplied to the plotly.io
to_image or write_image functions.

Returns
-------
int or None
default_widthNr   r   s    r   r   OrcaConfig.default_width  s     {{55r    c                     Uc  U R                   R                  SS 5        g [        U[        5      (       d"  [	        SR                  [        U5      US95      eXR                   S'   g )Nr   zg
The default_width property must be an int, but received value of type {typ}.
    Received value: {val}rt   r   r   s     r   r   r     sc     ;KKOOOT2#s###VS	s $   (+O$r    c                 :    U R                   R                  SS5      $ )z
The default height to use on image export. This value is only
applied if no height value is supplied to the plotly.io
to_image or write_image functions.

Returns
-------
int or None
default_heightNr   r   s    r   r   OrcaConfig.default_height  s     {{/66r    c                     Uc  U R                   R                  SS 5        g [        U[        5      (       d"  [	        SR                  [        U5      US95      eXR                   S'   g )Nr   zh
The default_height property must be an int, but received value of type {typ}.
    Received value: {val}rt   r   r   s     r   r   r     se     ;KKOO,d3#s###VS	s $   ),$%r    c                 :    U R                   R                  SS5      $ )aV  
The default image format to use on image export.

Valid image formats strings are:
  - 'png'
  - 'jpg' or 'jpeg'
  - 'webp'
  - 'svg'
  - 'pdf'
  - 'eps' (Requires the poppler library to be installed)

This value is only applied if no format value is supplied to the
plotly.io to_image or write_image functions.

Returns
-------
str or None
default_formatr   r   r   s    r   r   OrcaConfig.default_format  s    ( {{/77r    c                 v    Uc  U R                   R                  SS 5        g [        U5      nXR                   S'   g )Nr   )r_   r   r)   r   s     r   r   r   2  s4    ;KKOO,d3$S)(+$%r    c                 :    U R                   R                  SS5      $ )z
The default image scaling factor to use on image export.
This value is only applied if no scale value is supplied to the
plotly.io to_image or write_image functions.

Returns
-------
int or None
default_scaler#   r   r   s    r   r   OrcaConfig.default_scale;  s     {{22r    c                     Uc  U R                   R                  SS 5        g [        U[        [        45      (       d"  [        SR                  [        U5      US95      eXR                   S'   g )Nr   zi
The default_scale property must be a number, but received value of type {typ}.
    Received value: {val}rt   )r_   r   r$   r   r   r   r   r   r   s     r   r   r   H  sg     ;KKOOOT2#U|,,#VS	s $   (+O$r    c                 :    U R                   R                  SS5      $ )z
Path to the topojson files needed to render choropleth traces.

If None, topojson files from the plot.ly CDN are used.

Returns
-------
str
r   Nr   r   s    r   r   OrcaConfig.topojsonX  s     {{z400r    c                     Uc  U R                   R                  SS 5        OE[        U[        5      (       d"  [	        SR                  [        U5      US95      eXR                   S'   [        5         g )Nr   zd
The topojson property must be a string, but received value of type {typ}.
    Received value: {val}rt   r_   r   r$   r%   r   r   r   r   r   s     r   r   r   e  sh     ;KKOOJ-c3'' #V I3 $   '*KK
# 	r    c                 :    U R                   R                  SS5      $ )zS
Path to the MathJax bundle needed to render LaTeX characters

Returns
-------
str
r   z?https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.jsr   r   s    r   r   OrcaConfig.mathjaxx  s     {{Q
 	
r    c                     Uc  U R                   R                  SS 5        OE[        U[        5      (       d"  [	        SR                  [        U5      US95      eXR                   S'   [        5         g )Nr   zc
The mathjax property must be a string, but received value of type {typ}.
    Received value: {val}rt   r   r   s     r   r   r     sh     ;KKOOIt,c3'' #V I3 $   &)KK	" 	r    c                 :    U R                   R                  SS5      $ )zL
Mapbox access token required to render mapbox traces.

Returns
-------
str
r   Nr   r   s    r   r   OrcaConfig.mapbox_access_token  s     {{4d;;r    c                     Uc  U R                   R                  SS 5        OE[        U[        5      (       d"  [	        SR                  [        U5      US95      eXR                   S'   [        5         g )Nr   zo
The mapbox_access_token property must be a string, but received value of type {typ}.
    Received value: {val}rt   r   r   s     r   r   r     sl     ;KKOO148c3''  $V I3 $ 	  25KK-. 	r    c                 >    SnU R                   R                  SU5      $ )Nautouse_xvfbr   )rj   dflts     r   r   OrcaConfig.use_xvfb  s    {{z400r    c           	          / SQnUc  U R                   R                  SS 5        O?X;  a,  [        SR                  U[	        U5      [        U5      S95      eXR                   S'   [        5         g )N)TFr   r   zZ
The use_xvfb property must be one of {valid_vals}
    Received value of type {typ}: {val})
valid_valsr   r   )r_   r   r   r   r   reprro   )rj   r   r   s      r   r   r     si    *
;KKOOJ-$ ++16#-49$s) ,2 ,  '*KK
# 	r    c                 :    U R                   R                  SS5      $ )zK
The plotly.js bundle being used for image rendering.

Returns
-------
str
r]   N)ri   r   r   s    r   r]   OrcaConfig.plotlyjs  s     "":t44r    c                 J    [         R                  R                  [        S5      $ )z
Path to orca configuration file

Using the `plotly.io.config.save()` method will save the current
configuration settings to this file. Settings in this file are
restored at the beginning of each sessions.

Returns
-------
str
r\   )r`   ra   rf   r   r   s    r   r^   OrcaConfig.config_file  s     ww||J00r    c                 R   SR                  U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9$ )zB
Display a nice representation of the current orca configuration.
a  orca configuration
------------------
    server_url: {server_url}
    executable: {executable}
    port: {port}
    timeout: {timeout}
    default_width: {default_width}
    default_height: {default_height}
    default_scale: {default_scale}
    default_format: {default_format}
    mathjax: {mathjax}
    topojson: {topojson}
    mapbox_access_token: {mapbox_access_token}
    use_xvfb: {use_xvfb}

constants
---------
    plotlyjs: {plotlyjs}
    config_file: {config_file}

)r   r5   r   r   r   r   r   r   r   r   r   r]   r^   r   )r   r   r5   r   r   r   r   r   r   r   r   r   r]   r^   r   r   s    r   __repr__OrcaConfig.__repr__  s    * FLL,,..,,..LL]] $ 8 8]]((]]  
+$	
r    )	ri   r_   r   r   r   rg   r5   r   r   N)T)__name__
__module____qualname____firstlineno____doc__rl   rq   rw   rh   r   propertyr   setterr5   r   r   r   r   r   r   r   r   r   r   r]   r^   r   __static_attributes__rT   r    r   rW   rW      sr   
&  2 h9v. 3 3 ( (4 - - 
[[" "  - -:  ( 0 0, ^^ $ 
6 
6 + + 
7 
7 , , 8 8* , , 
3 
3 + + 
1 
1 __ $ 
 
 ^^ $ < <   & 1 1 __ & 5 5 1 1(
r    rW   c                       \ rS rSrSrSSSSSSS.r\S 5       r\S 5       r\S 5       r	\S	 5       r
\S
 5       r\S 5       rS rSrg)
OrcaStatusi  zI
Class to store information about the current status of the orca server.
unvalidatedN)stater   versionpidr5   commandc                      U R                   S   $ )aQ  
A string representing the state of the orca server process

One of:
  - unvalidated: The orca executable has not yet been searched for or
    tested to make sure its valid.
  - validated: The orca executable has been located and tested for
    validity, but it is not running.
  - running: The orca server process is currently running.
r   r_   r   s    r   r   OrcaStatus.state,  s     {{7##r    c                 J    U R                   S   nUc  gSR                  U5      $ )a#  
If the `state` property is 'validated' or 'running', this property
contains the full path to the orca executable.

This path can be specified explicitly by setting the `executable`
property of the `plotly.io.orca.config` object.

This property will be None if the `state` is 'unvalidated'.
r   Nr   )r_   rf   r   s     r   r   OrcaStatus.executable:  s+     ++&78"88O,,r    c                      U R                   S   $ )z
If the `state` property is 'validated' or 'running', this property
contains the version of the validated orca executable.

This property will be None if the `state` is 'unvalidated'.
r   r   r   s    r   r   OrcaStatus.versionK  s     {{9%%r    c                      U R                   S   $ )zp
The process id of the orca server process, if any. This property
will be None if the `state` is not 'running'.
r   r   r   s    r   r   OrcaStatus.pidU  s     {{5!!r    c                      U R                   S   $ )z
The port number that the orca server process is listening to, if any.
This property will be None if the `state` is not 'running'.

This port can be specified explicitly by setting the `port`
property of the `plotly.io.orca.config` object.
r5   r   r   s    r   r5   OrcaStatus.port]  s     {{6""r    c                      U R                   S   $ )z
The command arguments used to launch the running orca server, if any.
This property will be None if the `state` is not 'running'.
r   r   r   s    r   r   OrcaStatus.commandh  s     {{9%%r    c           	          SR                  U R                  U R                  U R                  U R                  U R
                  U R                  S9$ )zB
Display a nice representation of the current orca server status.
zorca status
-----------
    state: {state}
    executable: {executable}
    version: {version}
    port: {port}
    pid: {pid}
    command: {command}

)r   r   r5   r   r   r   )r   r   r   r5   r   r   r   r   s    r   r   OrcaStatus.__repr__p  sG    
 FLL**LL  
	
r    rT   )r   r   r   r   r   r_   r   r   r   r   r   r5   r   r   r   rT   r    r   r   r     s    
 F $ $ - -  & & " " # # & &
r    r   c            	   #     #    / SQn 0 n UR                  U  Vs0 s H8  o"[        R                  ;   d  M  U[        R                  R                  U5      _M:     sn5        Sv   UR	                  5        H  u  p#U[        R                  U'   M     gs  snf ! UR	                  5        H  u  p#U[        R                  U'   M     f = f7f)a  
Context manager to clear and restore environment variables that are
problematic for orca to function properly

NODE_OPTIONS: When this variable is set, orca <v1.2 will have a
segmentation fault due to an electron bug.
See: https://github.com/electron/electron/issues/12695

ELECTRON_RUN_AS_NODE: When this environment variable is set the call
to orca is transformed into a call to nodejs.
See https://github.com/plotly/orca/issues/149#issuecomment-443506732
)NODE_OPTIONSELECTRON_RUN_AS_NODE
LD_PRELOADN)rw   r`   environr   rx   )clear_env_varsorig_env_varsvarr   s       r   orca_envr     s      LNM	"1?U#"**CT%S"**..%%U	
 	 &++-HC!BJJsO . V
 &++-HC!BJJsO .s2   CB B$BB #-CB .CCc            	         [         R                  S:w  a  gSn [        [        R                  5      n[
        R                  R                  S[
        R                  5      nUR                  [
        R                  S5      nUc(  [        SR                  [        R                  UU S95      eSS	S
U/n[        R                  S:X  a1  [        S5      nU(       d  [        SR                  US95      eU/U-   nO[        R                  S:X  aj  [        R                  R!                  S5      (       aF  [
        R                  R                  S5      (       d"  [        S5      (       a  [        S5      nU/U-   nOU/nSR                  XS9n[#        5          [$        R&                  " US/-   [$        R(                  [$        R(                  S9nUR+                  5       u  pSSS5        WR,                  S:w  a  USR                  SR/                  U5      W
R1                  S5      UR,                  S9-   n[        R                  R!                  S5      (       a)  [
        R                  R                  S5      (       d  US-  n[        U5      eW	(       d*  [        USR                  SR/                  U5      S9-   5      eSU	R1                  S5      ;  a+  [        USR                  SR/                  U5      U	S 9-   5      e[#        5          [$        R&                  " US!/-   [$        R(                  [$        R(                  S9nUR+                  5       u  pSSS5        UR,                  S:w  aE  [        US"R                  SR/                  U5      WR1                  S5      UR,                  S9-   5      eW(       d*  [        US#R                  SR/                  U5      S9-   5      eUR1                  5       nU[         R2                  S$'   UR5                  5       [         R2                  S%'   S&[         R2                  S''   g! , (       d  f       GN]= f! , (       d  f       N= f)(a  
Attempt to find and validate the orca executable specified by the
`plotly.io.orca.config.executable` property.

If the `plotly.io.orca.status.state` property is 'validated' or 'running'
then this function does nothing.

How it works:
  - First, it searches the system PATH for an executable that matches the
  name or path specified in the `plotly.io.orca.config.executable`
  property.
  - Then it runs the executable with the `--help` flag to make sure
  it's the plotly orca executable
  - Then it runs the executable with the `--version` flag to check the
  orca version.

If all of these steps are successful then the `status.state` property
is set to 'validated' and the `status.executable` and `status.version`
properties are populated

Returns
-------
None
r   Na  If you haven't installed orca yet, you can do so using conda as follows:

    $ conda install -c plotly plotly-orca

Alternatively, see other installation methods in the orca project README at
https://github.com/plotly/orca

After installation is complete, no further configuration should be needed.

If you have installed orca, then for some reason plotly.py was unable to
locate it. In this case, set the `plotly.io.orca.config.executable`
property to the full path of your orca executable. For example:

    >>> plotly.io.orca.config.executable = '/path/to/orca'

After updating this executable property, try the export operation again.
If it is successful then you may want to save this configuration so that it
will be applied automatically in future sessions. You can do this as follows:

    >>> plotly.io.orca.config.save()

If you're still having trouble, feel free to ask for help on the forums at
https://community.plot.ly/c/api/python
PATHz
    z
The orca executable is required to export figures as static images,
but it could not be found on the system path.

Searched for executable '{executable}' on the following path:
    {formatted_path}

{instructions})r   formatted_pathinstructionsz--auto-servernumz--server-argsz4-screen 0 640x480x24 +extension RANDR +extension GLXTzxvfb-runz
The plotly.io.orca.config.use_xvfb property is set to True, but the
xvfb-run executable could not be found on the system path.

Searched for the executable 'xvfb-run' on the following path:
    {formatted_path})r  r   linuxDISPLAYa  
The orca executable is required in order to export figures as static images,
but the executable that was found at '{executable}'
does not seem to be a valid plotly orca executable. Please refer to the end of
this message for details on what went wrong.

{instructions})r   r  z--helpstdoutstderrr   zu
Here is the error that was returned by the command
    $ {executable} --help

[Return code: {returncode}]
{err_msg}
r   utf-8)r   err_msg
returncodea  Note: When used on Linux, orca requires an X11 display server, but none was
detected. Please install Xvfb and configure plotly.py to run orca using Xvfb
as follows:

    >>> import plotly.io as pio
    >>> pio.orca.config.use_xvfb = True

You can save this configuration for use in future sessions as follows:

    >>> pio.orca.config.save()

See https://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml
for more info on Xvfb
z_
The error encountered is that no output was returned by the command
    $ {executable} --help
)r   z"Plotly's image-exporting utilitieszv
The error encountered is that unexpected output was returned by the command
    $ {executable} --help

{help_result}
)r   help_resultz	--versiona  
An error occurred while trying to get the version of the orca executable.
Here is the command that plotly.py ran to request the version
    $ {executable} --version

This command returned the following error:

[Return code: {returncode}]
{err_msg}
        z
The error encountered is that no version was reported by the orca executable.
Here is the command that plotly.py ran to request the version:

    $ {executable} --version
r   r   	validatedr   )statusr   r   configr   r`   r   r   defpathreplacepathsepr   r   r   sysplatformr   r   
subprocessPopenPIPEcommunicater  rf   decoder_   strip)install_location_instructionsr   ra   r  	xvfb_argsxvfb_run_executabler   invalid_executable_msgpr  
help_errorr  version_resultversion_errors                 r   validate_executabler$    s   6 ||}$%!: v(()J::>>&"**-D\\"**h7N &!,,-:  
 	
$ 	>	I $#J/"
 #1  	 	 //);6!LL##G,,

y))* $J/./); &, &    
xj(
 #$--/ 
 	||q" F88O4"))'2<<   	  <<""7++BJJNN94M4M  G !!" F88O4  	
 	
 ,;3E3Eg3NN"
 F88O4+  

 
	
 
{m+????
 )*% 
 	||q"	 F88O4%,,W5<<  
 	
$ "
 F88O4  

 
	
 (..0'6FMM#$-335FMM)(FMM'g 
L 
s   A	P.?A	Q .
P= 
Qc                      [        5         S[        R                  S'   S[        R                  S'   S[        R                  S'   g)z
Shutdown the running orca server, if any, and reset the orca status
to unvalidated.

This command is only needed if the desired orca executable is changed
during an interactive session.

Returns
-------
None
Nr   r   r   r   )r   r  r_   rT   r    r   ro   ro     s5     '+FMM#$#FMM)*FMM'r    )procshutdown_timerc                      [        5         g )N)r   rT   r    r   cleanupr)    s    r    c                     [         S   Gb  [           [         S   Gb  [        R                  [         S   R                  5      n U R                  SS9 H  n UR                  5         M      [         S   R                  5         [         S   R                  5       nS[         S'   [         S   b   [         S   R                  5         S[         S'   S[         S'   S[        R                  S'   S[        R                  S	'   S[        R                  S'   S[        R                  S
'   SSS5        gg!    M  = f!    N= f! , (       d  f       g= f)zH
Shutdown the running orca server process, if any

Returns
-------
None
r&  NT)	recursiver'  r5   r  r   r   r   )
orca_state	orca_lockr   Processr   children	terminatewaitcancelr  r_   )parentchildchild_statuss      r   r   r     s(    &%&!-  
6(:(>(>?#__t_<E) =v&002 $.f#5#:#:#<L &*
6"./;/077937J/0%)
6" *5g&'+e$(,f%+/i(Q Y &1 Ys=   AD;D,'D;,.D4BD;,D1.D;4D86D;;
E	c                     [         c  [        S5      e[        S5      (       d  [        S5      e[        R                  (       Gd  [
        R                  S:X  a
  [        5         [           [        S   b  [        S   R                  5         [        S   Gc  [        R                  c  [        5       [        S'   O[        R                  [        S'   [
        R                  S	   S
S[        [        S   5      S[        R                  S/-   n [        R                   (       a!  U R#                  S[        R                   /5        [        R$                  (       a!  U R#                  S[        R$                  /5        [        R&                  (       a!  U R#                  S[        R&                  /5        [)        [*        R,                  S5      n[/        5          S[*        R0                  ;   a  UOSn[2        R4                  " XUS9[        S'   SSS5        S[
        R                  S'   [        S   R6                  [
        R                  S'   [        S   [
        R                  S'   U [
        R                  S'   [        R8                  bI  [:        R<                  " [        R8                  [>        5      nSUl         URC                  5         U[        S'   SSS5        gg! , (       d  f       N= f! , (       d  f       g= f)z
Start an orca server if none is running. If a server is already running,
then reset the timeout countdown

Returns
-------
None
NzImage generation requires the psutil package.

Install using pip:
    $ pip install psutil

Install using conda:
    $ conda install psutil
requestszImage generation requires the requests package.

Install using pip:
    $ pip install requests

Install using conda:
    $ conda install requests
r   r'  r&  r5   r   servez-pz--plotlyz--graph-onlyz
--topojsonz	--mathjaxz--mapbox-access-tokenwbCIr  runningr   r   r   T)"r   r   r
   r  r   r  r   r$  r-  r,  r2  r5   r6   r_   r%   r]   r   extendr   r   r   r`   devnullr   r   r  r  r   r   	threadingTimerr   daemonstart)cmd_listDEVNULLr	  ts       r   ensure_serverrE    s7    ~

 
	
 j!!

 
	
 <<=(! *+7+,335 &!) ;;&)7)9Jv&)/Jv& "==):;
6*+OO"?  ??OO\6??$CD>>OO[&..$AB--OO0&2L2LM rzz40Z(,

(:WF)3)9)9 *Jv&   *3g&'1&'9'='=e$(26(:f%+3i( ~~)OOFNNOD  	/0
+,u Y X  ZM Ys&   (E'K%5KCK%
K"	K%%
K3)rM   rL   rK   c                  x   SSK Jn  SSKJn  [        R
                  (       a  [        R
                  nOSR                  S[        S   S9nU R                  5        VVs0 s H  u  pEUc  M
  XE_M     nnnU" U5      nU" US-   US	9nUR                  S
:X  a  [        5         [        5         [        S5      eU$ s  snnf )za
Helper method to perform an image request to a running orca server process
with retrying logic.
r   )post)to_json_plotlyzhttp://{hostname}:{port}	localhostr5   )hostnamer5   /)datai
  z522: client socket timeout)r7  rG  plotly.io.jsonrH  r  r   r   r,  rx   status_coder   rE  OSError)	rE   rG  rH  r   ru   r   request_paramsjson_strresponses	            r   request_image_with_retryingrS  j  s     -&&
/66 z&'9 7 

 )/Huq!dadNHn-HJ$84Hs"233O Is   	B6*B6c           	         [        5         Uc  [        R                  n[        U5      nUc  [        R                  nUc  [        R
                  nUc  [        R                  n[        X5      n [        XaXBUS9nUR&                  S:X  a  UR(                  $ S	R                  UR&                  UR(                  R+                  S
5      S9nUR&                  S:X  a"  [-        U [.        5      (       a  U(       d  US-  nOUR&                  S:X  a]  [1        UR3                  S/ 5       Vs/ s H  nUR3                  SS5      S:H  PM     sn5      nU(       a  [        R4                  c  US-  nOUR&                  S:X  a  US:X  a  US-  n[        U5      e! [         a  n[        [        5      n	[        R                  (       a&  [        SR                  [        R                  S95      e[        R!                  [        R"                  5      n
U
(       a  [        SR                  U	S95      e[%        5         [        SR                  U	S95      eSnAff = fs  snf )a  
Convert a figure to a static image bytes string

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

format: str or None
    The desired image format. One of
      - 'png'
      - 'jpg' or 'jpeg'
      - 'webp'
      - 'svg'
      - 'pdf'
      - 'eps' (Requires the poppler library to be installed)

    If not specified, will default to `plotly.io.config.default_format`

width: int or None
    The width of the exported image in layout pixels. If the `scale`
    property is 1.0, this will also be the width of the exported image
    in physical pixels.

    If not specified, will default to `plotly.io.config.default_width`

height: int or None
    The height of the exported image in layout pixels. If the `scale`
    property is 1.0, this will also be the height of the exported image
    in physical pixels.

    If not specified, will default to `plotly.io.config.default_height`

scale: int or float or None
    The scale factor to use when exporting the figure. A scale factor
    larger than 1.0 will increase the image resolution with respect
    to the figure's layout pixel dimensions. Whereas as scale factor of
    less than 1.0 will decrease the image resolution.

    If not specified, will default to `plotly.io.config.default_scale`

validate: bool
    True if the figure should be validated before being converted to
    an image, False otherwise.

Returns
-------
bytes
    The image data
N)figurer   scalewidthheightz
Plotly.py was unable to communicate with the orca server at {server_url}

Please check that the server is running and accessible.
)r   z
For some reason plotly.py was unable to communicate with the
local orca server process, even though the server process seems to be running.

Please review the process and connection information below:

{info}
)infoz
For some reason the orca server process is no longer running.

Please review the process and connection information below:

{info}
plotly.py will attempt to start the local server process again the next time
an image export operation is performed.
   zl
The image request was rejected by the orca conversion utility
with the following error:
   {status}: {msg}
r
  )r  msgi  z\
Try setting the `validate` argument to True to check for errors in the
figure specificationi  rL  r   scattermapboxaX  
Exporting scattermapbox traces requires a mapbox access token.
Create a token in your mapbox account and then set it using:

>>> plotly.io.orca.config.mapbox_access_token = 'pk.abc...'

If you would like this token to be applied automatically in
future sessions, then save your orca configuration as follows:

>>> plotly.io.orca.config.save()
i  r   a  
Exporting to EPS format requires the poppler library.  You can install
poppler on MacOS or Linux with:

    $ conda install poppler

Or, you can install it on MacOS using homebrew with:

    $ brew install poppler

Or, you can install it on Linux using your distribution's package manager to
install the 'poppler-utils' package.

Unfortunately, we don't yet know of an easy way to install poppler on Windows.
)rE  r  r   r)   r   r   r   r	   rS  rO  r   r  r   r   r   r   
pid_existsr   ro   rN  contentr  r$   rv   anyr   r   )figr   rW  rX  rV  validatefig_dictrR  err
status_strr]  err_messagetrace
any_mapboxs                 r   to_imagerh    sb   j O
 ~&&#F+F}$$}$$~&& +39H5.%V
p s" F''X-=-=-D-DW-M  
	 	$ 3&:c4+@+@  K !!S( "*fb!9!9 IIfd+>!9J f88@ 
  
 !!S(Vu_  K %%g  1&\
 F%00     **6::6J   F'      F'   K1ds   .F #I
I
B.II
c           	         [        U[        5      (       a  [        U5      nO[        U[        5      (       a  UnOSnUb@  Uc=  UR                  nU(       a  UR	                  S5      nO[        SR                  US95      e[        XX4XVS9n	Uc   UR                  U	5        gUR                  U	5        g! [         a     Of = f[        SR                  US95      e)a  
Convert a figure to a static image 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)

format: str or None
    The desired image format. One of
      - 'png'
      - 'jpg' or 'jpeg'
      - 'webp'
      - 'svg'
      - 'pdf'
      - 'eps' (Requires the poppler library to be installed)

    If not specified and `file` is a string then this will default to the
    file extension. If not specified and `file` is not a string then this
    will default to `plotly.io.config.default_format`

width: int or None
    The width of the exported image in layout pixels. If the `scale`
    property is 1.0, this will also be the width of the exported image
    in physical pixels.

    If not specified, will default to `plotly.io.config.default_width`

height: int or None
    The height of the exported image in layout pixels. If the `scale`
    property is 1.0, this will also be the height of the exported image
    in physical pixels.

    If not specified, will default to `plotly.io.config.default_height`

scale: int or float or None
    The scale factor to use when exporting the figure. A scale factor
    larger than 1.0 will increase the image resolution with respect
    to the figure's layout pixel dimensions. Whereas as scale factor of
    less than 1.0 will decrease the image resolution.

    If not specified, will default to `plotly.io.config.default_scale`

validate: bool
    True if the figure should be validated before being converted to
    an image, False otherwise.

Returns
-------
None
Nr"   z
Cannot infer image type from output path '{file}'.
Please add a file extension or specify the type using the format parameter.
For example:

    >>> import plotly.io as pio
    >>> pio.write_image(fig, file_path, format='png')
)file)r   rV  rW  rX  ra  zX
The 'file' argument '{file}' is not a string, pathlib.Path object, or file descriptor.
)r$   r%   r   suffixlstripr   r   rh  writeAttributeErrorwrite_bytes)
r`  rj  r   rV  rW  rX  ra  ra   extimg_datas
             r   write_imagerr  O  s    | $Dz	D$		  FNkkZZ_F F     %VH |	JJx  	"  		
F  
 	
s   B2 2
B?>B?)r7   r8   r9   )NNNNT)4atexitrP   r   r`   r@   r,   r  r  r>  r=   r   
contextlibr   r   pathlibr   shutilr   rd   plotly.filesr   r   plotly.io._utilsr	   plotly.optional_importsr
   r   r   r   rw   r   r)   r6   rU   objectrW   r  r   r  r   r$  ro   Lockr-  r,  registerr)  r   rE  rS  rh  rr  r'   s   0r   <module>r}     sW      	    
    %     ? 8 .	H	 =*78-33h-8    5&/ *

0#f$6E

 E

T 

g
 g
X 
 " "<y)x+( NN	d3
  30nf1R B%0 18E&R KOx#i1 9s   +D