o
    Ni/                  	   @   s   d Z ddlmZ ddlmZ ddlZddlZddlm	Z	m
Z
mZ ddlmZ ddlmZ 	dd	ed
ee dee defddZddedee defddZdS )z
HuggingFace Hub.

Unlike the other schemes, we don't implement a `SchemeClient` subclass here because
`huggingface_hub` handles the caching logic internally in essentially the same way.
    )Path)OptionalN)EntryNotFoundErrorRepositoryNotFoundErrorRevisionNotFoundError   )	PathOrStr)VERSIONmodel_identifierfilename	cache_dirreturnc              	   C   sd   d| v r|  dd }|  dd }n| }d }|d ur(ttj|||dt|dS ttj|||dS )N@r      cached_path)repo_idr   revisionlibrary_namelibrary_versionr   )r   r   )splitr   hf_hubhf_hub_downloadr	   snapshot_download)r
   r   r   r   r    r   J/home/ubuntu/.local/lib/python3.10/site-packages/cached_path/schemes/hf.pyr      s"   r   urlc              
   C   s:  |d urt | }|jddd | dd  }|ddkr<d|ddd  }d|dd d }t|||S |ddkrz|d\}}t|||W S  ttt	fyc   t|d | Y S  t
jjy } z|jd ur|jjdv rt|d |W  Y d }~S  d }~w ty   t|d | Y S w t|d |S )NT)parentsexist_ok   /r   r   >       )r   
expandusermkdircountjoinr   r   r   r   r   requests
exceptions	HTTPErrorresponsestatus_code
ValueError)r   r   
identifierr   r
   excr   r   r   hf_get_from_cache1   s.   r.   )N)__doc__pathlibr   typingr   huggingface_hubr   r&   huggingface_hub.utilsr   r   r   commonr   versionr	   strr   r.   r   r   r   r   <module>   s&    
 