o
    Zh                     @   sN   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
 d
Z
dS )zAContain helper class to retrieve/store token from/to local cache.    N)Path)Optional   )	constants   )	get_tokenc                   @   sf   e Zd ZeejZeejZe	de
ddfddZe	dee
 fddZe	ddd	Ze	d
d ZdS )HfFoldertokenreturnNc                 C   s"   | j jjddd | j | dS )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	    r   W/var/www/html/lang_env/lib/python3.10/site-packages/huggingface_hub/utils/_hf_folder.py
save_token    s   zHfFolder.save_tokenc                 C   s(   z|    W t S  ty   Y t S 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   r   r   r   r   1   s   
zHfFolder.get_tokenc                 C   sH   z| j   W n	 ty   Y nw z| j  W dS  ty#   Y dS w )zX
        Deletes the token from storage. Does not fail if token does not exist.
        N)r   unlinkFileNotFoundError_old_path_tokenr   r   r   r   delete_tokenF   s   zHfFolder.delete_tokenc                 C   sL   | j  r"| j s$| | j   td| j  d| j d d S d S d S )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   r   r   r   r   U   s   
z#HfFolder._copy_to_new_path_and_warn)r
   N)__name__
__module____qualname__r   r   ZHF_TOKEN_PATHr   Z_OLD_HF_TOKEN_PATHr   classmethodstrr   r   r   r   r   r   r   r   r   r      s    

r   )__doc__r   pathlibr   typingr    r   _tokenr   r   r   r   r   r   <module>   s   