o
    "if                     @   sF  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y%   dZY nw 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re`%eej& D ]Z'ee' qe  dS )z@
Module to show if an object has changed since it was memorised
    NTFgetrefcountc                 C   s   dS )Nr    )xr   r   D/var/www/html/corbot_env/lib/python3.10/site-packages/dill/__diff.py<lambda>   s    r   c                 c   s    | ]}t |V  qd S N)id.0ir   r   r   	<genexpr>!   s    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w t}||v r*|| r(|| dr&|  S | S dS tr@|tjtjj	j
fv r@| jr>| jr>| S g S || drm|| drm|| drm||drm||drm||drmd||< || drk|  S | S d||< dS )z9
    Gets all the items in a sequence or return None
    copy__contains____iter____len__TFN)	__class__AttributeErrorr   hasattrr   	HAS_NUMPYnumpyndarraymacoreMaskedConstantshapesize)r   cacheo_typehsattrr   r   r   get_seq/   s>   


r%   c                    sD  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 r5d}n$t|drHt fdd| D }nt|dsPd}n	 fdd|D }||ft|< | t|< t	|durtfd	d| D  |durt|drfd
d| D  dS t|drfdd|D  dS | dS 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   _       zmemorise.<locals>.<genexpr>itemsc                 3   s$    | ]\}} | |fV  qd S r   r   r&   r)   r   r   r   e   s   " r   c                       g | ]} |qS r   r   r	   r)   r   r   
<listcomp>i       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'   itemr0   r   r   r.   s   s    c                    r-   r   r   )r
   r2   r0   r   r   r.   w   r/   )
r   memo	dont_memor   dictr,   r%   r   	id_to_objmemorise)r   forceobj_idgattrs_idsseq_idr   )r*   r1   r   r7   Q   s<   





r7   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   itopmpsrcr   r   r.   }   s    z release_gone.<locals>.<listcomp>)r6   popr3   r   listr,   r   r   r?   r   release_gone{   s   "rE   c                    s  |rdt jv r	t `|du ri }t| }||v r#|rt|| S || S |tv r5i dg||< |r1dS || S |tvrE|r=dS tdt|  i df||< t	}t}t
|   du rZi }n1t| d }|j}	t fdd|D }  D ]\}
}|||	|
dks|||ddr|||
< qrt| }d}|durt|d	rt| d
 }t|t|krd}nIt| dr|j}	| D ] \}
}|||	||
ks||
|dds|||ddrd} nqnt||D ]\}}|||ks|||ddrd} n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   rF   r   anyr4   r3   RuntimeErrorstrwhats_changedr   getr5   r,   r%   r   lenzip)r   seensimplefirstr9   chngdr*   changed	obj_attrsobj_getr'   or,   seq_diffobj_seqr2   r   jr   rG   r   rN      sv   	
 

rN   c                  O   s   d|d< t | i |S )NTrS   )rN   )argskwdsr   r   r   has_changed   s   r_   c                  O   sL   t tj }t| i |}t tj |}|D ]	}ttj|  q|S )zn
    Replaces the default __import__, to allow a module to be memorised
    before the user can change it
    )setsysmoduleskeys
__import__
differencer7   )r]   r^   beforemodaftermr   r   r   _imp   s   rj   rF   )F)NFT)(__doc__rJ   osra   typesr   r   ImportErrorr   r   r3   r6   r`   rM   rD   r5   	frozensetintr   rb   path_importer_cacheenvironr4   r   tupler   
ModuleTypeFunctionTypeBuiltinFunctionTyper%   r7   rE   rN   r_   rd   rj   r   rF   valuesrg   r   r   r   r   <module>   sH   


"*
N


