
    i              	           d Z ddlZddlZddlmZ ddlmZmZ  ej        dej	        ej
        z  ej        z            Zdd	edz  d
ee         fdZddeded	edz  d
dfdZdded	edz  d
dfdZded
ee         fdZdS )z-Contains utilities to manage Git credentials.    N   )ENDPOINT   )run_interactive_subprocessrun_subprocessz
        ^\s* # start of line
        credential\.helper # credential.helper value
        \s*=\s* # separator
        ([\w\-\/]+) # the helper name or absolute path (group 1)
        (\s|$) # whitespace or end of line
    )flagsfolderreturnc                     	 t          d|           j        }t          |          }|S # t          j        $ r}t          |j                  d}~ww xY w)a  Return the list of git credential helpers configured.

    See https://git-scm.com/docs/gitcredentials.

    Credentials are saved in all configured helpers (store, cache, macOS keychain,...).
    Calls "`git credential approve`" internally. See https://git-scm.com/docs/git-credential.

    Args:
        folder (`str`, *optional*):
            The folder in which to check the configured helpers.
    zgit config --listr	   N)r   stdout_parse_credential_output
subprocessCalledProcessErrorOSErrorstderr)r	   outputparsedexcs       f/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/huggingface_hub/utils/_git_credential.pylist_credential_helpersr   #   sa    " 3FCCCJ)&11( " " "cj!!!"s   &) AAAhf_usertokenusernamec           
          t          d|          5 \  }}|                    dt           d|                                 d|  d           |                                 ddd           dS # 1 swxY w Y   dS )a  Save a username/token pair in git credential for HF Hub registry.

    Credentials are saved in all configured helpers (store, cache, macOS keychain,...).
    Calls "`git credential approve`" internally. See https://git-scm.com/docs/git-credential.

    Args:
        username (`str`, defaults to `"hf_user"`):
            A git username. Defaults to `"hf_user"`, the default user used in the Hub.
        token (`str`, defaults to `"hf_user"`):
            A git password. In practice, the User Access Token for the Hub.
            See https://huggingface.co/settings/tokens.
        folder (`str`, *optional*):
            The folder in which to check the configured helpers.
    zgit credential approver   url=z

username=z

password=z

N)r   writer   lowerflush)r   r   r	   stdin_s        r   set_git_credentialr"   7   s     
$$<V	L	L	L  Q	X8XX0@0@XXUXXXYYY                 s   AA--A14A1c                    t          d|          5 \  }}dt           d}| |d|                                  dz  }|dz  }|                    |           |                                 ddd           dS # 1 swxY w Y   dS )aY  Erase credentials from git credential for HF Hub registry.

    Credentials are erased from the configured helpers (store, cache, macOS
    keychain,...), if any. If `username` is not provided, any credential configured for
    HF Hub endpoint is erased.
    Calls "`git credential erase`" internally. See https://git-scm.com/docs/git-credential.

    Args:
        username (`str`, defaults to `"hf_user"`):
            A git username. Defaults to `"hf_user"`, the default user used in the Hub.
        folder (`str`, *optional*):
            The folder in which to check the configured helpers.
    zgit credential rejectr   r   
Nz	username=)r   r   r   r   r   )r   r	   r    r!   standard_inputs        r   unset_git_credentialr&   N   s     
$$;F	K	K	K 
 P	,,,,>(..*:*:>>>>N$N###
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   AA99A= A=r   c                 d    t          d t                              |           D                       S )zParse the output of `git credential fill` to extract the password.

    Args:
        output (`str`):
            The output of `git credential fill`.
    c                     h | ]
}|d          S )r    ).0matchs     r   	<setcomp>z+_parse_credential_output.<locals>.<setcomp>t   s)     	
 	
 	
E!H	
 	
 	
    )sortedGIT_CREDENTIAL_REGEXfindall)r   s    r   r   r   i   s@     	
 	
"6">">v"F"F	
 	
 	
  r-   )N)r   N)__doc__rer   	constantsr   _subprocessr   r   compile	MULTILINE
IGNORECASEVERBOSEr/   strlistr   r"   r&   r   r)   r-   r   <module>r;      sM   4 3 				                 C C C C C C C C "rz ,
&
3	 	 	 " "C$J "$s) " " " "( c S cDj \`    . 3 C$J RV    6S T#Y      r-   