U
    ZÊ¹j  ã                   @   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ršdZn2zeeƒZW n$ ek
rÊ   edde  ƒ‚Y nX edkrÚeZn2edkrìe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/bwave/python/venv/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 )	z‰Create 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   !,

ÿÿ



ÿ