
    chlN                    ^   % S SK Jr  S SKrS SKrS SKJrJrJrJrJ	r	  S SK
Jr  S SKJrJrJrJr  S SKJr  S SKrS SKJrJr  S SKJrJr  S S	KJr  \" \5      rS
\S'    " S S5      r\" 5       r S
\S'   SS jr!SS jr"SS jr# " S S\\$\4   5      r% " S S\\$\4   5      r&\&" 5       r'S
\S'   g)    )annotationsN)	ItemsViewIteratorKeysViewMapping
ValuesView)deepcopy)AnyCallableFinalNoReturn)Signal)configruntime)StreamlitMaxRetriesErrorStreamlitSecretNotFoundError)
get_loggerr   _LOGGERc                      \ rS rSrSrSS jrSS jrSS jrSS jr    SS jr	    SS jr
SS	 jrSS
 jrSS jrSS jrSS jrSS jrSS jrSrg)SecretErrorMessages&   a  SecretErrorMessages stores all error messages we use for secrets to allow customization
for different environments.

For example Streamlit Cloud can customize the message to be different than the open source.

For internal use, may change in future releases without notice.
c                d    S U l         S U l        S U l        S U l        S U l        S U l        g )Nc                    SU  S3$ )Nzst.secrets has no attribute "". Did you forget to add it to secrets.toml, mount it to secret directory, or the app settings on Streamlit Cloud? More info: https://docs.streamlit.io/deploy/streamlit-community-cloud/deploy-your-app/secrets-management 	attr_names    lC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\streamlit/runtime/secrets.py<lambda>.SecretErrorMessages.__init__.<locals>.<lambda>0   s    +I; 7l l    c                    SU  S3$ )Nzst.secrets has no key "r   r   keys    r   r   r    6   s    %cU +l lr!   c                *    SSR                  U 5       3$ )NzQNo secrets found. Valid paths for a secrets.toml file or secret directories are: z, )join)
file_pathss    r   r   r    <   s    _`d`i`ijt`u_vwr!   c                    SU  SU 3$ )NzError parsing secrets file at z: r   )pathexs     r   r   r    @   s    =dV2bTJr!   c                    U  S3$ )Nzn is not a folder. To use directory based secrets, mount every secret in a subfolder under the secret directoryr   )sub_folder_paths    r   r   r    C   s    "# $o or!   c                    SU  S3$ )NzInvalid secrets path: z): path is not a .toml file or a directoryr   )r)   s    r   r   r    H   s    $TF*STr!   )missing_attr_messagemissing_key_messageno_secrets_founderror_parsing_file_at_pathsubfolder_path_is_not_a_folderinvalid_secret_pathselfs    r   __init__SecretErrorMessages.__init__/   sE    ;
!:
 =
 K 	' 	+:
 r!   c                    Xl         g)z(Set the missing attribute error message.Nr.   r5   messages     r   set_missing_attr_message,SecretErrorMessages.set_missing_attr_messageL   s    $+!r!   c                    Xl         g)z"Set the missing key error message.Nr/   r:   s     r   set_missing_key_message+SecretErrorMessages.set_missing_key_messageP       #* r!   c                    Xl         g)z'Set the no secrets found error message.Nr0   r:   s     r   set_no_secrets_found_message0SecretErrorMessages.set_no_secrets_found_messageT   s     'r!   c                    Xl         g)z1Set the error parsing file at path error message.Nr1   r:   s     r   &set_error_parsing_file_at_path_message:SecretErrorMessages.set_error_parsing_file_at_path_messageX   s
     +2'r!   c                    Xl         g)z5Set the subfolder path is not a folder error message.Nr2   r:   s     r   *set_subfolder_path_is_not_a_folder_message>SecretErrorMessages.set_subfolder_path_is_not_a_folder_message^   s
     /6+r!   c                    Xl         g)z*Set the invalid secret path error message.Nr3   r:   s     r   set_invalid_secret_path_message3SecretErrorMessages.set_invalid_secret_path_messaged   rB   r!   c                $    U R                  U5      $ )z(Get the missing attribute error message.r9   )r5   r   s     r   get_missing_attr_message,SecretErrorMessages.get_missing_attr_messageh   s    ((33r!   c                $    U R                  U5      $ )z"Get the missing key error message.r?   r5   r$   s     r   get_missing_key_message+SecretErrorMessages.get_missing_key_messagel   s    '',,r!   c                $    U R                  U5      $ )z'Get the no secrets found error message.rD   )r5   r'   s     r   get_no_secrets_found_message0SecretErrorMessages.get_no_secrets_found_messagep   s    $$Z00r!   c                $    U R                  X5      $ )z1Get the error parsing file at path error message.rH   )r5   r)   r*   s      r   &get_error_parsing_file_at_path_message:SecretErrorMessages.get_error_parsing_file_at_path_messaget   s    ..t88r!   c                $    U R                  U5      $ )z5Get the subfolder path is not a folder error message.rL   )r5   r,   s     r   *get_subfolder_path_is_not_a_folder_message>SecretErrorMessages.get_subfolder_path_is_not_a_folder_messagex   s    22?CCr!   c                $    U R                  U5      $ )z*Get the invalid secret path error message.rP   )r5   r)   s     r   get_invalid_secret_path_message3SecretErrorMessages.get_invalid_secret_path_message|   s    ''--r!   )r1   r3   r.   r/   r0   r2   NreturnNone)r;   zCallable[[str], str]rg   rh   )r;   zCallable[[list[str]], str]rg   rh   )r;   zCallable[[str, Exception], str]rg   rh   r   strrg   rj   r$   rj   rg   rj   )r'   z	list[str]rg   rj   )r)   rj   r*   	Exceptionrg   rj   )r,   rj   rg   rj   )r)   rj   rg   rj   )__name__
__module____qualname____firstlineno____doc__r6   r<   r@   rE   rI   rM   rQ   rT   rX   r[   r^   ra   rd   __static_attributes__r   r!   r   r   r   &   si    
:,+(262	26+6	6+4-19D.r!   r   secret_error_messages_singletonc           	         [        U [        5      (       a  U R                  5       $ U R                  5        VVs0 s H-  u  pU[        U[        5      (       a  UR                  5       OU_M/     snn$ s  snnf )z4Convert Mapping or AttrDict objects to dictionaries.)
isinstanceAttrDictto_dictitems)objkvs      r   _convert_to_dictr|      sT    #x  {{}ILUAjH55qyy{1<UUUs   4A1c                ,    [         R                  U 5      $ N)rs   rT   r   s    r   _missing_attr_error_messager      s    *CCINNr!   c                ,    [         R                  U 5      $ r~   )rs   rX   r#   s    r   _missing_key_error_messager      s    *BB3GGr!   c                      \ rS rSrSrSS jr\SS j5       rSS jrSS jr	SS jr
SS jrSS	 jrSS
 jrSS jrSS jrSrg)rv      zcWe use AttrDict to wrap up dictionary values from secrets
to provide dot access to nested secrets.
c                4    [        U5      U R                  S'   g )N__nested_secrets__)dict__dict__)r5   values     r   r6   AttrDict.__init__   s    .25k*+r!   c                F    [        U [        5      (       d  U $ [        U 5      $ r~   )ru   r   rv   )r   s    r   _maybe_wrap_in_attr_dict!AttrDict._maybe_wrap_in_attr_dict   s    %))Lr!   c                ,    [        U R                  5      $ r~   )lenr   r4   s    r   __len__AttrDict.__len__   s    4**++r!   c                ,    [        U R                  5      $ r~   )iterr   r4   s    r   __iter__AttrDict.__iter__       D++,,r!   c                     U R                   U   nU R                  U5      $ ! [         a    [        [        U5      5      ef = fr~   )r   r   KeyErrorr   r5   r$   r   s      r   __getitem__AttrDict.__getitem__   sH    	<++C0E0077 	<5c:;;	<	   " Ac                     U R                   U   nU R                  U5      $ ! [         a    [        [	        U5      5      ef = fr~   )r   r   r   AttributeErrorr   )r5   r   r   s      r   __getattr__AttrDict.__getattr__   sK    	I++I6E0077 	I !<Y!GHH	Ir   c                ,    [        U R                  5      $ r~   )reprr   r4   s    r   __repr__AttrDict.__repr__   r   r!   c                    [        S5      e)Nz)Secrets does not support item assignment.	TypeErrorr   s      r   __setitem__AttrDict.__setitem__   s    CDDr!   c                    [        S5      e)N.Secrets does not support attribute assignment.r   r   s      r   __setattr__AttrDict.__setattr__   s    HIIr!   c                ,    [        U R                  5      $ r~   )r	   r   r4   s    r   rw   AttrDict.to_dict   s    //00r!   r   N)r   Mapping[str, Any]rg   rh   )r   r
   rg   r
   rg   intrg   zIterator[str]r$   rj   rg   r
   )r   rj   rg   r
   rg   rj   )r$   rj   r   r
   rg   r   rg   dict[str, Any])rm   rn   ro   rp   rq   r6   staticmethodr   r   r   r   r   r   r   r   rw   rr   r   r!   r   rv   rv      sK    :  
,-<I-EJ1r!   rv   c                  2  ^  \ rS rSrSrSS jrSS jr    SS jrSS jrSS jr	SS jr
SS	 jrS S
 jrS!S jr\S"S j5       r\S"S j5       rSS jrS#S jrS$S jrS$S jrS%U 4S jjrS&S jrS'S jrS(S jrS)S jrS*S jrS+S jrS,S jrS-S jrSrU =r$ ).Secrets   zA dict-like class that stores secrets.
Parses secrets.toml on-demand. Cannot be externally mutated.

Safe to use from multiple threads.
c                p    S U l         [        R                  " 5       U l        SU l        [        SS9U l        g )NFz4Emitted when a `secrets.toml` file has been changed.)doc)_secrets	threadingRLock_lock_file_watchers_installedr   file_change_listenerr4   s    r   r6   Secrets.__init__   s/    26__&
(-%$*F%
!r!   c                F     U R                  5         g! [         a     gf = f)a   Load secrets.toml files from disk if they exists. If none exist,
no exception will be raised. (If a file exists but is malformed,
an exception *will* be raised.).

Returns True if a secrets.toml file was successfully parsed, False otherwise.

Thread-safe.
TF)_parser   r4   s    r   load_if_toml_existsSecrets.load_if_toml_exists   s%    	KKM+ 		s    
  c                    g)zYLeft in place for compatibility with integrations until integration
code can be updated.
Nr   )r5   !suppress_print_error_on_exceptions     r   %set_suppress_print_error_on_exception-Secrets.set_suppress_print_error_on_exception   s     	r!   c                    U R                      U R                  c
   SSS5        gU R                  R                  5        H  u  pU R                  X5        M     SU l        SSS5        g! , (       d  f       g= f)zaClear the secrets dictionary and remove any secrets that were
added to os.environ.

Thread-safe.
N)r   r   rx   "_maybe_delete_environment_variable)r5   rz   r{   s      r   _resetSecrets._reset   sY     ZZ}}$ Z ++-77= . DM ZZs   A);A))
A7c                n   0 nSn [        USS9 nUR                  5       nSSS5        Sn SSKnUR	                  UR                  W5      5        X#4$ ! , (       d  f       N8= f! [         a    0 S4s $ f = f! [        WR                  4 a&  n[        R                  X5      n[        U5      UeSnAff = f)z9Parse a TOML file and return the secrets as a dictionary.Fzutf-8)encodingNTr   )openreadFileNotFoundErrortomlupdateloadsr   TomlDecodeErrorrs   r^   r   )	r5   r)   secretsfound_secrets_filefsecrets_file_strr   r*   msgs	            r   _parse_toml_fileSecrets._parse_toml_file   s    "	dW-#$668  . "&

	<NN4::&678 **) .- ! 	u9	 4//0 	</VV 
 /s3;	<s>   
A$ A
A$ $A8 
A!A$ $A54A58B4!B//B4c                   0 nSn[         R                  " U5       GH>  n[         R                  R                  X5      n[         R                  R	                  U5      (       d   [
        R                  U5      n[        U5      e0 n[         R                  " U5       H~  n[         R                  R                  XX5      n	[         R                  R	                  U	5      (       a  MH  [        U	5       n
U
R                  5       R                  5       Xx'   SnSSS5        M     [        U5      S:X  a*  U[        [        UR                  5       5      5         X$'   GM:  XrU'   GMA     X#4$ ! , (       d  f       M  = f)a  Parse a directory for secrets. Directory style can be used to support Kubernetes secrets that are
mounted to folders.

Example structure:
- top_level_secret_folder
    - user_pass_secret (folder)
        - username (file), content: myuser
        - password (file), content: mypassword
    - my_plain_secret (folder)
        - regular_secret (file), content: mysecret

See: https://kubernetes.io/docs/tasks/inject-data-application/distribute-credentials-secure/#create-a-pod-that-has-access-to-the-secret-data-through-a-volume
And: https://docs.snowflake.com/en/developer-guide/snowpark-container-services/additional-considerations-services-jobs#passing-secrets-in-local-container-files
FTN   )oslistdirr)   r&   isdirrs   ra   r   r   r   stripr   nextr   keys)r5   r)   r   r   dirnamer,   	error_msgsub_secretsfilename	file_pathr   s              r   _parse_directorySecrets._parse_directory  s    #%"zz$'G ggll49O77==11;ff#	 39==KJJ7GGLLC	 77==++)_,-FFHNN,<K))-& %_ 8 ;1$#.tD9I9I9K4L/M#N #. 1 (4 ** %_s   -#E!!
E0c                    UR                  S5      (       a  U R                  U5      $ [        R                  R	                  U5      (       a  U R                  U5      $ [        R                  U5      n[        U5      e)N.toml)	endswithr   r   r)   r   r   rs   rd   r   )r5   r)   r   s      r   _parse_file_pathSecrets._parse_file_pathD  sf    ==!!((..77==((..3SS
	 +955r!   c                @   U R                   nUb  U$ U R                     U R                   b  U R                   sSSS5        $ 0 n[        R                  " S5      nSnU H2  nU R	                  U5      u  pVU=(       d    UnUR                  U5        M4     U(       d   [        R                  U5      n[        U5      eUR                  5        H  u  pU R                  X5        M     Xl         U R                  5         U R                   sSSS5        $ ! , (       d  f       g= f)aT  Parse our secrets.toml files if they're not already parsed.
This function is safe to call from multiple threads.

Parameters
----------
print_exceptions : bool
    If True, then exceptions will be printed with `st.error` before
    being re-raised.

Raises
------
    StreamlitSecretNotFoundError
    Raised if secrets.toml doesn't exist.

Nsecrets.filesF)r   r   r   
get_optionr   r   rs   r[   r   rx   _maybe_set_environment_variable_maybe_install_file_watchers)
r5   r   r'   r   r)   path_secretsfound_secrets_file_in_pathr   rz   r{   s
             r   r   Secrets._parseP  s    $ --NZZ}}(}} Z G**?;J!&";?;P;PQU;V8%7%U;U"|, #
 &3PP" 
 39==44Q: ( $M--/==7 ZZs   DCD
Dc                8    U R                  5       n[        U5      $ )zyConverts the secrets store into a nested dictionary, where nested AttrDict objects are
also converted into dictionaries.
)r   r|   )r5   r   s     r   rw   Secrets.to_dict  s     ++-((r!   c                ~    [        U5      nU[        [        [        4;   a  [        U5      [        R
                  U '   gg)zTAdd the given key/value pair to os.environ if the value
is a string, int, or float.
N)typerj   r   floatr   environrz   r{   
value_types      r   r   'Secrets._maybe_set_environment_variable  s2    
 !W
#sE**FBJJqM +r!   c                    [        U5      nU[        [        [        4;   a6  [        R
                  R                  U 5      U:X  a  [        R
                  U 	 ggg)zYRemove the given key/value pair from os.environ if the value
is a string, int, or float.
N)r   rj   r   r   r   r  getr  s      r   r   *Secrets._maybe_delete_environment_variable  sD    
 !W
#sE**rzz~~a/@A/E

1 0F*r!   c                   U R                      U R                  (       a
   S S S 5        g [        R                  " S5      nU H  n UR	                  S5      (       a5  [
        R                  R                  R                  UU R                  SS9  MO  [
        R                  R                  R                  UU R                  SS9  M     SU l        S S S 5        g ! [        [        4 a     M  f = f! , (       d  f       g = f)Nr   r   poll)watcher_typeT)r   r   r   r   r   	streamlitwatcherpath_watcher
watch_file_on_secrets_changed	watch_dirr   r   )r5   r'   r)   s      r   r   $Secrets._maybe_install_file_watchers  s    ZZ,, Z  **?;J"}}W--!))66AA  44)/ B  "))66@@  44)/ A  #, -1D)7 Z& 12CD  	' ZsA   C.C.A	CC.3CC.C+'C.*C++C..
C<c                    U R                      [        R                  SU5        U R                  5         U R	                  5         S S S 5        U R
                  R                  5         g ! , (       d  f       N)= f)Nz!Secret path %s changed, reloading)r   r   debugr   r   r   send)r5   changed_file_paths     r   r  Secrets._on_secrets_changed  sL    ZZMM=?PQKKMKKM  	!!&&( Zs   7A''
A5c                     U R                  5       U   n[        U[        5      (       d  U$ [        U5      $ ! [        [
        4 a    [        [        U5      5      ef = f)zcReturn the value with the given key. If no such key
exists, raise an AttributeError.

Thread-safe.
)r   ru   r   rv   r   r   r   r   r   s      r   r   Secrets.__getattr__  s^    		CKKM#&EeW--E?" +, 	C !<S!ABB	Cs   )7 
7 %Ac                     U R                  5       U   n[        U[        5      (       d  U$ [        U5      $ ! [         a    [	        [        U5      5      ef = f)z\Return the value with the given key. If no such key
exists, raise a KeyError.

Thread-safe.
)r   ru   r   rv   r   r   r   s      r   r   Secrets.__getitem__  sS    	<KKM#&EeW--E?" 	<5c:;;	<s   )7 
7 Ac                F   > US;   a  [         TU ]  X5        g [        S5      e)N>   r   r   r   r   r   "_suppress_print_error_on_exceptionr   )superr   r   )r5   r$   r   	__class__s      r   r   Secrets.__setattr__  s+     
 
 G+LMMr!   c                    [         R                  " 5       (       d  U R                  R                   $ [	        U R                  5       5      $ )zAA string representation of the contents of the dict. Thread-safe.)r   existsr  rm   r   r   r4   s    r   r   Secrets.__repr__  s5     ~~nn--./DKKM""r!   c                4    [        U R                  5       5      $ )z/The number of entries in the dict. Thread-safe.)r   r   r4   s    r   r   Secrets.__len__  s    4;;=!!r!   c                &    XR                  5       ;   $ z2True if the given key is in the dict. Thread-safe.r   )r5   rz   s     r   has_keySecrets.has_key  s    KKM!!r!   c                >    U R                  5       R                  5       $ )z,A view of the keys in the dict. Thread-safe.)r   r   r4   s    r   r   Secrets.keys  s    {{}!!##r!   c                >    U R                  5       R                  5       $ )z.A view of the values in the dict. Thread-safe.)r   valuesr4   s    r   r-  Secrets.values  s    {{}##%%r!   c                >    U R                  5       R                  5       $ )z7A view of the key-value items in the dict. Thread-safe.)r   rx   r4   s    r   rx   Secrets.items  s    {{}""$$r!   c                &    XR                  5       ;   $ r&  r'  rW   s     r   __contains__Secrets.__contains__  s    kkm##r!   c                4    [        U R                  5       5      $ )z3An iterator over the keys in the dict. Thread-safe.)r   r   r4   s    r   r   Secrets.__iter__  s    DKKM""r!   )r   r   r   r   rf   )rg   bool)r   r6  rg   rh   )r)   rj   rg   ztuple[Mapping[str, Any], bool])rg   r   r   )rz   r
   r{   r
   rg   rh   )r  rj   rg   rh   r   )r$   rj   r   r
   rg   rh   r   r   )rz   rj   rg   r6  )rg   zKeysView[str])rg   zValuesView[Any])rg   zItemsView[str, Any])r$   r
   rg   r6  r   ) rm   rn   ro   rp   rq   r6   r   r   r   r   r   r   r   rw   r   r   r   r   r  r   r   r   r   r   r(  r   r-  rx   r2  r   rr   __classcell__)r  s   @r   r   r      s    
"15	!+8,+\
61!f) # #  1<)C"<N#""$&%$# #r!   r   secrets_singleton)ry   zMapping[str, Any] | AttrDictrg   r   ri   rk   )(
__future__r   r   r   collections.abcr   r   r   r   r   copyr	   typingr
   r   r   r   blinkerr   streamlit.watcher.path_watcherr  r   r   streamlit.errorsr   r   streamlit.loggerr   rm   r   __annotations__r   rs   r|   r   r   rj   rv   r   r8  r   r!   r   <module>rB     s    # 	  N N    % % S 'H% %X. X.v *=)>  >VOH,1wsCx  ,1^S#gc3h S#l
 #9 5 $r!   