o
    \i)                     @   s   d Z ddlZddlZddlZddlZddlZddlZddlZejZ	G dd de
ZG dd de
ZG dd de	ZG d	d
 d
eZdddZdS )zb
Fast cryptographic hash of Python objects, with a special case for fast
hashing of numpy arrays.
    Nc                   @      e Zd ZdZdd ZdS )_ConsistentSetz\Class used to ensure the hash of Sets is preserved
    whatever the order of its items.
    c              	   C   s@   zt || _W d S  ttjfy   t dd |D | _Y d S w )Nc                 s   s    | ]}t |V  qd S Nhash).0e r	   o/var/www/www-root/data/www/176.119.141.140/sports-predictor/venv/lib/python3.10/site-packages/joblib/hashing.py	<genexpr>%   s    z*_ConsistentSet.__init__.<locals>.<genexpr>)sorted	_sequence	TypeErrordecimalInvalidOperation)selfset_sequencer	   r	   r
   __init__   s
   z_ConsistentSet.__init__N__name__
__module____qualname____doc__r   r	   r	   r	   r
   r      s    r   c                   @   r   )_MyHashz5Class used to hash objects that won't normally picklec                 G   s
   || _ d S r   )args)r   r   r	   r	   r
   r   +   s   
z_MyHash.__init__Nr   r	   r	   r	   r
   r   (   s    r   c                   @   s   e Zd ZdZdddZdddZdd	 Zd
d Zdej	fddZ
ej Ze
eee< e
eee< e
eee< e
eeej< dd Zdd Zeeee < dS )HasherzA 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.
    md5c                 C   s4   t  | _d}tj| | j|d tj|dd| _d S )N   )protocolF)usedforsecurity)ioBytesIOstreamPicklerr   hashlibnew_hash)r   	hash_namer   r	   r	   r
   r   5   s   
zHasher.__init__Tc              
   C   sl   z|  | W n tjy! } z| jd||f f7  _ d }~ww | j }| j| |r4| j S d S )Nz"PicklingError while hashing %r: %r)	dumppicklePicklingErrorr   r"   getvaluer&   update	hexdigest)r   objreturn_digestr   dumpsr	   r	   r
   r   >   s   

zHasher.hashc                 C   s   t |tjti jfr>t|dr|jj}n|j}|j}t|tt	u r*t
||j}n|d u r4t
||}n
|jj}t
|||}t| | d S )N__func__)
isinstancetypes
MethodTypetypepophasattrr1   r   __self__r)   r   	__class__r#   save)r   r.   	func_nameinstclsr	   r	   r
   r:   I   s   

zHasher.savec                 C   s"   t |ttfr	d S t| | d S r   )r2   bytesstrr#   memoize)r   r.   r	   r	   r
   r@   \   s   zHasher.memoizeNc                 C   s   t ||d}|d= ztj| |fi | W d S  tjyT   tj| |fi | t|dd }|dkrN|}|d u r;|j}tj| }t	||sQt
||| Y d S Y d S Y d S w )N)namepackrB   r   __main__)dictr#   save_globalr)   r*   getattrr   sysmodulesr7   setattr)r   r.   rA   rB   kwargsmodulemy_namemodr	   r	   r
   rE   g   s"   

zHasher.save_globalc              	   G   s^   zt j| tt|g|R   W d S  ty.   t j| ttdd |D g|R   Y d S w )Nc                 s   s     | ]\}}t ||fV  qd S r   r   )r   kvr	   r	   r
   r      s    z)Hasher._batch_setitems.<locals>.<genexpr>)r#   _batch_setitemsiterr   r   )r   itemsr   r	   r	   r
   rP      s   "zHasher._batch_setitemsc                 C   s   t | t| d S r   )r#   r:   r   )r   	set_itemsr	   r	   r
   save_set   s   zHasher.save_set)r   )T)r   r   r   r   r   r   r:   r@   structrB   rE   r#   dispatchcopyr5   lenobjectr)   r(   rP   rT   setr	   r	   r	   r
   r   /   s    

	
r   c                   @   s"   e Zd ZdZd	ddZdd ZdS )
NumpyHasherz1Special case the hasher for when numpy is loaded.r   Fc                 C   sB   || _ tj| |d ddl}|| _t|dr|j| _dS t| _dS )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'   r   N	getbuffer)	coerce_mmapr   r   numpynpr7   r]   
_getbuffer
memoryview)r   r'   r^   r`   r	   r	   r
   r      s   


zNumpyHasher.__init__c                 C   s   t || jjrT|jjsT|jdkr| }n|jjr|}n|jj	r$|j
}n| }| j| || jj | jrEt || jjrE| jj}n|j}|d|j|j|jff}nt || jjro| jdd | jt| dS t| | dS )zSubclass the save method, to hash ndarray subclass, rather
        than pickling them. Off course, this is a total abuse of
        the Pickler class.
        r	   HASHED_HASHED_DTYPEzutf-8N)r2   r`   ndarraydtype	hasobjectshapeflattenflagsc_contiguousf_contiguousTr&   r,   ra   viewuint8r^   memmapr9   stridesencoder)   r0   r   r:   )r   r.   obj_c_contiguousklassr	   r	   r
   r:      s$   


zNumpyHasher.saveNr   F)r   r   r   r   r   r:   r	   r	   r	   r
   r[      s    
r[   r   Fc                 C   sH   d}||vrt d||dtjv rt||d}nt|d}|| S )aI  Quick 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'   r^   r\   )
ValueErrorformatrG   rH   r[   r   r   )r.   r'   r^   valid_hash_nameshasherr	   r	   r
   r      s   


r   ru   )r   r   r$   r    r)   rU   rG   r3   _Picklerr#   rY   r   r   r   r[   r   r	   r	   r	   r
   <module>   s    	oY