
    g                        d Z ddlmZ ddlmZ  G d de      Z e       Zej                  Zej                  Z	ddl
mZmZ d Zd Zd	 ZddZ edd      j#                         Z edd      Zej#                         dk(  rd
Zn		  ee      Zedk(  reZn'edk(  r	 ee      Znedk(  r	 ee      Zn edez        d ZdededefdZy
# e$ r  eddez  z         w xY w)z Caching facility for SymPy     )import_module)Callablec                       e Zd ZdZd Zd Zy)_cachez List of cached functions c                     | D ]`  }|j                   }|}t        |d      r6t        |d      r|j                         }n|j                  }t        |d      r6d}t	        ||       b y)zprint cache info__wrapped__
cache_infoN)__name__hasattrr	   r   print)selfitemnamemyfuncinfos        E/var/www/openai/venv/lib/python3.12/site-packages/sympy/core/cache.pyprint_cachez_cache.print_cache   si     D==DF&-06<0!,,.D#//F &-0 $     c                     | D ]G  }|}t        |d      st        |d      r|j                          /|j                  }t        |d      r6I y)zclear cache contentr   cache_clearN)r   r   r   )r   r   r   s      r   clear_cachez_cache.clear_cache   sK    DF&-06=1&&(#//F &-0 r   N)r
   
__module____qualname____doc__r   r    r   r   r   r      s    $"	0r   r   )	lru_cachewrapsc                       f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                       t        d             t                fd       }j                  |_        j                  |_        t        j                  |       |S )NT)typedc                      	  | i |}|S # t         $ r>}|j                  r|j                  d   j                  d      s  | i |}Y d }~|S d }~ww xY w)Nr   zunhashable type:)	TypeErrorargs
startswith)r#   kwargsretvalecfuncfuncs       r   wrapperz0__cacheit.<locals>.func_wrapper.<locals>.wrapperE   sd    ///
 M	  /vvQVVAY%9%9:L%Mt.v.M	/s    	A3AA)r   r   r	   r   CACHEappendr)   r*   r(   maxsizes   ` @r   func_wrapperz__cacheit.<locals>.func_wrapperB   s[    .	'.t4	t	 
	 #--#//Wr   r   r.   r/   s   ` r   	__cacheitr1   -   s    *& r   c                     | S Nr   )r)   s    r   __cacheit_nocacher4   Y   s    Kr   c                       fd}|S )z)cacheit + code to check cache consistencyc                 V      t                     t                fd       }|S )Nc                  t     | i |} | i |}t        |      t        |      f ||k7  rt        d      |S )Nz Returned values are not the same)hashRuntimeError)r#   kw_argsr1r2r(   r)   s       r   r*   z6__cacheit_debug.<locals>.func_wrapper.<locals>.wrapperb   sO     t'w'B((B Hd2h Rx"#EFFIr   )r1   r   r-   s   ` @r   r/   z%__cacheit_debug.<locals>.func_wrapper_   s1    "	'"4(	t	 
	( r   r   r0   s   ` r   __cacheit_debugr=   ]   s    2 r   Nc                      ddl m}  || |      S )Nr   )getenv)osr?   )keydefaultr?   s      r   _getenvrC   {   s    #wr   SYMPY_USE_CACHEyesSYMPY_CACHE_SIZE1000nonez2SYMPY_CACHE_SIZE must be a valid integer or None. zGot: %snodebugz*unrecognized value for SYMPY_USE_CACHE: %sc                 ^     d j                   z   t                fd}t        |      S )z"Decorator to cache property method__c                 T    t        |       }|u r |       }t        | |       |S r3   )getattrsetattr)r   val_cached_property_sentinelattrnamer)   s     r   propfuncz!cached_property.<locals>.propfunc   s5    dH&?@++t*CD(C(
r   )r
   objectproperty)r)   rS   rQ   rR   s   ` @@r   cached_propertyrV      s+    dmm#H & Hr   moduler   returnc                 r     d fd G  fddt               } G  f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                  6     t        t                      S r3   rN   r   )r)   rW   r   s   r   _get_functionz$lazy_function.<locals>._get_function   s    <=0$7Dr   c                   &    e Zd Ze fd       Zy)'lazy_function.<locals>.LazyFunctionMetac                 p            j                   }|d| j                  j                   d d dz  }|S Nz

Note: this is a z wrapper of '.'r   	__class__r
   r   	docstringr\   rW   r   s     r   r   z/lazy_function.<locals>.LazyFunctionMeta.__doc__   G    %//I/0G0G/HV\U]]^_c^ddeffIr   N)r
   r   r   rU   r   )r\   rW   r   s   r   LazyFunctionMetar^      s    		 
	r   rh   c                   T     e Zd ZfdZefd       ZfdZ fdZ xZS )#lazy_function.<locals>.LazyFunctionc                 B    t        t                     |i |S r3   r[   )r   r#   r%   r)   rW   r   s      r   __call__z,lazy_function.<locals>.LazyFunction.__call__   s+     |}V4d;(((r   c                 p            j                   }|d| j                  j                   d d dz  }|S r`   rc   re   s     r   r   z+lazy_function.<locals>.LazyFunction.__doc__   rg   r   c                 .            j                         S r3   )__str__)r   r\   s    r   ro   z+lazy_function.<locals>.LazyFunction.__str__   s     ?**,,r   c           	      J    dj                    dt        |       dd d d	S )N<z object at 0xxz>: wrapping 'ra   rb   )r
   id)r   rd   rW   r   s    r   __repr__z,lazy_function.<locals>.LazyFunction.__repr__   s7    y))*-4|=QWPXXYZ^Y__`aar   )	r
   r   r   rl   rU   r   ro   rt   __classcell__)rd   r\   r)   rW   r   s   @r   LazyFunctionrj      s-    	) 
	 
	
	-	b 	br   rv   )	metaclass)type)rW   r   rh   rv   r\   r)   s   ``  @@r   lazy_functionry      s?     D 4 b b!1 b( >r   r3   )r   	importlibr   typingr   listr   r+   r   r   	functoolsr   r   r1   r4   r=   rC   lower	USE_CACHEscsrF   int
ValueErrorr9   cacheitrV   strry   r   r   r   <module>r      s6   " # 0T 0B 	 &(X< 
 %u-335	
  &)99;&*s8 G%()G'./G
4y@B B
*3 *s *x *;  *@(()* 	**s   C
 
C