
    HWh')                         S r SSKrSSKrSSKrSSKrSSKrSSKrSSKr\R                  r	 " S S\
5      r " S S\
5      r " S S\	5      r " S	 S
\5      rSS jrg)zb
Fast cryptographic hash of Python objects, with a special case for fast
hashing of numpy arrays.
    Nc                       \ rS rSrSrS rSrg)_ConsistentSet   zTClass used to ensure the hash of Sets is preserved
whatever the order of its items.
c                      [        U5      U l        g ! [        [        R                  4 a    [        S U 5       5      U l         g f = f)Nc              3   8   #    U  H  n[        U5      v   M     g 7fNhash).0es     0/usr/lib/python3/dist-packages/joblib/hashing.py	<genexpr>*_ConsistentSet.__init__.<locals>.<genexpr>%   s     $ClT!WWls   )sorted	_sequence	TypeErrordecimalInvalidOperation)selfset_sequences     r   __init___ConsistentSet.__init__   sF    		E
 $L1DN7334 	E $$Cl$CDDN	Es    1AA)r   N__name__
__module____qualname____firstlineno____doc__r   __static_attributes__     r   r   r      s    Er!   r   c                       \ rS rSrSrS rSrg)_MyHash(   z6Class used to hash objects that won't normally pickle c                     Xl         g r   args)r   r'   s     r   r   _MyHash.__init__+   s    	r!   r&   Nr   r    r!   r   r#   r#   (   s
    Ar!   r#   c                   &   \ rS rSrSrSS jrSS jrS rS rS\	R                  4S jr\R                  R                  5       r\\\" \5      '   \\\" \5      '   \\\" \5      '   \\\" \R&                  5      '   S	 rS
 r\\\" \" 5       5      '   Srg)Hasher/   zJA subclass of pickler, to do cryptographic hashing, rather than
pickling.
c                     [         R                  " 5       U l        Sn[        R	                  X R                  US9  [
        R                  " U5      U l        g )N   )protocol)ioBytesIOstreamPicklerr   hashlibnew_hash)r   	hash_namer.   s      r   r   Hasher.__init__4   s=    jjl {{X>[[+
r!   c                 J    U R                  U5        U R                  R                  5       nU R                  R                  U5        U(       a  U R                  R                  5       $ g ! [        R                   a$  nU=R                  SU< SU< 34-  sl        e S nAff = f)NzPicklingError while hashing z: )	dumppicklePicklingErrorr'   r1   getvaluer5   update	hexdigest)r   objreturn_digestr   dumpss        r   r
   Hasher.hash=   s    	IIcN $$&

% ::''))  ## 	FFsAFHHF	s   A* *B">BB"c                    [        U[        R                  [        0 R                  5      45      (       a  [        US5      (       a  UR                  R                  nOUR                  nUR                  n[        U5      [        [        5      L a  [        X#R                  5      nO1Uc  [        X#5      nO"UR                  R                  n[        X#U5      n[        R                  X5        g )N__func__)
isinstancetypes
MethodTypetypepophasattrrD   r   __self__r:   r#   	__class__r2   save)r   r?   	func_nameinstclss        r   rM   Hasher.saveH   s    cE,,d266l;<< sJ''LL11	LL	<<DDzT&\)i7i.ll,,is3Tr!   c                 f    [        U[        [        45      (       a  g [        R	                  X5        g r   )rE   bytesstrr2   memoize)r   r?   s     r   rU   Hasher.memoize[   s$    
 cE3<(("r!   Nc                 \   [        X#S9nUS	  [        R                  " X40 UD6  g ! [        R                   aq    [        R                  " X40 UD6  [        USS 5      nUS:X  aD  UnUc  UR                  n[        R                  U   n[        Xv5      (       d  [        XvU5         g  g  g f = f)N)namepackrY   r   __main__)dictr2   save_globalr:   r;   getattrr   sysmodulesrJ   setattr)r   r?   rX   rY   kwargsmodulemy_namemods           r   r\   Hasher.save_globalf   s     4+6N	/4V4## 	/4V4S,5F#?!llGkk&)s,, C#. - $	/s   & A>B+*B+c           
           [         R                  U [        [        U5      5      5        g ! [         a2    [         R                  U [        [        S U 5       5      5      5         g f = f)Nc              3   @   #    U  H  u  p[        U5      U4v   M     g 7fr   r	   )r   kvs      r   r   )Hasher._batch_setitems.<locals>.<genexpr>   s"      6IBG$! 8<AwlBGs   )r2   _batch_setitemsiterr   r   )r   itemss     r   rk   Hasher._batch_setitems   sf    
	K
 ##D$ve}*=> 	K ##D$v 6IBG6I 0I +J K	Ks   (+ 9A'&A'c                 B    [         R                  U [        U5      5        g r   )r2   rM   r   )r   	set_itemss     r   save_setHasher.save_set   s    T>)45r!   )r5   r1   )md5)T)r   r   r   r   r   r   r
   rM   rU   structrY   r\   r2   dispatchcopyrH   lenobjectr:   r9   rk   rq   setr   r    r!   r   r*   r*   /   s    ,	* &# %)v{{ /* $$&H%HT#Y(HT&\)HT']"-HT&++K6 %HT#%[r!   r*   c                   (    \ rS rSrSrSS jrS rSrg)NumpyHasher   z6Special case the hasher for when numpy is loaded.
    c                     X l         [        R                  XS9  SSKnX0l        [        US5      (       a  UR                  U l        g[        U l        g)z
Parameters
----------
hash_name: string
    The hash algorithm to be used
coerce_mmap: boolean
    Make no difference between np.memmap and np.ndarray
    objects.
r6   r   N	getbuffer)	coerce_mmapr*   r   numpynprJ   r   
_getbuffer
memoryview)r   r6   r   r   s       r   r   NumpyHasher.__init__   s?     '22{## llDO(DOr!   c                 2   [        XR                  R                  5      (       Ga_  UR                  R                  (       GdC  UR
                  S:X  a  UR                  5       nOVUR                  R                  (       a  UnO8UR                  R                  (       a  UR                  nOUR                  5       nU R                  R                  U R                  UR                  U R                  R                  5      5      5        U R                   (       a;  [        XR                  R"                  5      (       a  U R                  R                  nOUR$                  nUSUR                  UR
                  UR&                  44nO~[        XR                  R                  5      (       aZ  U R                  R                  SR)                  S5      5        U R                  R                  [*        R,                  " U5      5        g[.        R1                  X5        g)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)rE   r   ndarraydtype	hasobjectshapeflattenflagsc_contiguousf_contiguousTr5   r=   r   viewuint8r   memmaprL   stridesencoder:   rA   r*   rM   )r   r?   obj_c_contiguousklasss       r   rM   NumpyHasher.save   s`   
 c77??++CII4G4G4G yyB $';;= ''#& ''#&55 
 $';;=  JJ 0 5 5dggmm DEG JsGGNN$C$C 
 8SYY		3;;GHCWW]]++  JJo44W=>JJfll3/0Dr!   )r   r   r   Nrs   F)r   r   r   r   r   r   rM   r   r    r!   r   r{   r{      s    )(?r!   r{   c                     SnX;  a  [        SR                  X15      5      eS[        R                  ;   a
  [	        XS9nO	[        US9nUR                  U 5      $ )a%  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
)rs   sha1zAValid options for 'hash_name' are {}. Got hash_name={!r} instead.r   )r6   r   r~   )
ValueErrorformatr^   r_   r{   r*   r
   )r?   r6   r   valid_hash_nameshashers        r   r
   r
      s^     '( 7 &!1=? 	? #++yJ),;;sr!   r   )r   r:   r3   r^   rF   rt   r/   r   _Picklerr2   rx   r   r#   r*   r{   r
   r    r!   r   <module>r      si      
   	  //EV E$f h%W h%VW& Wtr!   