
    \j                         d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZ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 ddlmZmZ ddlmZ ddlmZmZ  ej@                  e!      Z" ed      Z#e#jI                  dg d      	 	 	 d1dedee% ed      f   dee% ed      f   ddfd       Z&e#jI                  dddg      	 d2dee'dz   ed      f   ddfd        Z(de'dz  fd!Z)e#jI                  d"d#d$g      	 	 d3dee'dz   ed%      f   dee% ed      f   ddfd&       Z*e#jI                  d'd(g      d4d)       Z+e#jI                  dd*d+g      d4d,       Z,e#jI                  d-d.d/g      d4d0       Z-y)5z^Contains commands to authenticate to the Hugging Face Hub and interact with your repositories.    )	AnnotatedN)ENDPOINT)whoami   )_save_oauth_token	auth_listauth_switchloginlogout)CLIError)get_stored_tokens	get_tokenloggingselect_choice)poll_device_tokenrequest_device_code   )TokenOpttyper_factory)Option)OutputFormatoutz,Manage authentication (login, logout, etc.).)helpr
   )zhf auth loginzhf auth login --token $HF_TOKENz7hf auth login --token $HF_TOKEN --add-to-git-credentialzhf auth login --force)examplestokenadd_to_git_credentialzTSave to git credential helper. Useful only if you plan to run git commands directly.forcez)Force re-login even if already logged in.returnc           	         | !t         j                  t        j                  k(  rt	        | ||        yt         j                  t        j
                  k7  rt        d      |s!t               t        j                  d       yt               }t        j                  d|d    d|d	    d
|d    d       t        |      }t        |      \  }}t        j                  d| d| d       y)zNLogin from your browser, or using a token from huggingface.co/settings/tokens.N)r   r   skip_if_logged_inzr`hf auth login` is interactive and does not support --format json/quiet. Pass --token for a non-interactive login.z;Already logged in. Use `hf auth login --force` to re-login.)agentzAsk the user to open verification_uri_completez! in a browser and enter the code 	user_codez. The code expires in 
expires_inz& seconds. Waiting for authorization...zLogin successful: logged in as z (token saved as 'z').)r   moder   humanr
   r!   r   r   textr   r   r   )r   r   r   device_inforesponse
token_nameusernames          K/root/.hermes/venv/lib/python3.12/site-packages/huggingface_hub/cli/auth.py
auth_loginr-   &   s    2 CHH(:(::E1F^cZcd xx<%%%8
 	
 Y[,TU%'KHH#K0K$L#MMn;'((>{<?X>Y Z++ !-H,X6JHH4XJ>PQ[P\\_`a    r   zhf auth logoutz$hf auth logout --token-name my-tokenr*   zName of token to logoutc                     t        |        y)zLogout from a specific token.r*   N)r   r0   s    r,   auth_logoutr1   \   s     j!r.   c                      t        t               j                               } | st        j	                  d       y t
        j                  t        j                  k7  rt        d      | t        d|          S )Nz+No stored tokens found. Please login first.z;Use --token-name to select a token in non-interactive mode.zSelect a token to switch to:)listr   keysloggererrorr   r%   r   r&   r   r   )token_namess    r,   _select_token_namer8   j   s]    (*//12KBC
xx<%%%TUU}%C[QRRr.   switchzhf auth switchz$hf auth switch --token-name my-tokenzName of the token to switch toc                     | 
t               } | )t        d       t        j                  j	                         t        | |       y)zSwitch between access tokens.Nz!No token name provided. Aborting.)r   )r8   printclick
exceptionsExitr	   )r*   r   s     r,   auth_switch_cmdr?   v   sA    & ')
12##%%
2GHr.   z	list | lszhf auth listc                      t                y)zList all stored access tokens.N)r    r.   r,   auth_list_cmdrB      s	     Kr.   zhf auth tokenz8hf auth token | xargs curl -H 'Authorization: Bearer {}'c                      t               } | 5t        j                  d       t        j                  j                  d      t        |        t        j                  d       y)z)Print the current access token to stdout.Nz)Not logged in. Run `hf auth login` first.r   codez@Run `hf auth whoami` to see which account this token belongs to.)r   r   r6   r<   r=   r>   r;   hint)r   s    r,   
auth_tokenrG      sK     KE}		=>###++	%LHHOPr.   r   zhf auth whoamizhf auth whoami --format jsonc                  4   t               } | 5t        j                  d       t        j                  j                  d      t        |       }dj                  d |d   D              xs d}t        dk7  rt        nd}t        j                  d	|d
   ||       y)z;Find out which huggingface.co account you are logged in as.NzNot logged inr   rD   ,c              3   &   K   | ]	  }|d      yw)nameNrA   ).0orgs     r,   	<genexpr>zauth_whoami.<locals>.<genexpr>   s     8CCK8s   orgszhttps://huggingface.coz	Logged inrK   )userrO   endpoint)
r   r   r6   r<   r=   r>   r   joinr   result)r   inforO   rQ   s       r,   auth_whoamirU      s     KE}		/"###++%=D8884<88@DD#'??xTHJJ{fD8Lr.   )NFF)N)NF)r   N).__doc__typingr   r<   huggingface_hub.constantsr   huggingface_hub.hf_apir   _loginr   r   r	   r
   r   errorsr   utilsr   r   r   r   utils._oauth_devicer   r   
_cli_utilsr   r   
_frameworkr   _outputr   r   
get_logger__name__r5   auth_clicommandboolr-   strr1   r8   r?   rB   rG   rU   rA   r.   r,   <module>rg      sm   e   . ) M M  H H H /  & 
		H	% LM 
    	 	*b*b$g	
	*b <	
	*b 
*b*bZ 
 FG   		"d
-.	0"
 
"	"	SC$J 	S 
 FG   	 	Id
1	
	I %g	
	I 
I	I. 
+(89 :
 
'_6p$qrQ sQ 
(&68V%WXM YMr.   