o �J�h�)�@s�dZddlZddlZddlZddlZddlZddlZddlZejZ Gdd�de �Z Gdd�de �Z Gdd�de �Z Gd d �d e �Zdd d�ZdS)zb Fast cryptographic hash of Python objects, with a special case for fast hashing of numpy arrays. �Nc@�eZdZdZdd�ZdS)�_ConsistentSetz\Class used to ensure the hash of Sets is preserved whatever the order of its items. c Cs@zt|�|_WdSttjfytdd�|D��|_YdSw)Ncss�|]}t|�VqdS�N��hash)�.0�e�r �LC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\joblib\hashing.py� <genexpr>%s�z*_ConsistentSet.__init__.<locals>.<genexpr>)�sortedZ _sequence� TypeError�decimal�InvalidOperation)�selfZ set_sequencer r r �__init__s �z_ConsistentSet.__init__N��__name__� __module__� __qualname__�__doc__rr r r r rs rc@r)�_MyHashz5Class used to hash objects that won't normally picklecGs ||_dSr)�args)rrr r r r+s z_MyHash.__init__Nrr r r r r(s rc@s�eZdZdZddd�Zddd�Zdd �Zd d �Zd ej fd d�Z e j � �Z e e ee�<e e ee�<e e ee �<e e eej�<dd�Zdd�Zee ee��<d S)�Hasherz�A subclass of pickler, to do cryptographic hashing, rather than pickling. This is used to produce a unique hash of the given Python object that is not necessarily cryptographically secure. �md5cCs4t��|_d}tj||j|d�tj|dd�|_dS)N�)�protocolF)�usedforsecurity)�io�BytesIO�stream�Picklerr�hashlib�new�_hash)r� hash_namerr r r r5s zHasher.__init__Tc Cslz|�|�Wntjy!}z |jd||ff7_�d}~ww|j��}|j�|�|r4|j��SdS)Nz"PicklingError while hashing %r: %r) �dump�pickle� PicklingErrorrr �getvaluer$�update� hexdigest)r�objZ return_digestr�dumpsr r r r>s��   �z Hasher.hashcCs�t|tjtij�f�r>t|d�r|jj}n|j}|j}t|�tt �ur*t ||j�}n|dur4t ||�}n |jj }t |||�}t � ||�dS)N�__func__)� isinstance�types� MethodType�type�pop�hasattrr.r�__self__r'r� __class__r!�save)rr,� func_name�inst�clsr r r r7Is    z Hasher.savecCs"t|ttf�r dSt�||�dSr)r/�bytes�strr!�memoize)rr,r r r r=\szHasher.memoizeNcCs�t||d�}|d=z tj||fi|��WdStjyTtj||fi|��t|dd�}|dkrN|}|dur;|j}tj|}t ||�sQt |||�YdSYdSYdSw)N)�name�packr?r�__main__) �dictr!� save_globalr'r(�getattrr�sys�modulesr4�setattr)rr,r>r?�kwargs�moduleZmy_name�modr r r rBgs"    ��zHasher.save_globalc Gs^ztj|tt|��g|�R�WdSty.tj|ttdd�|D���g|�R�YdSw)Ncss �|] \}}t|�|fVqdSrr)r�k�vr r r r �s�z)Hasher._batch_setitems.<locals>.<genexpr>)r!�_batch_setitems�iterr r )r�itemsrr r r rL�s" ���zHasher._batch_setitemscCst�|t|��dSr)r!r7r)r� set_itemsr r r �save_set�szHasher.save_set)r)T)rrrrrrr7r=�structr?rBr!�dispatch�copyr2�len�objectr'r&rLrP�setr r r r r/s       rc@s"eZdZdZd dd�Zdd�ZdS) � NumpyHasherz1Special case the hasher for when numpy is loaded.rFcCsB||_tj||d�ddl}||_t|d�r|j|_dSt|_dS)z� Parameters ---------- hash_name: string The hash algorithm to be used coerce_mmap: boolean Make no difference between np.memmap and np.ndarray objects. �r%rN� getbuffer) � coerce_mmaprr�numpy�npr4rY� _getbuffer� memoryview)rr%rZr\r r r r�s    zNumpyHasher.__init__cCs�t||jj�rT|jjsT|jdkr|��}n|jjr|}n |jj r$|j }n|��}|j � |� |�|jj���|jrEt||jj�rE|jj}n|j}|d|j|j|jff}nt||jj�ro|j � d�d��|j � t�|��dSt�||�dS)z�Subclass the save method, to hash ndarray subclass, rather than pickling them. Off course, this is a total abuse of the Pickler class. r ZHASHEDZ _HASHED_DTYPEzutf-8N)r/r\�ndarray�dtype� hasobject�shape�flatten�flags� c_contiguous� f_contiguous�Tr$r*r]�view�uint8rZ�memmapr6�strides�encoder'r-rr7)rr,Zobj_c_contiguous�klassr r r r7�s$   zNumpyHasher.saveN�rF)rrrrrr7r r r r rW�s  rWrFcCsHd}||vrtd�||���dtjvrt||d�}nt|d�}|�|�S)aIQuick calculation of a hash to identify uniquely Python objects containing numpy arrays. Parameters ---------- hash_name: 'md5' or 'sha1' Hashing algorithm used. sha1 is supposedly safer, but md5 is faster. coerce_mmap: boolean Make no difference between np.memmap and np.ndarray )r�sha1zAValid options for 'hash_name' are {}. Got hash_name={!r} instead.r[)r%rZrX)� ValueError�formatrDrErWrr)r,r%rZZvalid_hash_names�hasherr r r r�s ��   rrn)rrr"rr'rQrDr0�_Picklerr!rUrrrrWrr r r r �<module>s oY
Memory