U
    CŒÑhB  ã                   @   s–   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlZd dl	m
Z
 e e¡Zdd„ Zdd	„ Zddd„Zdddœeeeeef eedœdd„ZdS )é    N)ÚPathLike)ÚPath)ÚUnion©Údownload_url_to_filec                 C   s.   t tj ¡ ƒd t | ƒ }|jjddd� |S )NZ
torchaudioT)ÚparentsÚexist_ok)r   ÚtorchZhubZget_dirÚparentÚmkdir)ÚkeyÚpath© r   úG/tmp/user/2202/pip-unpacked-wheel-p89lpdx5/torchaudio/utils/download.pyÚ_get_local_path   s    r   c                 C   s   d| › �}t |||d� d S )Nz(https://download.pytorch.org/torchaudio/©Úprogressr   )r   r   r   Úurlr   r   r   Ú	_download   s    
r   é  c              	   C   sJ   t  ¡ }t| dƒ�*}| |¡}|r8| |¡ | |¡}qW 5 Q R X | ¡ S )NÚrb)ÚhashlibÚsha256ÚopenÚreadÚupdateÚ	hexdigest)r   ÚhashÚ
chunk_sizeÚmÚfileÚdatar   r   r   Ú	_get_hash   s    

r"   Ú Tr   )r   r   r   r   Úreturnc                C   sŒ   |p
t | ƒ}| ¡ r"t d|¡ nt d| |¡ t| ||d� |r„t d¡ t||ƒ}||krztd|› d|› d|› d�ƒ‚t d	¡ t|ƒS )
a4  Download and store torchaudio assets to local file system.

    If a file exists at the download path, then that path is returned with or without
    hash validation.

    Args:
        key (str): The asset identifier.
        hash (str, optional):
            The value of SHA256 hash of the asset. If provided, it is used to verify
            the downloaded / cached object. If not provided, then no hash validation
            is performed. This means if a file exists at the download path, then the path
            is returned as-is without verifying the identity of the file.
        path (path-like object, optional):
            By default, the downloaded asset is saved in a directory under
            :py:func:`torch.hub.get_dir` and intermediate directories based on the given `key`
            are created.
            This argument can be used to overwrite the target location.
            When this argument is provided, all the intermediate directories have to be
            created beforehand.
        progress (bool): Whether to show progress bar for downloading. Default: ``True``.

    Note:
        Currently the valid key values are the route on ``download.pytorch.org/torchaudio``,
        but this is an implementation detail.

    Returns:
        str: The path to the asset on the local file system.
    z2The local file (%s) exists. Skipping the download.zDownloading %s to %sr   zVerifying the hash value.z'The hash value of the downloaded file (z), 'z+' does not match the provided hash value, 'z'.zHash validated.)r   ÚexistsÚ_LGÚinfor   r"   Ú
ValueErrorÚstr)r   r   r   r   Údigestr   r   r   Údownload_asset"   s    #

ÿ
r+   )r   )r#   r#   )r   ÚloggingÚosr   Úpathlibr   Útypingr   r	   Ztorchaudio._internalr   Ú	getLoggerÚ__name__r&   r   r   r"   r)   Úboolr+   r   r   r   r   Ú<module>   s*   

  ýû
ú