a
    
d                     @   s   d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	 dee
 ee
 dd	d
Zde
e
ee
 ddddZde
ee
 ddddZdS )z-Contains utilities to manage Git credentials.    N)ListOptional   )ENDPOINT   )run_interactive_subprocessrun_subprocess)folderreturnc              
   C   s^   z(t d| dj}tdd |dD W S  tjyX } zt|jW Y d}~n
d}~0 0 dS )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	   c                 S   s*   h | ]"}d |v r| dd   d qS )zcredential.helper=r   )split).0line r   n/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/huggingface_hub/utils/_git_credential.py	<setcomp>)   s   z*list_credential_helpers.<locals>.<setcomp>
N)r   stdoutsortedr   
subprocessCalledProcessErrorEnvironmentErrorstderr)r	   outputexcr   r   r   list_credential_helpers   s    r   hf_user)tokenusernamer	   r
   c              
   C   s^   t d|d>\}}|dt d|  d|  d |  W d   n1 sP0    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_r   r   r   set_git_credential1   s
    "r'   )r    r	   r
   c                 C   sv   t d|dV\}}dt d}| dur:|d|   d7 }|d7 }|| |  W d   n1 sh0    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!   r   Nz	username=)r   r   r#   r"   r$   )r    r	   r%   r&   Zstandard_inputr   r   r   unset_git_credentialH   s    
r(   )N)r   N)r   N)__doc__r   typingr   r   	constantsr   Z_subprocessr   r   strr   r'   r(   r   r   r   r   <module>   s   