o
    id                     @   sr   d dl Z d dlmZ d dlmZmZ d dlZd dlmZ e	 fdee
 de
fddZd	eee
f de
fd
dZdS )    N)Path)IterableUnion)msgexcludereturnc                    sB   t | tr fdd|  D } tj| ddd}t| S )zGet the hash for a JSON-serializable object.

    data: The data to hash.
    exclude (Iterable[str]): Top-level keys to exclude if data is a dict.
    RETURNS (str): The hash.
    c                    s   i | ]\}}| vr||qS  r   ).0kvr   r   G/home/ubuntu/.local/lib/python3.10/site-packages/weasel/util/hashing.py
<dictcomp>   s    zget_hash.<locals>.<dictcomp>T)	sort_keysutf8)	
isinstancedictitemssrsly
json_dumpsencodehashlibmd5	hexdigest)datar   data_strr   r   r   get_hash	   s   
r   pathc                 C   s   t | } |  s|  stjd|  ddd |  r&tt |   S t }t	dd | 
dD D ]	}||  q6| S )zGet the checksum for a file or directory given its file path. If a
    directory path is provided, this uses all files in that directory.

    path (Union[Path, str]): The file or directory path.
    RETURNS (str): The checksum.
    zCan't get checksum for z: not a file or directory   )exitsc                 s   s    | ]	}|  r|V  qd S )N)is_file)r	   fpr   r   r   	<genexpr>%   s    zget_checksum.<locals>.<genexpr>*)r   r    is_dirr   failr   r   
read_bytesr   sortedrglobupdate)r   dir_checksumsub_filer   r   r   get_checksum   s   r,   )r   pathlibr   typingr   r   r   wasabir   tuplestrr   r,   r   r   r   r   <module>   s    