
    Ug')                         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e
          Z G d de
          Z G d de	          Z G d	 d
e          Z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 ZdS )_ConsistentSetza Class used to ensure the hash of Sets is preserved
        whatever the order of its items.
    c                     	 t          |          | _        d S # t          t          j        f$ r" t          d |D                       | _        Y d S w xY w)Nc              3   4   K   | ]}t          |          V  d S Nhash).0es     M/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/joblib/hashing.py	<genexpr>z*_ConsistentSet.__init__.<locals>.<genexpr>%   s(      $C$CT!WW$C$C$C$C$C$C    )sorted	_sequence	TypeErrordecimalInvalidOperation)selfset_sequences     r   __init__z_ConsistentSet.__init__   sj    		E
 $L11DNNN734 	E 	E 	E $$C$Cl$C$C$CDDDNNNN	Es    4AAN__name__
__module____qualname____doc__r    r   r   r   r      s2         E E E E Er   r   c                       e Zd ZdZd ZdS )_MyHashz7 Class used to hash objects that won't normally pickle c                     || _         d S r   )args)r   r    s     r   r   z_MyHash.__init__+   s    			r   Nr   r   r   r   r   r   (   s)        AA    r   r   c                   (   e Zd ZdZddZddZd Zd Zdej	        fd	Z
ej                                        Ze
e ee          <   e
e ee          <   e
e ee          <   e
e eej                  <   d
 Zd Zee e e                      <   dS )HasherzW A subclass of pickler, to do cryptographic hashing, rather than
        pickling.
    md5c                     t          j                    | _        d}t                              | | j        |           t          j        |          | _        d S )N   )protocol)ioBytesIOstreamPicklerr   hashlibnew_hash)r   	hash_namer&   s      r   r   zHasher.__init__4   sH    jll t{X>>>[++


r   Tc                 .   	 |                      |           n/# t          j        $ r}|xj        d|d|fz  c_         d }~ww xY w| j                                        }| j                            |           |r| j                                        S d S )NzPicklingError while hashing z: )	dumppicklePicklingErrorr    r)   getvaluer-   update	hexdigest)r   objreturn_digestr   dumpss        r   r	   zHasher.hash=   s    	IIcNNNN# 	 	 	FFFsssAAFHHFF	 $$&&
%    	*:'')))	* 	*s    A?Ac                    t          |t          j        t          i j                  f          rt          |d          r|j        j        }n|j        }|j        }t          |          t          t                    u rt          ||j                  }n0|t          ||          }n|j        j        }t          |||          }t                              | |           d S )N__func__)
isinstancetypes
MethodTypetypepophasattrr:   r   __self__r1   r   	__class__r*   save)r   r6   	func_nameinstclss        r   rC   zHasher.saveH   s    cE,d26ll;<< 	4 sJ'' )L1		L	<DDzzT&\\))i77i..l,is33T3r   c                 x    t          |t          t          f          rd S t                              | |           d S r   )r;   bytesstrr*   memoize)r   r6   s     r   rJ   zHasher.memoize[   s9    
 cE3<(( 	Fc"""""r   Nc                 ^   t          ||          }|d= 	 t          j        | |fi | d S # t          j        $ rr t          j        | |fi | t          |dd           }|dk    rA|}||j        }t          j        |         }t          ||          st          |||           Y d S Y d S Y d S w xY w)N)namepackrM   r   __main__)dictr*   save_globalr1   r2   getattrr   sysmodulesr@   setattr)r   r6   rL   rM   kwargsmodulemy_namemods           r   rP   zHasher.save_globalf   s     4d+++6N	/c44V44444# 	/ 	/ 	/c44V444S,55F##?!lGk&)sG,, / C#...... $##
/ / /	/s   + A7B,+B,c           
         	 t                               | t          t          |                               d S # t          $ rC t                               | t          t          d |D                                            Y d S w xY w)Nc              3   >   K   | ]\  }}t          |          |fV  d S r   r   )r
   kvs      r   r   z)Hasher._batch_setitems.<locals>.<genexpr>   sL       6I 6I:>!Q 8<Awwl 6I 6I 6I 6I 6I 6Ir   )r*   _batch_setitemsiterr   r   )r   itemss     r   r]   zHasher._batch_setitems   s    
	K
 ##D$ve}}*=*=>>>>> 	K 	K 	K ##D$v 6I 6IBG6I 6I 6I 0I 0I +J +J K K K K K K	Ks   59 A	BBc                 V    t                               | t          |                     d S r   )r*   rC   r   )r   	set_itemss     r   save_setzHasher.save_set   s$    T>)4455555r   )r#   )T)r   r   r   r   r   r	   rC   rJ   structrM   rP   r*   dispatchcopyr>   lenobjectr1   r0   r]   rb   setr   r   r   r"   r"   /   s        , , , ,	* 	* 	* 	*     &# # # %)v{ / / / /* $$&&H%HTT#YY(HTT&\\)HTT']]"-HTT&+K K K6 6 6 %HTT##%%[[r   r"   c                        e Zd ZdZddZd ZdS )NumpyHasherz7 Special case the hasher for when numpy is loaded.
    r#   Fc                     || _         t                              | |           ddl}|| _        t          |d          r|j        | _        dS t          | _        dS )a  
            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npr@   rm   
_getbuffer
memoryview)r   r.   rn   rp   s       r   r   zNumpyHasher.__init__   s_     '	2222{## 	) lDOOO(DOOOr   c                 N   t          || j        j                  r|j        j        s|j        dk    r|                                }n7|j        j        r|}n(|j        j	        r|j
        }n|                                }| j                            |                     |                    | j        j                                       | j        r't          || j        j                  r| j        j        }n|j        }|d|j        |j        |j        ff}nut          || j        j                  r[| j                            d                    d                     | j                            t+          j        |                     dS t.                              | |           dS )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   HASHED_HASHED_DTYPEzutf-8N)r;   rp   ndarraydtype	hasobjectshapeflattenflagsc_contiguousf_contiguousTr-   r4   rq   viewuint8rn   memmaprB   stridesencoder1   r8   r"   rC   )r   r6   obj_c_contiguousklasss       r   rC   zNumpyHasher.save   s   
 c47?++ 9	CI4G 9	 yB $';;==  ' 1#&  ' 1#&5  
 $';;==  J 0 5 5dgm D DEEG G G  &JsDGN$C$C & 
 8SY	3;GHCCTW]++ 	  Jo44W==>>>Jfl3//000FD#r   Nr#   F)r   r   r   r   r   rC   r   r   r   rj   rj      sA         ) ) ) )(? ? ? ? ?r   rj   r#   Fc                     d}||vr#t          d                    ||                    dt          j        v rt	          ||          }nt          |          }|                    |           S )aj   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.ro   )r.   rn   rl   )
ValueErrorformatrR   rS   rj   r"   r	   )r6   r.   rn   valid_hash_nameshashers        r   r	   r	      s     '((( 7 &!19==? ? 	? #+ykJJJ),,,;;sr   r   )r   r1   r+   rR   r<   rc   r'   r   _Picklerr*   rg   r   r   r"   rj   r	   r   r   r   <module>r      s9      



   				  /E E E E EV E E E$    f   h% h% h% h% h%W h% h% h%VW W W W W& W W Wt     r   