Ë
    æÿæiÆ)  ã                   ó¸   — 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y)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y)Ú_ConsistentSetz\Class used to ensure the hash of Sets is preserved
    whatever the order of its items.
    c                 ó’   — 	 t        |«      | _        y # t        t        j                  f$ r t        d„ |D «       «      | _        Y y w xY w)Nc              3   ó2   K  — | ]  }t        |«      –— Œ y ­w©N©Úhash)Ú.0Úes     úc/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/joblib/hashing.pyÚ	<genexpr>z*_ConsistentSet.__init__.<locals>.<genexpr>%   s   è ø€ Ð$C±l°¤T¨!§W±lùs   ‚)ÚsortedÚ	_sequenceÚ	TypeErrorÚdecimalÚInvalidOperation)ÚselfÚset_sequences     r   Ú__init__z_ConsistentSet.__init__   sF   € ð		Eô
 $ LÓ1ˆD�NøÜœ7×3Ñ3Ð4ò 	Eô $Ñ$C±lÓ$CÓDˆDŽNð	Eús   ‚ “0AÁAN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   © ó    r   r   r      s   „ ñóEr   r   c                   ó   — e Zd ZdZd„ Zy)Ú_MyHashz5Class used to hash objects that won't normally picklec                 ó   — || _         y r   )Úargs)r   r    s     r   r   z_MyHash.__init__+   s	   € Øˆ�	r   Nr   r   r   r   r   r   (   s
   „ Ù?ó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                  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«       «      <   y)Ú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.
    c                 ó¶   — t        j                  «       | _        d}t        j	                  | | j                  |¬«       t        j                  |d¬«      | _        y )Né   )ÚprotocolF)Úusedforsecurity)ÚioÚBytesIOÚstreamÚPicklerr   ÚhashlibÚnewÚ_hash)r   Ú	hash_namer%   s      r   r   zHasher.__init__5   sA   € Ü—j‘j“lˆŒð ˆÜ×Ñ˜˜tŸ{™{°XÐÔ>ä—[‘[ ¸EÔBˆ�
r   c                 ó:  — 	 | j                  |«       | j                  j                  «       }| j                  j                  |«       |r| j                  j                  «       S y # t        j                  $ r"}|xj                  d|›d|›�fz  c_        ‚ d }~ww xY w)NzPicklingError while hashing z: )	ÚdumpÚpickleÚPicklingErrorr    r)   Úgetvaluer-   ÚupdateÚ	hexdigest)r   ÚobjÚreturn_digestr   Údumpss        r   r	   zHasher.hash>   s„   € ð	Ø�I‰I�cŒNð —‘×$Ñ$Ó&ˆØ�
‰
×Ñ˜%Ô ÙØ—:‘:×'Ñ'Ó)Ð)ð øô ×#Ñ#ò 	Ø�F‹FºsÁAÐFÐHÑH�FØûð	ús   ‚A% Á%BÁ8BÂBc                 óÊ  — t        |t        j                  t        i j                  «      f«      ržt        |d«      r|j                  j                  }n|j                  }|j                  }t        |«      t        t        «      u rt        ||j                  «      }n2|€t        ||«      }n#|j                  j                  }t        |||«      }t        j                  | |«       y )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.saveI   s¨   € Ü�cœE×,Ñ,¬d°2·6±6«lÐ;Ô<ô �s˜JÔ'ØŸL™L×1Ñ1‘	àŸL™L�	Ø—<‘<ˆDÜ�D‹zœT¤&›\Ñ)Ü˜i¨¯©Ó7‘Ø�ä˜i¨Ó.‘à—l‘l×,Ñ,�Ü˜i¨¨sÓ3�Ü�‰�T˜3Õr   c                 ó^   — t        |t        t        f«      ry t        j	                  | |«       y r   )r;   ÚbytesÚstrr*   Úmemoize)r   r6   s     r   rJ   zHasher.memoize\   s#   € ô
 �cœE¤3˜<Ô(ØÜ�‰˜˜cÕ"r   Nc                 óX  — t        ||¬«      }|d= 	 t        j                  | |fi |¤Ž y # t        j                  $ rl t        j                  | |fi |¤Ž t        |dd «      }|dk(  r@|}|€|j                  }t        j                  |   }t        ||«      st        |||«       Y y Y y Y y 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_globalg   s´   € ô ˜4 dÔ+ˆØ�6ˆNð	/Ü×Ñ  cÑ4¨VÓ4øÜ×#Ñ#ò 	/Ü×Ñ  cÑ4¨VÒ4Ü˜S ,°Ó5ˆFØ˜Ò#Ø�Ø�?Ø!Ÿl™l�GÜ—k‘k &Ñ)�Ü˜s GÔ,ô ˜C ¨#Ö.ñ -ñ $ð	/ús   ’* ªA8B)Â(B)c           
      óÖ   — 	 t        j                  | t        t        |«      «      g|¢­Ž  y # t        $ r3 t        j                  | t        t        d„ |D «       «      «      g|¢­Ž  Y y w xY w)Nc              3   ó<   K  — | ]  \  }}t        |«      |f–— Œ y ­wr   r   )r
   ÚkÚvs      r   r   z)Hasher._batch_setitems.<locals>.<genexpr>”   s   è ø€ Ð!A¹5±4°1°a¤4¨£7¨A¤,¹5ùs   ‚)r*   Ú_batch_setitemsÚiterr   r   )r   Úitemsr    s      r   r]   zHasher._batch_setitemsˆ   sc   € ð	ô
 ×#Ñ# D¬$¬v°e«}Ó*=ÐEÀÔEøÜò 	ô ×#Ñ#Ø”dœ6Ñ!A¹5Ó!AÓAÓBðØEIõð	ús   ‚), ¬9A(Á'A(c                 óB   — t         j                  | t        |«      «       y r   )r*   rC   r   )r   Ú	set_itemss     r   Úsave_setzHasher.save_set—   s   € ä�‰�Tœ>¨)Ó4Õ5r   )Úmd5)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›   „ ñó
Có	*ò ò&#ð %)¨v¯{©{ó /ð* ×Ñ×$Ñ$Ó&€Hà%€H‰T�#‹YÑà(€H‰T�&‹\Ñà)€H‰T�'‹]Ñà"-€H‰T�&—+‘+ÓÑòò6ð %€H‰T‘#“%‹[Òr   r"   c                   ó   — e Zd ZdZdd„Zd„ Zy)ÚNumpyHasherz1Special case the hasher for when numpy is loaded.c                 ó¨   — || _         t        j                  | |¬«       ddl}|| _        t        |d«      r|j                  | _        yt        | _        y)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Únpr@   rn   Ú
_getbufferÚ
memoryview)r   r.   ro   rq   s       r   r   zNumpyHasher.__init__¡   sB   € ð 'ˆÔÜ�‰˜¨	ˆÔ2ãàˆŒÜ�2�{Ô#Ø Ÿl™lˆD�Oä(ˆD�Or   c                 óð  — t        || j                  j                  «      �rF|j                  j                  �s/|j
                  dk(  r|j                  «       }nL|j                  j                  r|}n3|j                  j                  r|j                  }n|j                  «       }| j                  j                  | j                  |j                  | j                  j                  «      «      «       | j                   r7t        || j                  j"                  «      r| j                  j                  }n|j$                  }|d|j                  |j
                  |j&                  ff}nyt        || j                  j                  «      rY| j                  j                  dj)                  d«      «       | j                  j                  t+        j,                  |«      «       yt.        j1                  | |«       y)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;   rq   ÚndarrayÚdtypeÚ	hasobjectÚshapeÚflattenÚflagsÚc_contiguousÚf_contiguousÚTr-   r4   rr   ÚviewÚuint8ro   ÚmemmaprB   ÚstridesÚencoder1   r8   r"   rC   )r   r6   Úobj_c_contiguousÚklasss       r   rC   zNumpyHasher.save¶   sX  € ô
 �c˜4Ÿ7™7Ÿ?™?Õ+°C·I±I×4GÓ4Gð �y‰y˜BŠð $'§;¡;£=Ñ Ø—‘×'Ò'Ø#&Ñ Ø—‘×'Ò'Ø#&§5¡5Ñ ð
 $'§;¡;£=Ð ð �J‰J×Ñ˜dŸo™oÐ.>×.CÑ.CÀDÇGÁGÇMÁMÓ.RÓSÔTð
 ×Ò¤J¨s°D·G±G·N±NÔ$Cð Ÿ™Ÿ™‘àŸ™�ð
 ˜8 S§Y¡Y°·	±	¸3¿;¹;ÐGÐH‰CÜ˜˜TŸW™WŸ]™]Ô+ð  �J‰J×Ñ˜o×4Ñ4°WÓ=Ô>Ø�J‰J×ÑœfŸl™l¨3Ó/Ô0ØÜ�‰�D˜#Õr   N©rc   F)r   r   r   r   r   rC   r   r   r   rk   rk   ž   s   „ Ù;ó)ó*>r   rk   c                 ó¾   — d}||vrt        dj                  ||«      «      ‚dt        j                  v rt	        ||¬«      }nt        |¬«      }|j                  | «      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
    )rc   Úsha1zAValid options for 'hash_name' are {}. Got hash_name={!r} instead.rp   )r.   ro   rm   )Ú
ValueErrorÚformatrR   rS   rk   r"   r	   )r6   r.   ro   Úvalid_hash_namesÚhashers        r   r	   r	   ÷   sf   € ð 'ÐØÐ(Ñ(ÜØO×VÑVØ  )óó
ð 	
ð
 ”#—+‘+ÑÜ y¸kÔJ‰ä )Ô,ˆØ�;‰;�sÓÐr   r‡   )r   r   r+   r'   r1   rd   rR   r<   Ú_Picklerr*   rh   r   r   r"   rk   r	   r   r   r   Ú<module>r�      sg   ðñó Û Û 	Û Û Û 
Û à
�/‰/€ôE�Vô Eô&ˆfô ôl%ˆWô l%ô^V�&ô Vôrr   