U
    -e                     @   sL  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k
rL   dZY nX 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' q2e  dS )z@
Module to show if an object has changed since it was memorised
    NTFgetrefcountc                 C   s   dS )Nr    )xr   r   L/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/dill/__diff.py<lambda>       r   c                 c   s   | ]}t |V  qd S N)id.0ir   r   r   	<genexpr>!   s     r   c                 C   s0   t | tks t | t kr$| tk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k
r&   t| }Y nX t}||krT|| r|| drN|  S | S ntr|tjtjj	j
fkr| jr|| jr|| 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kr|r|tkr dS t  t| }|dkr:d}nt fdd| D }t| }|dkrjd}nHt|drt fdd| D }n"t|dsd}n fdd|D }||ft|< | t|< t	|dk	rfd	d| D  |dk	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   _   s     zmemorise.<locals>.<genexpr>itemsc                 3   s"   | ]\}} | |fV  qd S r   r   r#   r&   r   r   r   e   s     r   c                    s   g | ]} |qS r   r   r
   r&   r   r   
<listcomp>i   s     zmemorise.<locals>.<listcomp>c                    s   g | ]\}} |qS r   r   r#   memr   r   r)   o   s     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   s     )
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krt `|dkri }t| }||krF|r>t|| S || S |tkrji dg||< |rbdS || S |tkr|rzdS tdt|  i df||< t	}t}t
|   dkri }ndt| d }|j}	t fdd|D }  D ]2\}
}|||	|
dks|||ddr|||
< qt| }d}|dk	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   | ]}| kr|d fV  qd S r   r   )r   r$   attrsr   r   r      s      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 | |S )NTrJ   )rE   )argskwdsr   r   r   has_changed   s    rQ   c                  O   sH   t tj }t| |}t tj |}|D ]}ttj|  q0|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>	   sX   
 

         "
*
N