wL idZddlmZddlmZmZddlmZddlm Z ddl m Z ddl m Z dd lmZmZmZmZdd lmZmZmZd d lmZej2eZ dd lmZddlmZdZ Gdde Z"GddZ#Gdde#Z$Gdde#Z%Gdde#Z&Gdde#Z'Gdde#Z(y#e!$rdZ YVwxYw) aContains 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)ListOptional) HTTPError)BaseHuggingfaceCLICommand)ENDPOINT)HfApi) auth_list auth_switchloginlogout)get_stored_tokens get_tokenlogging)ANSI)inquirer)ChoiceTFc"eZdZedefdZy) AuthCommandsparserc|jddjd}jfd|jdd}|jd td |jd d d|jd|jdd}|jdtd |jd|jdd}|jd|jdd}|jdtd |jd d d|jd|jdd}|jdy) Nauthz,Manage authentication (login, logout, etc.).)helpzAuthentication subcommandsc$jSN) print_help)args auth_parsers ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/huggingface_hub/cli/auth.pyz2AuthCommands.register_subcommand..Bs;3I3I3K)funcr z8Log in using a token from huggingface.co/settings/tokensz--tokenz;Token generated from https://huggingface.co/settings/tokens)typerz--add-to-git-credential store_truez.Optional: Save token to git credential helper.)actionrct|Sr) AuthLoginrs r!r"z2AuthCommands.register_subcommand..Rs IdOr#rzLog outz --token-namez3Optional: Name of the access token to log out from.ct|Sr) AuthLogoutr*s r!r"z2AuthCommands.register_subcommand..[ Z5Er#whoamiz;Find out which huggingface.co account you are logged in as.ct|Sr) AuthWhoamir*s r!r"z2AuthCommands.register_subcommand..ar-r#switchzSwitch between access tokensz0Optional: Name of the access token to switch to.ct|Sr) AuthSwitchr*s r!r"z2AuthCommands.register_subcommand..os *T:Jr#listzList all stored access tokensct|Sr)AuthListr*s r!r"z2AuthCommands.register_subcommand..rs r#) add_parseradd_subparsers set_defaults add_argumentstr)rauth_subparsers login_parser logout_parser whoami_parserauth_switch_parserauth_list_parserr s @r!register_subcommandz AuthCommands.register_subcommand;s''5c'd %44:V4W   &K L'11 T2  !! N " !! %A " !!'C!D(228)2L "" F # ""(E"F(22 X3  ""(E"F-77Ge7f'' C ( '' %A ( ''-J'K*55fCb5c%%+F%Gr#N)__name__ __module__ __qualname__ staticmethodrrBr#r!rr:s6H$56H6Hr#rceZdZdZy)BaseAuthCommandc0||_t|_yr)rr _api)selfrs r!__init__zBaseAuthCommand.__init__vs G r#N)rCrDrErMrGr#r!rIrIusr#rIceZdZdZy)r)ctjt|jj|jj y)N)tokenadd_to_git_credential)rset_verbosity_infor rrPrQrLs r!runz AuthLogin.run|s.""$ ))//"&))"A"A r#NrCrDrErTrGr#r!r)r){s r#r)ceZdZdZy)r,cltjt|jjy)N) token_name)rrRrrrXrSs r!rTzAuthLogout.runs ""$$))../r#NrUrGr#r!r,r,s0r#r,c@eZdZdZdeefdZdeedeefdZy)r3ctj|jj}||j }|t dt t||jjy)Nz!No token name provided. Aborting.)rQ) rrRrrX_select_token_nameprintexitr rQ)rLrXs r!rTzAuthSwitch.runsY""$YY))  002J   5 6 FJdii6U6UVr#returncttj}|stj dyt r|j |Stdt|dD]\}}t|d| td}|jdk(ryt|dz }d|cxkrt|krnn||Std W#t$rtd YwxYw) Nz+No stored tokens found. Please login first.zAvailable stored tokens:rz. z=Enter the number of the token to switch to (or 'q' to quit): qrz$Invalid selection. Please try again.z4Invalid input. Please enter a number or 'q' to quit.)r4rkeysloggererror_inquirer_py_available_select_token_name_tuir\ enumerateinputlowerintlen ValueError)rL token_namesirXchoiceindexs r!r[zAuthSwitch._select_token_names,.3356  LLF G !..{; ; ()&{A6 (MAz QCr*& ' ( N^_<<>S(F a0K 00&u--@A NLM NsC!)C CC/.C/rlc|Dcgc]}t||}} tjd|djScc}w#t$rt j dYywxYw)N)namezSelect a token to switch to:)messagechoicesdefaultzToken selection cancelled.)rrselectexecuteKeyboardInterruptrbinfo)rLrlrXrss r!rez!AuthSwitch._select_token_name_tuiskITU:6*:6UU ??6gi  V!  KK4 5 sA%AA('A(N) rCrDrErTrr;r[rrerGr#r!r3r3s5 WNHSMN4 $s)  r#r3ceZdZdZy)r6c@tjtyr)rrRr rSs r!rTz AuthList.runs""$ r#NrUrGr#r!r6r6sr#r6ceZdZdZy)r0cJt}|tdt |jj |}tt j d|d|dDcgc]}|d }}|r.tt j ddj|tdk7rtdtyycc}w#t$rR}t|tt j|jjtd Yd}~yd}~wwxYw) Nz Not logged inzuser: rqorgszorgs: ,zhttps://huggingface.coz(Authenticated through private endpoint: r) rr\r]rKr.rboldjoinrrredresponsetext)rLrPrxorgr}es r!rTzAuthWhoami.runs  = / " F 99##E*D $))H%tF| 4+/<8CCK8D8dii)388D>:33@ KL4 9   !H $((1::??+ , GG s,AC' C3A CC D"ADD"NrUrGr#r!r0r0sr#r0N))__doc__argparsertypingrrrequests.exceptionsrhuggingface_hub.commandsrhuggingface_hub.constantsrhuggingface_hub.hf_apir _loginr r r rutilsrrr _cli_utilsr get_loggerrCrb InquirerPyrInquirerPy.base.controlrrd ImportErrorrrIr)r,r3r6r0rGr#r!rs&'!)>.(::99   H %##.! 8H,8Hv   00 00f [#"#sB33B=<B=