
    Vfu:                     B   d Z ddlmZ ddlZddlZddlZddlmZ ddlZddl	m
Z
 ddlmZmZ ddlmZmZmZ  ej$                  d      Z ej$                  d	      Z ej$                  d
      Zd Zd Z	 	 	 	 	 ddZd Zd Z	 	 	 	 	 	 	 	 ddZd Zd ZddZddZddZ y)zB
tools
=====

Functions that USERS will possibly want access to.

    )absolute_importN)optional_imports)ensure_writable_plotly_dir)sessionutils)CONFIG_FILECREDENTIALS_FILEFILE_CONTENTzIPython.core.displayzIPython.displaysage_salvusc                  .    t        t        t                 S )z
    Convenience function to check current settings against defaults.

    Example:

        if plotly_domain != get_config_defaults()['plotly_domain']:
            # do something

    )dictr
   r        [/var/www/html/software/conda/envs/catlas/lib/python3.12/site-packages/chart_studio/tools.pyget_config_defaultsr      s     [)**r   c                     t               rt        t        fD ]  } t        j                  |        t        j
                  |       }|j                         }t        t        |    j                               D ]  \  }}||vs|||<    t        |j                               }|D ]  }|t        |    vs||=  |j                         |j                         k7  st        j                  | |        yt        j                  d       y)zEnsure that filesystem is setup/filled out in a valid way.
    If the config or credential files aren't filled out, then write them
    to the disk.
    af  Looks like you don't have 'read-write' permission to your 'home' ('~') directory or to our '~/.plotly' directory. That means plotly's python api can't setup local configuration files. No problem though! You'll just have to sign-in using 'plotly.plotly.sign_in()'. For help with that: 'help(plotly.plotly.sign_in)'.
Questions? Visit https://support.plotly.comN)r   r	   r   r   ensure_file_existsload_json_dictcopylistr
   itemskeyssave_json_dictwarningswarn)fncontentscontents_origkeyvalcontents_keyss         r   ensure_local_plotly_filesr"   +   s    
 "##[1 	3B$$R(++B/H$MMOM b!1!7!7!9: (Sh&$'HSM( !1M$ &l2.. & !!#x}}6$$R2#	3( 	<	
r   c                    t               st        j                  j                  d      t	                t               }t        | t        j                        r| |d<   t        |t        j                        r||d<   t        |t        j                        r||d<   t        |t        j                        r||d<   t        |t        t        f      r||d<   t        j                  t        |       t	                y)a  Set the keyword-value pairs in `~/.plotly_credentials`.

    :param (str) username: The username you'd use to sign in to Plotly
    :param (str) api_key: The api key associated with above username
    :param (list) stream_ids: Stream tokens for above credentials
    :param (str) proxy_username: The un associated with with your Proxy
    :param (str) proxy_password: The pw associated with your Proxy un

    <You don't have proper file permissions to run this function.usernameapi_keyproxy_usernameproxy_password
stream_idsN)r   _plotly_utils
exceptionsPlotlyErrorr"   get_credentials_file
isinstancesixstring_typesr   tupler   r   r	   )r%   r&   r)   r'   r(   credentialss         r   set_credentials_filer3   S   s      &'&&22M
 	
 &(K(C,,-"*J'3++,!(I.#"2"23(6$%.#"2"23(6$%*tUm,$.L!	);7r   c                  ~    t        j                  t        g|  }|s t        j                  t        t                 }|S )zReturn specified args from `~/.plotly_credentials`. as dict.

    Returns all if no arguments are specified.

    Example:
        get_credentials_file('username')

    )r   r   r	   r   r
   )argsr2   s     r   r-   r-   w   s7     &&'7?$?Kii-= >?r   c                  `    t                t        j                  t        i        t                y N)r"   r   r   r	   r   r   r   reset_credentials_filer8      s    	)2.r   c                 2   t               st        j                  j                  d      t	                t        j                  ||d       t               }t        | t        j                        r| |d<   n| t        d      t        |t        j                        r||d<   n|t        d      t        |t        j                        r||d<   n|t        d	      t        |t        j                  t        f      r||d
<   n|t        d      t        |t        j                  t        f      r||d<   n|t        d      t        |t              r||d<   n|t        d      t        j                  | |d       t        |t              r||d<   |j                  d       n|t        d      t        |t        j                        r||d<   n|t        d      t        j                  |       t        j                   t"        |       t	                y)a  Set the keyword-value pairs in `~/.plotly/.config`.

    :param (str) plotly_domain: ex - https://plotly.com
    :param (str) plotly_streaming_domain: ex - stream.plotly.com
    :param (str) plotly_api_domain: ex - https://api.plotly.com
    :param (bool) plotly_ssl_verification: True = verify, False = don't verify
    :param (bool) plotly_proxy_authorization: True = use plotly proxy auth creds
    :param (bool) world_readable: True = public, False = private

    r$   )sharingworld_readableplotly_domainNz plotly_domain should be a stringplotly_streaming_domainz*plotly_streaming_domain should be a stringplotly_api_domainz$plotly_api_domain should be a stringplotly_ssl_verificationz+plotly_ssl_verification should be a booleanplotly_proxy_authorizationz.plotly_proxy_authorization should be a boolean	auto_openzauto_open should be a boolean)r<   r>   r;   r:   zInput should be a booleanzsharing should be a string)r   r*   r+   r,   r"   r   ,validate_world_readable_and_sharing_settingsget_config_filer.   r/   r0   	TypeErrorboolvalidate_plotly_domainspopset_sharing_and_world_readabler   r   )	r<   r=   r>   r?   r@   r;   r:   rA   settingss	            r   set_config_filerJ      s    ( &'&&22M
 	
 	66~>  H-!1!12$1!		":;;)3+;+;<.E*+	 	,DEE#S%5%56(9$%		&>??)C,<,<d+CD.E*+	 	,EFF,s/?/?.FG1K-.	#	/HII)T" )		788 
!!'>OP .$'%3!"Y		#344'3++,%		455	((2	h/r   c                  ~    t        j                  t        g|  }|s t        j                  t        t                 }|S )zReturn specified args from `~/.plotly/.config`. as tuple.

    Returns all if no arguments are specified.

    Example:
        get_config_file('plotly_domain')

    )r   r   r   r   r
   )r5   configs     r   rC   rC      s4     !!+55F<45Mr   c                  l    t                t        t        d      } | j                          t                y )Nw)r"   openr   close)fs    r   reset_config_filerR      s#    [#AGGIr   c                    t        j                         j                  d      xs t               d   }|| }|d t	        |       |k7  r/t
        j                  j                  dj                  ||            t        j                  j                  j                  j                  |      }|j                  j                  d      d   j                  d      d   }|j                  j                  d      d   }t        j                  j                  j                  j!                  |j"                        }|r	|d   d   }nd	}n| }d	}	 t%        |      }t%        |      dk  rt
        j                  j                  d      |d	u rdj                  |||      S dj                  ||||      S # t&        $ r  t
        j                  j                  d
      w xY w)Nr<   zBecause you didn't supply a 'file_id' in the call, we're assuming you're trying to snag a figure from a url. You supplied the url, '{0}', we expected it to start with '{1}'.
Run help on this function for more information./   ~   	share_key zThe 'file_id' argument was not able to be converted into an integer number. Make sure that the positional 'file_id' argument is a number that can be converted into an integer or a string that can be converted into an integer.r   z5The 'file_id' argument must be a non-negative number.z/{plotly_rest_url}/~{file_owner}/{file_id}.embed)plotly_rest_url
file_ownerfile_idzE{plotly_rest_url}/~{file_owner}/{file_id}.embed?share_key={share_key})r[   r\   r]   rX   )r   get_session_configgetrC   lenr*   r+   r,   formatr/   movesurllibparseurlparsepathsplitparse_qsqueryint
ValueError)	file_owner_or_urlr]   r[   urlurlsplitr\   
query_dictrX   test_if_ints	            r   _get_embed_urlrq      s   ""$((9 	._-  %_%&/9**66
 6#/  99##))2237]]((-a066s;A>
--%%c*1- YY%%++44X^^D
";/3II&
	
'l 7|a&&22C
 	
 B@GG+
G H 
 	

 W
&+!	  
	
#  
&&225
 	

s   	F. .)Gc                 B    t        | |      }dj                  |||      S )a  Returns HTML code to embed figure on a webpage as an <iframe>

    Plotly uniquely identifies figures with a 'file_owner'/'file_id' pair.
    Since each file is given a corresponding unique url, you may also simply
    pass a valid plotly url as the first argument.

    Note, if you're using a file_owner string as the first argument, you MUST
    specify a `file_id` keyword argument. Else, if you're using a url string
    as the first argument, you MUST NOT specify a `file_id` keyword argument,
    or file_id must be set to Python's None value.

    Positional arguments:
    file_owner_or_url (string) -- a valid plotly username OR a valid plotly url

    Keyword arguments:
    file_id (default=None) -- an int or string that can be converted to int
                              if you're using a url, don't fill this in!
    width (default="100%") -- an int or string corresp. to width of the figure
    height (default="525") -- same as width but corresp. to the height of the
                              figure

    z<iframe id="igraph" scrolling="no" style="border:none;" seamless="seamless" src="{embed_url}" height="{iframe_height}" width="{iframe_width}"></iframe>)	embed_urliframe_heightiframe_width)rq   ra   )rl   r]   widthheightrs   s        r   	get_embedrx   1  s.    . 0':I	
 fyUfKLr   c                    	 t        | |||      }t        rt        j                  |d      S 	 t        rn|rGt	        j
                         j                  d      xs t               d   }dj                  || |      }n| }t        ||      }t        j                  |||      S t               d   t	        j
                         d   k7  rd}nd}t        j                  d	j                  |             y
#  Y xY w)a  Embeds existing Plotly figure in IPython Notebook

    Plotly uniquely identifies figures with a 'file_owner'/'file_id' pair.
    Since each file is given a corresponding unique url, you may also simply
    pass a valid plotly url as the first argument.

    Note, if you're using a file_owner string as the first argument, you MUST
    specify a `file_id` keyword argument. Else, if you're using a url string
    as the first argument, you MUST NOT specify a `file_id` keyword argument,
    or file_id must be set to Python's None value.

    Positional arguments:
    file_owner_or_url (string) -- a valid plotly username OR a valid plotly url

    Keyword arguments:
    file_id (default=None) -- an int or string that can be converted to int
                              if you're using a url, don't fill this in!
    width (default="100%") -- an int or string corresp. to width of the figure
    height (default="525") -- same as width but corresp. to the height of the
                              figure

    )r]   rv   rw   F)hider<   z{plotly_domain}/~{un}/{fid})r<   unfidzVisit support.plotly.comz)Contact your On-Premise account executivezLooks like you're not using IPython or Sage to embed this plot. If you just want the *embed code*,
try using `get_embed()` instead.
Questions? {}N)rx   r   htmlipython_core_displayr   r^   r_   rC   ra   rq   ipython_displayIFramer   r   r   )	rl   r]   rv   rw   sr<   rm   rs   feedback_contacts	            r   embedr   S  s   .'fU ##AE#22  **,00A 6"$_5  066+0Aw 7 C $C"30	%%i??  !/2))+O<=  :  K %f%56		
7s   +C2 2C6)NNNNN)NNNNNNNNr7   )Nz100%i  )!__doc__
__future__r   r   r/   r   r*   r   _plotly_utils.exceptions_plotly_utils.filesr   chart_studior   r   chart_studio.filesr   r	   r
   
get_moduler~   r   r   r   r"   r3   r-   r8   rJ   rC   rR   rq   rx   r   r   r   r   <module>r      s    '  
  *  : ' J J2'223IJ -"--.?@)))-8
+"
R ! H$    #H V$ 7
tLD=
r   