ó
î–+[c           @   sÚ   d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z e j d d k rm d d l Z e j Z	 n d d l
 Z
 e
 j	 Z	 d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e d „ Z d S(   sb   
Fast cryptographic hash of Python objects, with a special case for fast
hashing of numpy arrays.
iÿÿÿÿNi    i   t   _ConsistentSetc           B   s   e  Z d  Z d „  Z RS(   sa    Class used to ensure the hash of Sets is preserved
        whatever the order of its items.
    c         C   s   t  | ƒ |  _ d  S(   N(   t   sortedt	   _sequence(   t   selft   set_sequence(    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyt   __init__   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyR       s   t   Hasherc           B   sÔ   e  Z d  Z d d „ Z e d „ Z d „  Z e j d d k  r­ d
 e
 j d „ Z e j j j ƒ  Z e e e e ƒ <e e e e ƒ <e e e e j ƒ <e e e e j ƒ <n  d „  Z d	 „  Z e e e e ƒ  ƒ <RS(   sW    A subclass of pickler, to do cryptographic hashing, rather than
        pickling.
    t   md5c         C   s>   t  ƒ  |  _ t j j |  |  j d d ƒt j | ƒ |  _ d  S(   Nt   protocoli   (   t   StringIOt   streamt   picklet   PicklerR   t   hashlibt   newt   _hash(   R   t	   hash_name(    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyR   '   s    c         C   sC   |  j  | ƒ |  j j ƒ  } |  j j | ƒ | r? |  j j ƒ  Sd  S(   N(   t   dumpR   t   getvalueR   t   updatet	   hexdigest(   R   t   objt   return_digestt   dumps(    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyt   hash-   s
    c         C   sY   t  | t j ƒ rB | j j } | j } | j } | | | f } n  t j j	 |  | ƒ d  S(   N(
   t
   isinstancet   typest
   MethodTypet   im_funcR   t   im_selft   im_classR   R   t   save(   R   R   t	   func_namet   instt   cls(    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyR"   4   s    		i    i   c         C   s”   t  | d d  ƒ } | d k rn | } | d  k r< | j } n  t j | } t | | ƒ sn t | | | ƒ qn n  t j j	 |  | d | d t
 j ƒd  S(   NR   t   __main__t   namet   pack(   t   getattrt   NoneR   t   syst   modulest   hasattrt   setattrR   R   t   save_globalt   structR(   (   R   R   R'   R(   t   modulet   my_namet   mod(    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyR/   A   s    c         C   s#   t  j j |  t t | ƒ ƒ ƒ d  S(   N(   R   R   t   _batch_setitemst   iterR   (   R   t   items(    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyR4   [   s    c         C   s   t  j j |  t | ƒ ƒ d  S(   N(   R   R   t	   save_instR    (   R   t	   set_items(    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyt   save_set_   s    N(   R   R   R   R   t   TrueR   R"   R+   t   version_infoR*   R0   R(   R/   R   R   t   dispatcht   copyt   typet   lent   objectR   R4   R9   t   set(    (    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyR	   "   s   	
		t   NumpyHasherc           B   s&   e  Z d  Z d e d „ Z d „  Z RS(   s7    Special case the hasher for when numpy is loaded.
    R
   c         C   s5   | |  _  t j |  d | ƒd d l } | |  _ d S(   s  
            Parameters
            ----------
            hash_name: string
                The hash algorithm to be used
            coerce_mmap: boolean
                Make no difference between np.memmap and np.ndarray
                objects.
        R   iÿÿÿÿN(   t   coerce_mmapR	   R   t   numpyt   np(   R   R   RC   RE   (    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyR   k   s    
	c         C   sæ   t  | |  j j ƒ rÒ | j j rÒ y  |  j j |  j j | ƒ ƒ Wn3 t k
 rw |  j j |  j j | j	 ƒ  ƒ ƒ n X|  j
 r¥ t  | |  j j ƒ r¥ |  j j } n	 | j } | d | j | j | j f f } n  t j |  | ƒ d S(   s¨    Subclass the save method, to hash ndarray subclass, rather
            than pickling them. Off course, this is a total abuse of
            the Pickler class.
        t   HASHEDN(   R   RE   t   ndarrayt   dtypet	   hasobjectR   R   t	   getbuffert	   TypeErrort   flattenRC   t   memmapt	   __class__t   shapet   stridesR	   R"   (   R   R   t   klass(    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyR"   {   s    " &	$(   R   R   R   t   FalseR   R"   (    (    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyRB   g   s   R
   c         C   sC   d t  j k r' t d | d | ƒ } n t d | ƒ } | j |  ƒ S(   sl   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
    RD   R   RC   (   R+   R,   RB   R	   R   (   R   R   RC   t   hasher(    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyR   œ   s    (   R   R   R   R+   R   R0   R;   t   iot   BytesIOR   t	   cStringIOR@   R    R   R	   RB   RR   R   (    (    (    sV   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/hashing.pyt   <module>   s   	E5