o
    oi                     @  s`   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
mZ 				ddddZdS )    )annotationsN)Optional)urlparse)
HASH_REGEXdownload_url_to_fileget_dirTFurlstr	model_dirOptional[str]progressbool
check_hash	file_namereturnc                 C  s   |du rt  }tj|d}tj|dd t| }tj|j}|dur&|}tj||}tj|sZtj	
d|  d| d d}	|rRt|}
|
rP|
dnd}	t| ||	|d	 |S )
a  Load the ONNX model at the given URL.

    If downloaded file is a zip file, it will be automatically
    decompressed.

    If the object is already present in `model_dir`, it's deserialized and
    returned.
    The default value of ``model_dir`` is ``<hub_dir>/checkpoints`` where
    ``hub_dir`` is the directory returned by :func:`~torch.hub.get_dir`.

    Args:
        url (str): URL of the object to download
        model_dir (str, optional): directory in which to save the object
        progress (bool, optional): whether or not to display a progress bar to stderr.
            Default: True
        check_hash(bool, optional): If True, the filename part of the URL should follow the naming convention
            ``filename-<sha256>.ext`` where ``<sha256>`` is the first eight or more
            digits of the SHA256 hash of the contents of the file. The hash is used to
            ensure unique names and to verify the contents of the file.
            Default: False
        file_name (str, optional): name for the downloaded file. Filename from ``url`` will be used if not set.

    Example:
        >>> model = download_onnx_from_url('https://github.com/fabio-sim/LightGlue-ONNX/releases/download/v1.0.0/disk_lightglue_fused_fp16.onnx')

    NcheckpointsT)exist_okzDownloading: "z" to 
   )r   )r   ospathjoinmakedirsr   basenameexistssysstderrwriter   searchgroupr   )r   r
   r   r   r   hub_dirpartsfilenamecached_filehash_prefixr r&   `/home/ubuntu/.local/lib/python3.10/site-packages/kornia/feature/lightglue_onnx/utils/download.pydownload_onnx_from_url   s"   !
r(   )NTFN)r   r	   r
   r   r   r   r   r   r   r   r   r	   )
__future__r   r   r   typingr   urllib.parser   	torch.hubr   r   r   r(   r&   r&   r&   r'   <module>   s   