o
    FZh                     @   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rMdZnzeeZW n eyb   edde  w edkrjeZnedkrseeZnedkr|eeZnede dd Zdededef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   sT   | D ]%}|j }|}t|dr t|dr| }n
|j}t|dsd}t|| qdS )zprint cache info__wrapped__
cache_infoN)__name__hasattrr   r   print)selfitemnamemyfuncinfo r   ?/var/www/auris/lib/python3.10/site-packages/sympy/core/cache.pyprint_cache   s   


z_cache.print_cachec                 C   s@   | D ]}|}t |drt |dr|  n|j}t |ds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                        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               
      sb   z
 | i |}W |S  t y0 } z|jr|jd ds | i |}W Y d }~|S d }~ww )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                    r   )z)cacheit + code to check cache consistencyc                    s&   t  t fdd}|S )Nc                     s@   | i |} | i |}t |t |f ||krt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   r2   Nc                 C   s   ddl m} || |S )Nr   )getenv)osr3   )keydefaultr3   r   r   r   _getenv{   s   
r7   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 |  }| u 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"   rC   r   rA   r   cached_property   s   
rF   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 u rt t  S r,   r>   r   r   r"   rG   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                    ,     j }|d| jj d d d7 }|S Nz

Note: this is a z wrapper of '.'r   	__class__r   r
   	docstringrK   rG   r   r   r   r          z/lazy_function.<locals>.LazyFunctionMeta.__doc__N)r   r   r   rE   r   r   rT   r   r   LazyFunctionMeta   s    rV   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 u rt t  |i |S r,   rI   )r
   r   r   rJ   r   r   __call__   s   z,lazy_function.<locals>.LazyFunction.__call__c                    rL   rM   rP   rR   rT   r   r   r      rU   z+lazy_function.<locals>.LazyFunction.__doc__c                    s
       S r,   )__str__r
   )rK   r   r   rX      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 'rN   rO   )r   idrY   )rQ   rG   r   r   r   __repr__   s   &z,lazy_function.<locals>.LazyFunction.__repr__)	r   r   r   rW   rE   r   rX   r]   __classcell__r   rK   r"   rG   r   )rQ   r   LazyFunction   s    r`   )	metaclass)type)rG   r   rV   r`   r   r_   r   lazy_function   s
   rc   r,   )r   	importlibr   typingr   listr   r$   r   r   	functoolsr   r   r+   r-   r2   r7   lowerZ	USE_CACHEZscsr9   int
ValueErrorr/   ZcacheitrF   strrc   r   r   r   r   <module>   sH    !,



