o
    Ô2úh,  ã                   @   sH   d Z ddlZddlZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )	zCaching utilities.é    Nc                   @   s<   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )Ú_TransformedFnCachea5  Generic hierarchical cache for transformed functions.

  The keys are soft references (i.e. they are discarded when the key is
  destroyed) created from the source function by `_get_key`. The subkeys are
  strong references and can be any value. Typically they identify different
  kinds of transformation.
  )Ú_cachec                 C   s   t  ¡ | _d S ©N)ÚweakrefÚWeakKeyDictionaryr   ©Úself© r	   úa/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorflow/python/autograph/pyct/cache.pyÚ__init__!   s   z_TransformedFnCache.__init__c                 C   s   t dƒ‚)Nzsubclasses must override)ÚNotImplementedError©r   Úentityr	   r	   r
   Ú_get_key$   s   z_TransformedFnCache._get_keyc                 C   s,   |   |¡}| j |d ¡}|d u rdS ||v S )NF©r   r   Úget)r   r   ÚsubkeyÚkeyÚparentr	   r	   r
   Úhas'   s
   
z_TransformedFnCache.hasc                 C   s2   |   |¡}| j |d ¡}|d u ri  | j|< }|S r   r   )r   r   r   r   r	   r	   r
   Ú__getitem__.   s
   
z_TransformedFnCache.__getitem__c                 C   s
   t | jƒS r   )Úlenr   r   r	   r	   r
   Ú__len__7   s   
z_TransformedFnCache.__len__N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r   r   r	   r	   r	   r
   r      s    	r   c                   @   ó   e Zd ZdZdd„ ZdS )ÚCodeObjectCachea@  A function cache based on code objects.

  Code objects are good proxies for the source code of a function.

  This cache efficiently handles functions that share code objects, such as
  functions defined in a loop, bound methods, etc.

  The cache falls back to the function object, if it doesn't have a code object.
  c                 C   s   t |dƒr|jS |S )NÚ__code__)Úhasattrr    r   r	   r	   r
   r   F   s   
zCodeObjectCache._get_keyN©r   r   r   r   r   r	   r	   r	   r
   r   ;   ó    
r   c                   @   r   )ÚUnboundInstanceCacheaH  A function cache based on unbound function objects.

  Using the function for the cache key allows efficient handling of object
  methods.

  Unlike the _CodeObjectCache, this discriminates between different functions
  even if they have the same code. This is needed for decorators that may
  masquerade as another function.
  c                 C   s   t  |¡r|jS |S r   )ÚinspectÚismethodÚ__func__r   r	   r	   r
   r   X   s   
zUnboundInstanceCache._get_keyNr"   r	   r	   r	   r
   r$   M   r#   r$   )r   r%   r   Úobjectr   r   r$   r	   r	   r	   r
   Ú<module>   s   %