
    &e3*                        d 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 ddlm	Z	 ddl
mZ ddlZddlZddlmZmZmZ ddlmZ  ee          Zej        rd	Znd
Z edddg          ZdefdZd ej        dd           ej        e          dz  ZdZd ej        ddd           ej        dd           ej        dd          dz  ZdeddfdZ G d  d!e           Z!dedefd"Z"d# Z#d$ Z$d% Z%d& Z&dS )'z(Manage the user's Streamlit credentials.    N)
namedtuple)datetime)Optional)uuid4)env_util	file_utilutil)
get_loggerz$%userprofile%/.streamlit/config.tomlz~/.streamlit/config.toml_Activationemailis_validreturnc                     t           j        j        dk    o+t          j         pt
          j                            d          } d                    | rdnd          t          j
        dd          t          j
        d	d
          dz  S )Nzutf-8
WT_SESSIONu   
      {0}%(welcome)s

      If you’d like to receive helpful onboarding emails, news, offers, promotions,
      and the occasional swag, please enter your email address below. Otherwise,
      leave this field blank.

      %(email)su   👋  zWelcome to Streamlit!TboldzEmail: bluefg)welcomer   )sysstdoutencodingr   
IS_WINDOWSosenvirongetformatclickstyle)
show_emojis    =lib/python3.11/site-packages/streamlit/runtime/credentials.pyemail_promptr$   1   s    
 $/ ?2:>>,#?#? 
 6%2  ;6TBBBY6222	 	     a  
  You can find our privacy policy at %(link)s

  Summary:
  - This open source library collects usage statistics.
  - We cannot see and do not store information contained inside Streamlit apps,
    such as text, charts, images, etc.
  - Telemetry data is stored in servers in the United States.
  - If you'd like to opt out, add the following to %(config)s,
    creating that file if necessary:

    [browser]
    gatherUsageStats = false
z#https://streamlit.io/privacy-policyT)	underline)linkconfigzT
Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.
z$
  %(start)s
  %(prompt)s %(hello)s
zGet started by typing:r   )r   r   $r   zstreamlit hellor   )startprompthelloc           
      z   ddl }| d| vrdS dddddd	d
}t          j                                                    dz   }dddddit	          t                                |d| ddd| dd	}|                    d|t          j        |          	                                          }|
                                 dS )z1Send the user's email to segment.io, if submittedr   N@zapi.segment.ioz*/*zen-US,en;q=0.9z
text/plainzlocalhost:8501zlocalhost:8501/)	authorityacceptzaccept-languagezcontent-typeoriginrefererz+00:00libraryzanalytics-pythonz2.2.2)nameversionsubmittedEmailprovided_email)authoremailsourcetrack iCkMy7ymtJ9qYzQRXkQpnAJEq7D4NyMU)	anonymous_idcontext	messageId	timestampeventtraitstypeuserIdwriteKeyzhttps://api.segment.io/v1/t)headersdata)requestsr   utcnow	isoformatstrr   postjsondumpsencoderaise_for_status)r   rG   rE   dtrF   responses         r#   _send_emailrR   l   s   OOO}5(( &+$"$ G 
			$	$	&	&	1B  2wGG
 \\! &
 
 6 D" }}%Z$$&&   H r%   c                       e Zd ZU dZdZed          ed<   ed             Zd Z	de
fdZddd	ZddZed             Zd ZddeddfdZdS )CredentialszCredentials class.N
_singletonc                 D    | j         t                       t          j         S )zReturn the singleton instance.)rU   rT   )clss    r#   get_currentzCredentials.get_current   s     >!MMM%%r%   c                     t           j        t          d          d| _        t	                      | _        | t           _        dS )zInitialize class.Nz;Credentials already initialized. Use .get_current() instead)rT   rU   RuntimeError
activation_get_credential_file_path
_conf_fileselfs    r#   __init__zCredentials.__init__   sD    !-M   355!%r%   r   c                 *    t          j        |           S N)r	   repr_r^   s    r#   __repr__zCredentials.__repr__   s    z$r%   Fc                    | j         t                              d           dS 	 t          | j        d          5 }t          j        |                              d          }ddd           n# 1 swxY w Y   |t          t          |                    d                    | _         dS # t          $ r, |r|                     |            Y dS t          d          t          $ rZ |r.|                                  |                     |            Y dS t          t          j        d          | j        z            w xY w)	zLoad from toml file.Nz/Credentials already loaded. Not rereading file.rgeneralr   )show_instructionsz7Credentials not found. Please run "streamlit activate".zz
                Unable to load credentials from %s.
                Run "streamlit reset" and try again.
                )r[   LOGGERerroropenr]   tomlloadr   	Exception_verify_emailFileNotFoundErroractivaterZ   resettextwrapdedent)r_   auto_resolvefrF   s       r#   rm   zCredentials.load   s   ?&LLJKKKF	dos++ 3qy||''	223 3 3 3 3 3 3 3 3 3 3 3 3 3 3|+DHHW,=,=>>DOOO  	 	 	 L0@AAAI    	 	 	 

L0@AAA  ?$  	s;   B+ (A."B+ .A22B+ 5A263B+ +#EAE*ETc                     	 |                      |           n:# t          t          f$ r&}t          t	          |                     Y d}~nd}~ww xY w| j        | j        j        st          d           dS dS )zTCheck if streamlit is activated.

        Used by `streamlit run script.py`
        NzActivation email not valid.)rm   rn   rZ   _exitrJ   r[   r   )r_   ru   es      r#   _check_activatedzCredentials._check_activated   s    
	IIl####<( 	 	 	#a&&MMMMMMMM	 ?"$/*B"/00000 #"s    AA

Ac                     t                                           }d|_        	 t          j        |j                   dS # t          $ r(}t                              d|z             Y d}~dS d}~ww xY w)zReset credentials by removing file.

        This is used by `streamlit activate reset` in case a user wants
        to start over.
        Nz#Error removing credentials file: %s)	rT   rX   r[   r   remover]   OSErrorri   rj   )rW   cry   s      r#   rr   zCredentials.reset   s     ##%%	DIal##### 	D 	D 	DLL>BCCCCCCCCC	Ds   = 
A/A**A/c                    ddl m} | j        dS t          j        t          j                            | j                  d           d| j        j        i}t          | j        d          5 }t          j        d|i|           ddd           n# 1 swxY w Y   	 t          | j        j                   dS # |$ r(}t                              d	|            Y d}~dS d}~ww xY w)
z!Save to toml file and send email.r   )RequestExceptionNT)exist_okr   wrg   zError saving email: )requests.exceptionsr   r[   r   makedirspathdirnamer]   r   rk   rl   dumprR   ri   rj   )r_   r   rF   rv   ry   s        r#   savezCredentials.save   s>   888888?"F 	BGOODO44tDDDD ./$/3'' 	,1Iy$'+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,	5-..... 	5 	5 	5LL333444444444	5s*   +BBBB6 6C#;CC#rh   c                    	 |                                   n# t          $ r Y nw xY w| j        r.| j        j        rt	          d           dS t	          d           dS d}|st          j        t                      ddd          }t          |          | _        | j        j        rK| 	                                 t          j
        t                     |rt          j
        t                     d}nt                              d           |dS dS )	zCActivate Streamlit.

        Used by `streamlit activate`.
        zAlready activatedzUActivation not valid. Please run `streamlit activate reset` then `streamlit activate`Fr   )textprompt_suffixdefaultshow_defaultTzPlease try again.N)rm   rZ   r[   r   rx   r    r+   r$   ro   r   secho_TELEMETRY_TEXT_INSTRUCTIONS_TEXTri   rj   )r_   rh   	activatedr   s       r#   rq   zCredentials.activate  sI   
	IIKKKK 	 	 	 D	
 ? 	6' )*****K    
 I 6%"$!&	   #0"6"6?+ 6IIKKKK000( 8$6777 $IILL!4555!   6 6 6 6 6s    
$$)F)r   N)T)__name__
__module____qualname____doc__rU   r   __annotations__classmethodrX   r`   rJ   rd   rm   rz   rr   r   boolrq    r%   r#   rT   rT      s         *.J'...& & [&
& 
& 
& #                 D1 1 1 1 D D [D5 5 5('6 '6$ '6$ '6 '6 '6 '6 '6 '6r%   rT   c                     |                                  } t          |           dk    rC|                     d          dk    r*t                              d           t          dd          S t          | d          S )ar  Verify the user's email address.

    The email can either be an empty string (if the user chooses not to enter
    it), or a string with a single '@' somewhere in it.

    Parameters
    ----------
    email : str

    Returns
    -------
    _Activation
        An _Activation object. Its 'is_valid' property will be True only if
        the email was validated.

    r   r.      z"That doesn't look like an email :(NFT)striplencountri   rj   r   )r   s    r#   ro   ro   0  sk    " KKMME 5zzA~~%++c**a//9:::4'''ud###r%   c                 b    t                               |            t          j        d           dS )zExit program with error.N)ri   rj   r   exit)messages    r#   rx   rx   L  s%    
LLHRLLLLLr%   c                  *    t          j        d          S )Nzcredentials.toml)r   get_streamlit_file_pathr   r%   r#   r\   r\   R  s    ,-?@@@r%   c                  X    t           j                            t                                S rb   )r   r   existsr\   r   r%   r#   _check_credential_file_existsr   V  s    7>>355666r%   c                     ddl m}  t                      sE|                     d          r0|                     d          st          j        t                     dS t          	                                
                                 dS )zCheck credentials and potentially activate.

    Note
    ----
    If there is no credential file and we are in headless mode, we should not
    check, since credential would be automatically set to an empty string.

    r   r(   zserver.headlesszbrowser.gatherUsageStatsN)	streamlitr(   r   
get_optionis_manually_setr    r   _TELEMETRY_HEADLESS_TEXTrT   rX   rz   r   s    r#   check_credentialsr   Z  s     !     (** v/@/@AR/S/S %%&@AA 	2K0111..00000r%   )'r   rL   r   r   rs   collectionsr   r   typingr   uuidr   r    rl   r   r   r   r	   streamlit.loggerr
   r   ri   r   _CONFIG_FILE_PATHr   rJ   r$   r!   r   r   r   rR   objectrT   ro   rx   r\   r   r   r   r%   r#   <module>r      s   / .  				 



  " " " " " "                     / / / / / / / / / / ' ' ' ' ' '	H		  3?2j c    4 EK=NNNek+,, $ 
 U[1f4HHHek#&)))U[*666  ) s ) t )  )  )  ) XU6 U6 U6 U6 U6& U6 U6 U6p$ $ $ $ $ $8  A A A7 7 71 1 1 1 1r%   