o
    i                  
   @   s  d Z ddlmZm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mZmZmZ dd	lmZmZmZmZ d
dlmZmZ eeZeddZejddd		d,dedeeejddf ddfddZejddd	d-deee  ejddf ddfddZ!dee  fddZ"ejdd d		d,deee  ejd!df deeejddf ddfd"d#Z#ejd$d%dd.d&d'Z$ejd(d)dd.d*d+Z%dS )/a  Contains commands to authenticate to the Hugging Face Hub and interact with your repositories.

Usage:
    # login and save token locally.
    hf auth login --token=hf_*** --add-to-git-credential

    # switch between tokens
    hf auth switch

    # list all tokens
    hf auth list

    # logout from all tokens
    hf auth logout

    # check which account you are logged in as
    hf auth whoami
    )	AnnotatedOptionalN)ENDPOINT)HfHubHTTPError)whoami   )	auth_listauth_switchloginlogout)ANSIget_stored_tokens	get_tokenlogging   )TokenOpttyper_factoryz,Manage authentication (login, logout, etc.).)helpr
   z7Login using a token from huggingface.co/settings/tokensFtokenadd_to_git_credentialzTSave to git credential helper. Useful only if you plan to run git commands directly.returnc                 C   s   t | |d d S )Nr   r   )r
   r    r   ^/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/huggingface_hub/cli/auth.py
auth_login4   s   
r   r   zLogout from a specific token
token_namezName of token to logoutc                 C   s   t | d d S )Nr   )r   r   r   r   r   auth_logoutA   s   	r   c                  C   s   t t  } | std d S td t| dD ]\}}t| d|  q	 z,td}| dkr6W d S t	|d }d|  krHt
| k rOn n| | W S td	 W n tya   td
 Y nw q()Nz+No stored tokens found. Please login first.zAvailable stored tokens:r   z. Tz=Enter the number of the token to switch to (or 'q' to quit): qr   z$Invalid selection. Please try again.z4Invalid input. Please enter a number or 'q' to quit.)listr   keysloggererrorprint	enumerateinputlowerintlen
ValueError)token_namesir   choiceindexr   r   r   _select_token_nameM   s(   

r.   switchzSwitch between access tokenszName of the token to switch toc                 C   s6   | d u rt  } | d u rtd t t| |d d S )Nz!No token name provided. Aborting.)r   )r.   r#   typerExitr	   )r   r   r   r   r   auth_switch_cmde   s   r2   r   zList all stored access tokensc                   C   s
   t   d S N)r   r   r   r   r   auth_list_cmd|   s   
r4   r   z;Find out which huggingface.co account you are logged in as.c               
   C   s   t  } | d u rtd t z5t| }ttd|d  dd |d D }|r4ttdd| td	krBtd
t  W d S W d S  t	yc } zt| tt
|jj tjddd }~ww )NzNot logged inzuser: namec                 S   s   g | ]}|d  qS )r5   r   ).0orgr   r   r   
<listcomp>   s    zauth_whoami.<locals>.<listcomp>orgszorgs: ,zhttps://huggingface.coz(Authenticated through private endpoint: r   )code)r   r#   r0   r1   r   r   boldjoinr   r   redresponsetext)r   infor9   er   r   r   auth_whoami   s&   rC   )NFr3   )r   N)&__doc__typingr   r   r0   huggingface_hub.constantsr   huggingface_hub.errorsr   huggingface_hub.hf_apir   _loginr   r	   r
   r   utilsr   r   r   r   
_cli_utilsr   r   
get_logger__name__r!   auth_clicommandboolOptionr   strr   r.   r2   r4   rC   r   r   r   r   <module>   s   

