
    g                     T    d 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	  G d	 d
      Z
y)zAContain helper class to retrieve/store token from/to local cache.    N)Path)Optional   )	constants   )	get_tokenc                       e Zd Z eej
                        Z eej                        Ze	de
ddfd       Ze	dee
   fd       Ze	dd       Ze	d        Zy)	HfFoldertokenreturnNc                     | j                   j                  j                  dd       | j                   j                  |       y)a  
        Save token, creating folder as needed.

        Token is saved in the huggingface home folder. You can configure it by setting
        the `HF_HOME` environment variable.

        Args:
            token (`str`):
                The token to save to the [`HfFolder`]
        T)parentsexist_okN)
path_tokenparentmkdir
write_text)clsr   s     U/var/www/openai/venv/lib/python3.12/site-packages/huggingface_hub/utils/_hf_folder.py
save_tokenzHfFolder.save_token    s3     	##D4#@!!%(    c                 h    	 | j                          t               S # t        $ r Y t               S w xY w)aB  
        Get token or None if not existent.

        This method is deprecated in favor of [`huggingface_hub.get_token`] but is kept for backward compatibility.
        Its behavior is the same as [`huggingface_hub.get_token`].

        Returns:
            `str` or `None`: The token, `None` if it doesn't exist.
        )_copy_to_new_path_and_warn	Exceptionr   r   s    r   r   zHfFolder.get_token1   s9    	**, {  	{	s    	11c                     	 | j                   j                          	 | j                  j                          y# t        $ r Y 'w xY w# t        $ r Y yw xY w)zX
        Deletes the token from storage. Does not fail if token does not exist.
        N)r   unlinkFileNotFoundError_old_path_tokenr   s    r   delete_tokenzHfFolder.delete_tokenF   sU    
	NN!!#	&&(	 ! 		
 ! 		s    8 A 	AA	AAc                 "   | j                   j                         ru| j                  j                         sZ| j                  | j                   j	                                t        j                  d| j                    d| j                   d       y y y )NzA token has been found in `zG`. This is the old path where tokens were stored. The new location is `z` which is configurable using `HF_HOME` environment variable. Your token has been copied to this new location. You can now safely delete the old token file manually or use `huggingface-cli logout`.)r   existsr   r   	read_textwarningswarnr   s    r   r   z#HfFolder._copy_to_new_path_and_warnU   s{    %%'0E0E0GNN3..88:;MM-c.A.A-B C^^$ %-- 1H'r   )r   N)__name__
__module____qualname__r   r   HF_TOKEN_PATHr   _OLD_HF_TOKEN_PATHr   classmethodstrr   r   r   r    r    r   r   r
   r
      s    i--.J9778O )s )t ) )  (3-  (   
 
r   r
   )__doc__r$   pathlibr   typingr    r   _authr   r
   r-   r   r   <module>r3      s&    H     G Gr   