
    wi                        d Z ddlmZ ddlmZmZ ddlm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 ddlmZ  ej        e          Z	 ddlmZ ddlmZ dZ n# e!$ r dZ Y nw xY w G d de	          Z" G d d          Z# G d de#          Z$ G d de#          Z% G d de#          Z& G d de#          Z' G d de#          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
    )_SubParsersAction)ListOptional)	HTTPError)BaseHuggingfaceCLICommand)ENDPOINT)HfApi   )	auth_listauth_switchloginlogout)get_stored_tokens	get_tokenlogging   )ANSI)inquirerChoiceTFc                   *    e Zd Zedefd            ZdS )AuthCommandsparserc                 n   |                      dd                              d          }                    fd           |                     dd          }|                    d	t          d
           |                    ddd           |                    d            |                     dd          }|                    dt          d           |                    d            |                     dd          }|                    d            |                     dd          }|                    dt          d           |                    ddd           |                    d            |                     dd          }|                    d            d S ) Nauthz,Manage authentication (login, logout, etc.).)helpzAuthentication subcommandsc                 ,                                     S N)
print_help)argsauth_parsers    p/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/huggingface_hub/cli/auth.py<lambda>z2AuthCommands.register_subcommand.<locals>.<lambda>B   s    ;3I3I3K3K     )funcr   z8Log in using a token from huggingface.co/settings/tokensz--tokenz;Token generated from https://huggingface.co/settings/tokens)typer   z--add-to-git-credential
store_truez.Optional: Save token to git credential helper.)actionr   c                      t          |           S r   )	AuthLoginr    s    r"   r#   z2AuthCommands.register_subcommand.<locals>.<lambda>R   s    IdOO r$   r   zLog outz--token-namez3Optional: Name of the access token to log out from.c                      t          |           S r   )
AuthLogoutr+   s    r"   r#   z2AuthCommands.register_subcommand.<locals>.<lambda>[       Z5E5E r$   whoamiz;Find out which huggingface.co account you are logged in as.c                      t          |           S r   )
AuthWhoamir+   s    r"   r#   z2AuthCommands.register_subcommand.<locals>.<lambda>a   r.   r$   switchzSwitch between access tokensz0Optional: Name of the access token to switch to.c                      t          |           S r   )
AuthSwitchr+   s    r"   r#   z2AuthCommands.register_subcommand.<locals>.<lambda>o   s    *T:J:J r$   listzList all stored access tokensc                      t          |           S r   )AuthListr+   s    r"   r#   z2AuthCommands.register_subcommand.<locals>.<lambda>r   s     r$   )
add_parseradd_subparsersset_defaultsadd_argumentstr)r   auth_subparserslogin_parserlogout_parserwhoami_parserauth_switch_parserauth_list_parserr!   s          @r"   register_subcommandz AuthCommands.register_subcommand;   sE    ''5c'dd%44:V4WW 	  &K&K&K&K LLL '11T 2 
 
 	!!N 	" 	
 	
 	

 	!!%A 	" 	
 	
 	

 	!!'C'C!DDD (228)2LL""F 	# 	
 	
 	

 	""(E(E"FFF (22X 3 
 
 	""(E(E"FFF -77Ge7ff''C 	( 	
 	
 	

 	''%A 	( 	
 	
 	

 	''-J-J'KKK*55fCb5cc%%+F+F%GGGGGr$   N)__name__
__module____qualname__staticmethodr   rC    r$   r"   r   r   :   sA        6H$5 6H 6H 6H \6H 6H 6Hr$   r   c                       e Zd Zd ZdS )BaseAuthCommandc                 :    || _         t                      | _        d S r   )r    r	   _api)selfr    s     r"   __init__zBaseAuthCommand.__init__v   s    	GG			r$   N)rD   rE   rF   rN   rH   r$   r"   rJ   rJ   u   s#            r$   rJ   c                       e Zd Zd ZdS )r*   c                 v    t          j                     t          | j        j        | j        j                   d S )N)tokenadd_to_git_credential)r   set_verbosity_infor   r    rQ   rR   rM   s    r"   runzAuthLogin.run|   sA    "$$$)/"&)"A	
 	
 	
 	
 	
 	
r$   NrD   rE   rF   rU   rH   r$   r"   r*   r*   {   s#        
 
 
 
 
r$   r*   c                       e Zd Zd ZdS )r-   c                 `    t          j                     t          | j        j                   d S )N)
token_name)r   rS   r   r    rY   rT   s    r"   rU   zAuthLogout.run   s-    "$$$$).//////r$   NrV   rH   r$   r"   r-   r-      s#        0 0 0 0 0r$   r-   c                   T    e Zd Zd Zdee         fdZdee         dee         fdZdS )r4   c                     t          j                     | j        j        }||                                 }|t          d           t                       t          || j        j                   d S )Nz!No token name provided. Aborting.)rR   )	r   rS   r    rY   _select_token_nameprintexitr   rR   )rM   rY   s     r"   rU   zAuthSwitch.run   sn    "$$$Y)
0022J5666FFFJdi6UVVVVVVr$   returnc                 f   t          t                                                                }|st                              d           d S t
          r|                     |          S t          d           t          |d          D ]\  }}t          | d|            	 	 t          d          }|
                                dk    rd S t          |          dz
  }d|cxk    rt          |          k     rn n||         S t          d	           n# t          $ r t          d
           Y nw xY w)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.)r5   r   keysloggererror_inquirer_py_available_select_token_name_tuir]   	enumerateinputlowerintlen
ValueError)rM   token_namesirY   choiceindexs         r"   r\   zAuthSwitch._select_token_name   sk   ,..335566 	LLFGGG4! 	<..{;;;()))&{A66 	( 	(MAzQ&&*&&''''	N
N^__<<>>S((4Fa0000K 0 000000&u--@AAAA N N NLMMMMMN	Ns   #'D 6D D D/.D/rm   c                     d |D             }	 t          j        d|d                                           S # t          $ r t                              d           Y d S w xY w)Nc                 0    g | ]}t          ||           S )namer   ).0rY   s     r"   
<listcomp>z5AuthSwitch._select_token_name_tui.<locals>.<listcomp>   s%    UUU:6*:666UUUr$   zSelect a token to switch to:)messagechoicesdefaultzToken selection cancelled.)r   selectexecuteKeyboardInterruptrc   info)rM   rm   rx   s      r"   rf   z!AuthSwitch._select_token_name_tui   s~    UUUUU	?6   gii	
 ! 	 	 	KK455544	s   (7 $AAN)	rD   rE   rF   rU   r   r<   r\   r   rf   rH   r$   r"   r4   r4      st        	W 	W 	WNHSM N N N N4
$s) 
 
 
 
 
 
 
r$   r4   c                       e Zd Zd ZdS )r7   c                 H    t          j                     t                       d S r   )r   rS   r   rT   s    r"   rU   zAuthList.run   s    "$$$r$   NrV   rH   r$   r"   r7   r7      s#            r$   r7   c                       e Zd Zd ZdS )r1   c                    t                      }|t          d           t                       	 | j                            |          }t          t          j        d          |d                    d |d         D             }|r5t          t          j        d          d                    |                     t          dk    rt          d	t                      d S d S # t          $ rT}t          |           t          t          j
        |j        j                             t          d
           Y d }~d S d }~ww xY w)NzNot logged inzuser: rt   c                     g | ]
}|d          S rs   rH   )ru   orgs     r"   rv   z"AuthWhoami.run.<locals>.<listcomp>   s    888CCK888r$   orgszorgs: ,zhttps://huggingface.coz(Authenticated through private endpoint: r   )r   r]   r^   rL   r/   r   boldjoinr   r   redresponsetext)rM   rQ   r}   r   es        r"   rU   zAuthWhoami.run   s0   =/"""FFF	9##E**D$)H%%tF|444884<888D ;di))388D>>:::333KKKLLLLL 43 	 	 	!HHH$(1:?++,,,GGGGGGGGG	s   B-C   
D>*A	D99D>NrV   rH   r$   r"   r1   r1      s#            r$   r1   N))__doc__argparser   typingr   r   requests.exceptionsr   huggingface_hub.commandsr   huggingface_hub.constantsr   huggingface_hub.hf_apir	   _loginr   r   r   r   utilsr   r   r   
_cli_utilsr   
get_loggerrD   rc   
InquirerPyr   InquirerPy.base.controlr   re   ImportErrorr   rJ   r*   r-   r4   r7   r1   rH   r$   r"   <module>r      s}   & ' & & & & & ! ! ! ! ! ! ! ! ) ) ) ) ) ) > > > > > > . . . . . . ( ( ( ( ( ( : : : : : : : : : : : : 9 9 9 9 9 9 9 9 9 9       
	H	%	%#######......! # # #"#8H 8H 8H 8H 8H, 8H 8H 8Hv       
 
 
 
 
 
 
 
0 0 0 0 0 0 0 00 0 0 0 0 0 0 0f                s   A% %A/.A/