
    -Ph                        d Z ddlZddlZddlmZ d ej        D             Z	 ddlZe                    d dD                        d e	                                D             Zn# e
$ r Y nw xY wdd	Zd
 ZddZddZdS )z'
Calculating and checking file hashes.
    N)Pathc                 v    i | ]6}|t          t          |t          j        t          j        |                    7S  )getattrhashlib	functoolspartialnew.0algs     L/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pooch/hashes.py
<dictcomp>r      sE        #y0cBB	C	C      c                 <    i | ]}|t          t          |d           S N)r   xxhashr   s     r   r   r      s6     	
 	
 	
 d++	
 	
 	
r   )xxh128xxh64xxh32xxh3_128xxh3_64c                     i | ]
\  }}|||S r   r   )r   r   funcs      r   r   r   $   s*       c44CSTCSCSCSr   sha256c           	         |t           vr:t          d| dt          t                                                      d          d}t          |                     }t	          | d          5 }|                    |          }|r,|                    |           |                    |          }|,ddd           n# 1 swxY w Y   |                                S )ad  
    Calculate the hash of a given file.

    Useful for checking if a file has changed or been corrupted.

    Parameters
    ----------
    fname : str
        The name of the file.
    alg : str
        The type of the hashing algorithm

    Returns
    -------
    hash : str
        The hash of the file.

    Examples
    --------

    >>> fname = "test-file-for-hash.txt"
    >>> with open(fname, "w") as f:
    ...     __ = f.write("content of the file")
    >>> print(file_hash(fname))
    0fc74468e6a9a829f103d069aeb2bb4f8646bad58bf146bb0e3379b759ec4a00
    >>> import os
    >>> os.remove(fname)

    zAlgorithm 'zR' not available to the pooch library. Only the following algorithms are available .i   rbN)ALGORITHMS_AVAILABLE
ValueErrorlistkeysopenreadupdate	hexdigest)fnamer   	chunksizehasherfinbuffs         r   	file_hashr,   +   s-   < &&&4# 4 4(--//004 4 4
 
 	
 I!#&((F	eT		 'cxx	"" 	'MM$88I&&D  	'' ' ' ' ' ' ' ' ' ' ' ' ' ' '
 s   *AB::B>B>c                 |    d}| |}n"d| vr|}n|                      d          d         }|                                S )a  
    Parse the name of the hash method from the hash string.

    The hash string should have the following form ``algorithm:hash``, where
    algorithm can be the name of any algorithm known to :mod:`hashlib`.

    If the algorithm is omitted or the hash string is None, will default to
    ``"sha256"``.

    Parameters
    ----------
    hash_string : str
        The hash string with optional algorithm prepended.

    Returns
    -------
    hash_algorithm : str
        The name of the algorithm.

    Examples
    --------

    >>> print(hash_algorithm("qouuwhwd2j192y1lb1iwgowdj2898wd2d9"))
    sha256
    >>> print(hash_algorithm("md5:qouuwhwd2j192y1lb1iwgowdj2898wd2d9"))
    md5
    >>> print(hash_algorithm("sha256:qouuwhwd2j192y1lb1iwgowdj2898wd2d9"))
    sha256
    >>> print(hash_algorithm("SHA256:qouuwhwd2j192y1lb1iwgowdj2898wd2d9"))
    sha256
    >>> print(hash_algorithm("xxh3_64:qouuwhwd2j192y1lb1iwgowdj2898wd2d9"))
    xxh3_64
    >>> print(hash_algorithm(None))
    sha256

    r   N:r   )splitlower)hash_stringdefault	algorithms      r   hash_algorithmr4   Z   sQ    J G			K				%%c**1-	??r   Fc           
      X   |dS t          |          }t          | |          }|                                |                    d          d                                         k    }|r@|s>|t	          |           }t          |                                 d| d| d| d	          |S )
a  
    Check if the hash of a file matches a known hash.

    If the *known_hash* is None, will always return True.

    Coverts hashes to lowercase before comparison to avoid system specific
    mismatches between hashes in the registry and computed hashes.

    Parameters
    ----------
    fname : str or PathLike
        The path to the file.
    known_hash : str
        The known hash. Optionally, prepend ``alg:`` to the hash to specify the
        hashing algorithm. Default is SHA256.
    strict : bool
        If True, will raise a :class:`ValueError` if the hash does not match
        informing the user that the file may be corrupted.
    source : str
        The source of the downloaded file (name or URL, for example). Will be
        used in the error message if *strict* is True. Has no other use other
        than reporting to the user where the file came from in case of hash
        mismatch. If None, will default to *fname*.

    Returns
    -------
    is_same : bool
        True if the hash matches, False otherwise.

    NT)r   r.   z hash of downloaded file (z*) does not match the known hash: expected z	 but got zm. Deleted download for safety. The downloaded file may have been corrupted or the known hash may be outdated.)r4   r,   r0   r/   strr    upper)r'   
known_hashstrictsourcer3   new_hashmatchess          r   hash_matchesr>      s    > tz**II...Hnn*"2"23"7"7";"A"A"C"CCG 
g 
>ZZF   / /F / /)3/ />F/ / /
 
 	
 Nr   Tc           
          t                      |rd}nd}t           fd                     |          D                       } fd|D             }t          |dd          5 }t	          ||          D ]B\  }}|                    d                    |                    d	d
          |                     C	 ddd           dS # 1 swxY w Y   dS )a.  
    Make a registry of files and hashes for the given directory.

    This is helpful if you have many files in your test dataset as it keeps you
    from needing to manually update the registry.

    Parameters
    ----------
    directory : str
        Directory of the test data to put in the registry. All file names in
        the registry will be relative to this directory.
    output : str
        Name of the output registry file.
    recursive : bool
        If True, will recursively look for files in subdirectories of
        *directory*.

    z**/**c              3      K   | ]:}|                                 t          |                                        V  ;d S r   )is_filer7   relative_to)r   path	directorys     r   	<genexpr>z make_registry.<locals>.<genexpr>   s[        <<>>DY''((     r   c                 N    g | ]!}t          t          |z                      "S r   )r,   r7   )r   r'   rE   s     r   
<listcomp>z!make_registry.<locals>.<listcomp>   s.    CCCEiI-..//CCCr   wzutf-8)encodingz{} {}
\/N)r   sortedglobr#   zipwriteformatreplace)	rE   output	recursivepatternfileshashesoutfiler'   fhashs	   `        r   make_registryrZ      sd   & YI     NN7++    E DCCCUCCCF	fcG	,	,	, Mv.. 	M 	MLE5 MM)**5==s+C+CUKKLLLL	MM M M M M M M M M M M M M M M M M Ms   &ACCC)r   )FN)T)__doc__r   r   pathlibr   algorithms_availabler   r   r%   itemsImportErrorr,   r4   r>   rZ   r   r   r   <module>r`      sL               +   
	MMM 	
 	
J	
 	
 	
   #7#=#=#?#?    	 	 	D	, , , ,^, , ,^- - - -`%M %M %M %M %M %Ms   AA% %A-,A-