a
    Df                     @   sJ  d Z ddlZddlZddlZddlZzddlZdZW n eyJ   dZY n0 eeddd Z	i Z
i ZeeeeeeefZedd	 e
ejejejefD Zd
d Zedededededededejdejdejdi
fddZdddZdd ZdddZ dd Z!e"Z"dd Z#e#e_"e$edr"e`%eej& D ]Z'ee' q0e  dS )z@
Module to show if an object has changed since it was memorised
    NTFgetrefcountc                 C   s   dS )Nr    )xr   r   X/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/dill/__diff.py<lambda>       r   c                 c   s   | ]}t |V  qd S N)id.0ir   r   r   	<genexpr>!   r   r   c                 C   s0   t | tv s t | t u r$| tv r$dS t| ddS )zQ
    Gets all the attributes of an object though its __dict__ or return None
    N__dict__)typebuiltins_typesgetattr)objr   r   r   	get_attrs%   s    
r   c                 C   s   z
| j }W n ty$   t| }Y n0 t}||v rR|| r|| drL|  S | S ntr|tjtjj	j
fv r| jrz| jrz| S g S nf|| dr|| dr|| dr||dr||dr||drd||< || dr|  S | S d||< dS dS )z9
    Gets all the items in a sequence or return None
    copy__contains____iter____len__TFN)	__class__AttributeErrorr   hasattrr   	HAS_NUMPYnumpyZndarraymacoreZMaskedConstantshapesize)r   cacheZo_typeZhsattrr   r   r   get_seq/   s:    


r"   c                    sB  t | }|tv r|r|tv r dS t  t| }|du r:d}nt fdd| D }t| }|du rjd}nHt|drt fdd| D }n"t|dsd}n fdd|D }||ft|< | t|< t	|durfd	d| D  |dur>t|drfd
d| D  n(t|dr6fdd|D  n| dS )z
    Adds an object to the memo, and recursively adds all the objects
    attributes, and if it is a container, its items. Use force=True to update
    an object already in the memo. Updating is not recursively done.
    Nc                 3   s   | ]\}}| |fV  qd S r   r   r   keyvalueid_r   r   r   _   r   zmemorise.<locals>.<genexpr>itemsc                 3   s"   | ]\}} | |fV  qd S r   r   r#   r&   r   r   r   e   r   r   c                    s   g | ]} |qS r   r   r
   r&   r   r   
<listcomp>i   r   zmemorise.<locals>.<listcomp>c                    s   g | ]\}} |qS r   r   r#   memr   r   r)   o   r   c                    s    g | ]\}} | |fqS r   r   )r   r$   itemr*   r   r   r)   s   s   c                    s   g | ]} |qS r   r   )r   r,   r*   r   r   r)   w   r   )
r	   memo	dont_memor   dictr(   r"   r   	id_to_objmemorise)r   forceobj_idgZattrs_idsZseq_idr   )r'   r+   r   r1   Q   s:    



r1   c                      s6   t jtjt    fddtt  D  d S )Nc                    s,   g | ]$\}}|d k r ||fqS )   r   )r   r'   r   Zitopmpsrcr   r   r)   }   s   z release_gone.<locals>.<listcomp>)r0   popr-   r   listr(   r   r   r7   r   release_gone{   s    r<   c                    s(  |rdt jv rt `|du ri }t| }||v rF|r>t|| S || S |tv rji dg||< |rbdS || S |tvr|rzdS tdt|  i df||< t	}t}t
|   du ri }ndt| d }|j}	t fdd|D }  D ]2\}
}|||	|
dks|||ddr|||
< qt| }d}|durt|d	rt| d
 }t|t|kr^d}nt| dr|j}	| D ]J\}
}|||	||
ks||
|dds|||ddrxd} qqxn>t||D ]2\}}|||ks|||ddrd} qq||f||< |r |p|S ||fS )aG  
    Check an object against the memo. Returns a list in the form
    (attribute changes, container changed). Attribute changes is a dict of
    attribute name to attribute value. container changed is a boolean.
    If simple is true, just returns a boolean. None for either item means
    that it has not been checked yet
    _NFTzObject not memorised r   c                 3   s   | ]}| vr|d fV  qd S r   r   )r   r$   attrsr   r   r      r   z whats_changed.<locals>.<genexpr>r      r(   )builtinsr   r=   r	   anyr.   r-   RuntimeErrorstrwhats_changedr   getr/   r(   r"   r   lenzip)r   seensimplefirstr3   Zchngdr'   changedZ	obj_attrsZobj_getr$   or(   Zseq_diffZobj_seqr,   r   jr   r>   r   rE      sn    	
"


rE   c                  O   s   d|d< t | i |S )NTrJ   )rE   )argskwdsr   r   r   has_changed   s    rQ   c                  O   sL   t tj }t| i |}t tj |}|D ]}ttj|  q4|S )zn
    Replaces the default __import__, to allow a module to be memorised
    before the user can change it
    )setsysmoduleskeys
__import__
differencer1   )rO   rP   beforemodaftermr   r   r   _imp   s    r\   r=   )F)NFT)(__doc__rA   osrS   typesr   r   ImportErrorr   r   r-   r0   rR   rD   r;   r/   	frozensetintr   rT   path_importer_cacheenvironr.   r   tupler   
ModuleTypeFunctionTypeBuiltinFunctionTyper"   r1   r<   rE   rQ   rV   r\   r   r=   valuesrY   r   r   r   r   <module>	   sD   


"
*
N