
    hd                         S SK r S SKJr  S SKJrJr  S SKrS SKJr  \	" 5       4S\\
   S\
4S jjrS\\\
4   S\
4S	 jrg)
    N)Path)IterableUnion)msgexcludereturnc                    [        U [        5      (       a+  U R                  5        VVs0 s H  u  p#X!;  d  M  X#_M     n nn[        R                  " U SS9R                  S5      n[        R                  " U5      R                  5       $ s  snnf )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.
T)	sort_keysutf8)	
isinstancedictitemssrsly
json_dumpsencodehashlibmd5	hexdigest)datar   kvdata_strs        M/home/james-whalen/.local/lib/python3.13/site-packages/weasel/util/hashing.pyget_hashr   	   sq     $!%B1AB5<<VDH;;x **,, Cs
   B	B	pathc                    [        U 5      n U R                  5       (       d.  U R                  5       (       d  [        R                  " SU  S3SS9  U R                  5       (       a;  [
        R                  " [        U 5      R                  5       5      R                  5       $ [
        R                  " 5       n[        S U R                  S5       5       5       H"  nUR                  UR                  5       5        M$     UR                  5       $ )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              3   R   #    U  H  oR                  5       (       d  M  Uv   M     g 7f)N)is_file).0fps     r   	<genexpr>get_checksum.<locals>.<genexpr>%   s     LObzz|rrOs   '	'*)r   r    is_dirr   failr   r   
read_bytesr   sortedrglobupdate)r   dir_checksumsub_files      r   get_checksumr.      s     :DLLNNdkkmm*4&0IJRST||~~{{4:0023==?? {{}LDJJsOLLH 3 3 56 M%%''    )r   pathlibr   typingr   r   r   wasabir   tuplestrr   r.    r/   r   <module>r6      sN      "   -2G 
-HSM 
- 
-(uT3Y' (C (r/   