U
    9%e                     @   s*  d Z ddlmZ ddlmZ G dd deZe ZejZej	Z	ddl
mZmZ dd Zd	d
 Zdd ZdddZedd ZeddZe dkrdZn2zeeZW n$ ek
r   edde  Y nX edkreZn2edkreeZn edkr eeZnede dd ZeeedddZdS ) z Caching facility for SymPy     )import_module)Callablec                   @   s    e Zd ZdZdd Zdd ZdS )_cachez List of cached functions c                 C   sN   | D ]D}|j }|}t|dr:t|dr2| }q>q|j}qd}t|| qdS )zprint cache info__wrapped__
cache_infoN)__name__hasattrr   r   print)selfitemnamemyfuncinfo r   O/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/core/cache.pyprint_cache   s    

z_cache.print_cachec                 C   s:   | D ]0}|}t |drt |dr,|  qq|j}qqdS )zclear cache contentr   cache_clearN)r   r   r   )r
   r   r   r   r   r   clear_cache   s    

z_cache.clear_cacheN)r   
__module____qualname____doc__r   r   r   r   r   r   r      s   r   )	lru_cachewrapsc                    s    fdd}|S )a  caching decorator.

        important: the result of cached function must be *immutable*


        Examples
        ========

        >>> from sympy import cacheit
        >>> @cacheit
        ... def f(a, b):
        ...    return a+b

        >>> @cacheit
        ... def f(a, b): # noqa: F811
        ...    return [a, b] # <-- WRONG, returns mutable object

        to force cacheit to check returned results mutability and consistency,
        set environment variable SYMPY_USE_CACHE to 'debug'
    c                    sD   t dd t fdd} j|_ j|_t| |S )NT)typedc               
      sX   z | |}W nD t k
rR } z&|jr6|jd ds8 | |}W 5 d }~X Y nX |S )Nr   zunhashable type:)	TypeErrorargs
startswith)r   kwargsretvaleZcfuncfuncr   r   wrapperE   s    z0__cacheit.<locals>.func_wrapper.<locals>.wrapper)r   r   r   r   CACHEappendr!   r"   maxsizer    r   func_wrapperB   s    	
z__cacheit.<locals>.func_wrapperr   r'   r(   r   r&   r   	__cacheit-   s    r*   c                 C   s   | S Nr   )r!   r   r   r   __cacheit_nocacheY   s    r,   c                    s    fdd}|S )z)cacheit + code to check cache consistencyc                    s&   t  t fdd}|S )Nc                     s8   | |} | |}t |t |f ||kr4td|S )Nz Returned values are not the same)hashRuntimeError)r   Zkw_argsr1r2r    r   r   r"   b   s    

z6__cacheit_debug.<locals>.func_wrapper.<locals>.wrapper)r*   r   r%   r&   r    r   r(   _   s    z%__cacheit_debug.<locals>.func_wrapperr   r)   r   r&   r   __cacheit_debug]   s    r1   Nc                 C   s   ddl m} || |S )Nr   )getenv)osr2   )keydefaultr2   r   r   r   _getenv{   s    r6   ZSYMPY_USE_CACHEyesSYMPY_CACHE_SIZEZ1000nonez2SYMPY_CACHE_SIZE must be a valid integer or None. zGot: %snodebugz*unrecognized value for SYMPY_USE_CACHE: %sc                    s(   dj  t   fdd}t|S )z"Decorator to cache property method__c                    s,   t |  }| kr(| }t| | |S r+   )getattrsetattr)r
   valZ_cached_property_sentinelattrnamer!   r   r   propfunc   s
    z!cached_property.<locals>.propfunc)r   objectproperty)r!   rB   r   r@   r   cached_property   s    
rE   )moduler   returnc                    sN   dfdd G  fdddt }G  fddd|d}| S )	zCreate a lazy proxy for a function in a module.

    The module containing the function is not imported until the function is used.

    Nc                      s    d krt t  S r+   r=   r   r   r!   rF   r   r   r   _get_function   s    z$lazy_function.<locals>._get_functionc                       s    e Zd Ze fddZdS )z'lazy_function.<locals>.LazyFunctionMetac                    s,     j }|d| jj d d d7 }|S Nz

Note: this is a z wrapper of '.'r   	__class__r   r
   Z	docstringrJ   rF   r   r   r   r      s     z/lazy_function.<locals>.LazyFunctionMeta.__doc__N)r   r   r   rD   r   r   rQ   r   r   LazyFunctionMeta   s   rR   c                       sP   e Zd ZfddZefddZfddZ fddZ  ZS )	z#lazy_function.<locals>.LazyFunctionc                    s     d krt t  ||S r+   rH   )r
   r   r   rI   r   r   __call__   s    z,lazy_function.<locals>.LazyFunction.__call__c                    s,     j }|d| jj d d d7 }|S rK   rN   rP   rQ   r   r   r      s     z+lazy_function.<locals>.LazyFunction.__doc__c                    s
       S r+   )__str__r
   )rJ   r   r   rT      s    z+lazy_function.<locals>.LazyFunction.__str__c              	      s&   d j  dt| dd d d	S )N<z object at 0xxz>: wrapping 'rL   rM   )r   idrU   )rO   rF   r   r   r   __repr__   s    z,lazy_function.<locals>.LazyFunction.__repr__)	r   r   r   rS   rD   r   rT   rY   __classcell__r   rJ   r!   rF   r   )rO   r   LazyFunction   s
   r\   )	metaclass)type)rF   r   rR   r\   r   r[   r   lazy_function   s
    r_   )N)r   	importlibr   typingr   listr   r#   r   r   	functoolsr   r   r*   r,   r1   r6   lowerZ	USE_CACHEZscsr8   int
ValueErrorr.   ZcacheitrE   strr_   r   r   r   r   <module>   sD   !,





