
    VfL                         d Z ddlmZ ddlZ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  ed      Z ed      Z ed      Z ej"                         Zd	Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zy)zK
utils
=====

Low-level functionality NOT intended for users to EVER use.

    )absolute_importNPlotlyError)
get_modulenumpypandaszsage.allaV  The plotly_domain and plotly_api_domain of your config file must start with 'https', not 'http'. If you are not using On-Premise then run the following code to ensure your plotly_domain and plotly_api_domain start with 'https':


import plotly
plotly.tools.set_config_file(
    plotly_domain='https://plotly.com',
    plotly_api_domain='https://api.plotly.com'
)


If you are using On-Premise then you will need to use your company's domain and api_domain urls:


import plotly
plotly.tools.set_config_file(
    plotly_domain='https://plotly.your-company.com',
    plotly_api_domain='https://plotly.your-company.com'
)


Make sure to replace `your-company.com` with the URL of your Plotly On-Premise server.
See https://plotly.com/python/getting-started/#special-instructions-for-plotly-onpremise-users for more help with getting started with On-Premise.c                 |   i }t         j                  j                  |       rt        j	                          t        | d      5 }	 t        j                  |      }t        |t              si }ddd       t        j                          |r|D ci c]  }||v s|||    c}S |S #  i }Y ?xY w# 1 sw Y   CxY wc c}w )z5Checks if file exists. Returns {} if something fails.rN)ospathexistslockacquireopen_jsonload
isinstancedictrelease)filenameargsdatafkeys        [/var/www/html/software/conda/envs/catlas/lib/python3.12/site-packages/chart_studio/utils.pyload_json_dictr   9   s    D	ww~~h(C  	Azz!}!$-D		 	.2BscTkCcNBBK	 	 Cs*   B-'B$	B9B9$B*(B--B6c                    t        |t              rft        j                  |d      }t        j                          t        | d      5 }|j                  |       ddd       t        j                          yt        d      # 1 sw Y   )xY w)zBSave json to file. Error if path DNE, not a dict, or invalid json.   )indentwNz+json_dict was not a dictionary. not saving.)
r   r   r   dumpsr   r   r   writer   	TypeError)r   	json_dictjson_stringr   s       r   save_json_dictr&   K   sg    )T"kk)A6(C  	!AGGK 	!EFF		! 	!s   BBc                     t         j                  j                  |       sDt         j                  j                  |       \  }}t	        |       t        | d      5 }	 ddd       yy# 1 sw Y   yxY w)zAGiven a valid filename, make sure it exists (will create if DNE).r    N)r   r   r   splitensure_dir_existsr   )r   headtailr   s       r   ensure_file_existsr,   X   s^    77>>(#WW]]8,
d$(C  	A	 	 $	 	s   A%%A.c                 |    t         r6t        j                  j                  |       st        j                  |        yyy)z2Given a valid directory path, make sure it exists.N)dirr   r   isdirmakedirs)	directorys    r   r)   r)   a   s+    
ww}}Y'KK	" (     c                 X    t               }| D ]  }||vr|j                  |       |c S  y )N)setadd)itemsseenitems      r   get_first_duplicater9   h   s5    5D tHHTNK	
 r2   c                 R    t        j                  d      }|j                  |       yy)Nz.+src$TF)recompilematch)r   	src_regexs     r   is_source_keyr?   s   s%    

9%Is'r2   c                     d| v r#| d   du rd| v r| d   | d   dk7  rt        d      d| v r| d   du rd| v r| d   dk(  rt        d      d| v r| d   dvrt        d	      y y )
Nworld_readableTsharingpubliczLooks like you are setting your plot privacy to both public and private.
 If you set world_readable as True, sharing can only be set to 'public'FzLooks like you are setting your plot privacy to both public and private.
 If you set world_readable as False, sharing can only be set to 'private' or 'secret')rC   privatesecretNzThe 'sharing' argument only accepts one of the following strings:
'public' -- for public plots
'private' -- for private plots
'secret' -- for private plots that can be shared with a secret urlr   
option_sets    r   ,validate_world_readable_and_sharing_settingsrH   |   s    J&'(D0#y!-y!X-2
 	
 	J&'(E1#y!X-F
 	

 
j	 Z	%: C & 
 	
&	 r2   c                     g }dD ]!  }|| v s| |   s|j                  | |          # t        d |D              s t        j                  t        t
               y y )N)plotly_domainplotly_api_domainc              3   Z   K   | ]#  }|j                         j                  d        % yw)httpsN)lower
startswith).0ds     r   	<genexpr>z*validate_plotly_domains.<locals>.<genexpr>   s!     Gqwwy##G,Gs   )+)category)appendallwarningswarnhttp_msgUserWarning)rG   domains_not_nonerQ   s      r   validate_plotly_domainsr[      s[    3 3
?z!}##JqM23 G6FGGh5 Hr2   c                 p    d| v rd| vr| d   rd| d<   y d| d<   y d| v rd| vr| d   dk(  rd| d<   y d| d<   y y y )NrA   rB   rC   rD   TF rF   s    r   set_sharing_and_world_readabler^      sh    :%):*E,67G,H
9i
9	j	 %5Z%Gi H,+/J'(+0J'(	 &H	 r2   )__doc__
__future__r   os.pathr   r;   	threadingrV   jsonr   _plotly_utils.exceptionsr   _plotly_utils.optional_importsr   r   r   sage_allLockr   rX   r   r&   r,   r)   r9   r?   rH   r[   r^   r]   r2   r   <module>rh      s    '  	    0 5 	7	H	j! y~~: 	6$
G#$
N61r2   