
    3j                        S SK Jr  S SKrS SKrS SKrS SKJrJr  S SK	J
r
  S/r\R                  " \5      r " S S5      rg)    )annotationsN)AnyOptional)kornia_configCachedDownloaderc                  p    \ rS rSrSr\SS	S jj5       r\S
SS jj5       r\ S
       SS jj5       rSr	g)r       zFDownloads files from URLs to the local cache or .kornia_hub directory.Nc                   Uc  [         R                  nUb=  UR                  U5      (       d'  [        R                  R                  U5      S    U 3nO"[        R                  R                  U5      S   n[        R                  R                  " / UR                  [        R                  5      QUR                  [        R                  5      SS QUP76 nU$ )a  Construct the file path for the ONNX model based on the model name and cache directory.

Args:
    model_name: The name of the model or operator, typically in the format 'operators/model_name'.
    cache_dir: The directory where the model should be cached.
        Defaults to None, which will use a default `kornia.config.hub_onnx_dir` directory.
    suffix: Optional file suffix when the filename is the model name.

Returns:
    str: The full local path where the model should be stored or loaded from.

N)r   hub_cache_direndswithospathsplitjoinsep)cls
model_name	cache_dirsuffix	file_name	file_paths         N/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/onnx/download.py_get_file_pathCachedDownloader._get_file_path#   s     %33I j&9&9&&A&A77==4R89&BIj1"5IGGLLe)//"&&"9eJ<L<LRVV<TUXVX<Ye[de	    c                    UR                  S5      (       aF  UR                  SS 5      nUR                  SS 5      nU R                  X%US9nU R                  XUS9  U$ [	        SU 35      e)Nzhttp:zhttps:r   r   )r   )download_if_not_existsz-URL must start with 'http:' or 'https:'. Got )
startswithgetr   download
ValueError)r   urlnamer"   kwargsr   r   r   s           r   download_to_cache"CachedDownloader.download_to_cache=   sp    >>-..

;5IZZ$/F**46*JILLLIHNOOr   c                <   [         R                  R                  U5      (       a  [        R	                  SU SU S35        gU(       d  [        SU S35      e[         R                  " [         R                  R                  U5      SS9  UR                  S	5      (       a=   [        R	                  S
U SU S35        [        R                  R                  X5        g[        S5      e! [        R                  R                   a  n[        SU S35      UeSnAff = f)a9  Download an ONNX model from the specified URL and save it to the specified file path.

Args:
    url: The URL of the ONNX model to download.
    file_path: The local path where the downloaded model should be saved.
    download_if_not_exists: If True, the file will be downloaded if it's not already downloaded.

z	Loading `z` from `z`.N`z)` not found. You may set `download=True`.T)exist_okr   zDownloading `z` to `zError in resolving `z'URL must start with 'http:' or 'https:')r   r   existsloggerinfor#   makedirsdirnamer    urllibrequesturlretrieveerror	HTTPError)r   r$   r   r   es        r   r"   CachedDownloader.downloadG   s     77>>)$$KK)C52>?%q+TUVV
BGGOOI.>>>-..HmC5ykDE**3: FGG <<)) H #7uB!?@aGHs   !;C( (DDD )N)r   strr   Optional[str]r   r:   returnr9   )T)
r$   r9   r%   r9   r"   boolr&   r   r;   r9   )r$   r9   r   r9   r   r<   r;   None)
__name__
__module____qualname____firstlineno____doc__classmethodr   r'   r"   __static_attributes__r8   r   r   r   r       sr    P 2 P P 
 (,	HH H !%	H
 
H Hr   )
__future__r   loggingr   urllib.requestr1   typingr   r   kornia.configr   __all__	getLoggerr>   r-   r   r8   r   r   <module>rL      s?   $ #  	    '
			8	$FH FHr   