o
    ?e:'                     @   s   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ e Zd	Zed
dZdd Zdd Zdd Zdd ZG dd deZdS )z(Provides wrapper for TensorFlow modules.    N)
monitoring)
tf_logging)fast_module_type)tf_decorator)
tf_inspect)all_renames_v2   z/tensorflow/api/compat/v1zcompat.v1 usagec                 C   s   | t jvrd S t j|  S N)r   Zsymbol_renames)name r   f/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/util/module_wrapper.pyget_rename_v2    s   

r   c                  C   sT   t  } | jjjdksJ dtdD ]}| j}|du r q!|} qd| jj| jS )z|Extracts the caller filename and line number as a string.

  Returns:
    A string describing the caller source location.
  _tfmw_add_deprecation_warningzThis function should be called directly from _tfmw_add_deprecation_warning, as the caller is identified heuristically by chopping off the top stack frames.   Nz{}:{})	r   currentframef_backf_codeco_namerangeformatco_filenamef_lineno)frame_parentr   r   r   _call_location&   s   r   c                 C   s   t dd | D S )Nc                 s   s    | ]}|j d kV  qdS )
deprecatedN)Zdecorator_name).0dr   r   r   	<genexpr>>   s    z1contains_deprecation_decorator.<locals>.<genexpr>)any)
decoratorsr   r   r   contains_deprecation_decorator=   s   r"   c                 C   s\   t | \}} t|rdS t| rdS t| sdS t| ds"dS t | j\}}t|S )a%  Checks if given object has a deprecation decorator.

  We check if deprecation decorator is in decorators as well as
  whether symbol is a class whose __init__ method has a deprecation
  decorator.
  Args:
    symbol: Python object.

  Returns:
    True if symbol has deprecation decorator.
  TF__init__)r   unwrapr"   r   
isfunctionisclasshasattrr#   )symbolr!   Zinit_decoratorsr   r   r   r   has_deprecation_decoratorA   s   


r)   c                       s|   e Zd ZdZdZ			d fdd	Zdd Zd	d
 Zdd Zdd Z	 fddZ
dd Z fddZdd Zdd Z  ZS )TFModuleWrapperzGWrapper for TF modules to support deprecation messages and lazyloading.FNTc                    s   t t| |j t| tj t| tj | j	
|j	 || _|| _|| _|| _|| _|jd| _| jrIt| j | j_t| j | _nt| jdrU| jj| _ndd t| jD | j_| jj| _t | _d| _d S )Nz
.compat.v1__all__c                 S      g | ]	}| d s|qS r   
startswithr   attrr   r   r   
<listcomp>{       z,TFModuleWrapper.__init__.<locals>.<listcomp>r   )superr*   r#   __name__FastModuleTypeZset_getattr_callback_getattrZset_getattribute_callback_getattribute__dict__update_tfmw_wrapped_module_tfmw_module_name_tfmw_public_apis _tfmw_print_deprecation_warnings_tfmw_has_liteendswith_tfmw_is_compat_v1listkeysr+   r'   dirset_tfmw_deprecated_checked_tfmw_warning_count)selfwrappedmodule_nameZpublic_apisdeprecationZhas_lite	__class__r   r   r#   _   s.   


zTFModuleWrapper.__init__c                 C   s   | j tk rC|| jvrC| j| | jrd| j|f }nd| }t|}|rCt|sCt }|dsCt	
dt || |  j d7  _ dS dS )z@Print deprecation warning for attr with given name if necessary.ztf.%s.%sztf.%s<z;From %s: The name %s is deprecated. Please use %s instead.
r   TF)rG   _PER_MODULE_WARNING_LIMITrF   addr<   r   r)   r   r/   loggingwarning)rH   r
   r1   Z	full_namerenameZcall_locationr   r   r   r      s$   

z-TFModuleWrapper._tfmw_add_deprecation_warningc                 C   s   | j r|dkrtjsdt_t d | j| }|d r,t|d }t	||d }nt|d }t
| j|| || j|< | || |S )zLazily loading the modules.ZappTr   r   )rA   r*   compat_v1_usage_recordedcompat_v1_usage_gaugeZget_cellrE   r=   	importlibimport_modulegetattrsetattrr;   r9   _fastdict_insert)rH   r
   Zsymbol_loc_infomoduler1   r   r   r   _tfmw_import_module   s   

z#TFModuleWrapper._tfmw_import_modulec                 C   s   t | d}|dkr | jr | |}t| jd| ||| |S t | |}|ds5|ds5|dr<||| |S | jrE| ||sJ||| |S )zImports and caches pre-defined API.

    Warns if necessary.

    This method is a replacement for __getattribute__(). It will be added into
    the extended python module as a callback to reduce API overhead.
    rZ   Zlite___tfmw_Z
_fastdict_)	object__getattribute__r?   r\   rY   r;   r/   r>   r   )rH   r
   Zfunc__fastdict_insertr1   r   r   r   r8      s$   





zTFModuleWrapper._getattributec                 C   sX   zt | j|}W n ty    | js || jvr | |}Y nw | jr*| || |S )a  Imports and caches pre-defined API.

    Warns if necessary.

    This method is a replacement for __getattr__(). It will be added into the
    extended python module as a callback to reduce API overhead. Instead of
    relying on implicit AttributeError handling, this added callback function
    will
    be called explicitly from the extended C API if the default attribute lookup
    fails.
    )rX   r;   AttributeErrorr=   r\   r>   r   )rH   r
   r1   r   r   r   r7      s   
	zTFModuleWrapper._getattrc                    sl   | ds+t| j|| || j|< || jvr |dkr | j| | |r+| || tt	| 
|| d S )Nr^   r+   )r/   rY   r;   r9   r+   appendZ_fastdict_key_inrZ   r4   r*   __setattr__)rH   argvalrL   r   r   rc      s   


zTFModuleWrapper.__setattr__c                 C   s<   | j rtt| j  tdd t| jD S t| jS )Nc                 S   r,   r-   r.   r0   r   r   r   r2     r3   z+TFModuleWrapper.__dir__.<locals>.<listcomp>)r=   rB   rE   rC   unionrD   r;   rH   r   r   r   __dir__  s   
zTFModuleWrapper.__dir__c                    s.   | drtt| | d S t| j| d S )Nr^   )r/   r4   r*   __delattr__delattrr;   )rH   r
   rL   r   r   ri     s   
zTFModuleWrapper.__delattr__c                 C   s
   | j  S r	   )r;   __repr__rg   r   r   r   rk     s   
zTFModuleWrapper.__repr__c                 C   s   t j| jffS r	   )rV   rW   r5   rg   r   r   r   
__reduce__  s   zTFModuleWrapper.__reduce__)NTF)r5   
__module____qualname____doc__rT   r#   r   r\   r8   r7   rc   rh   ri   rk   rl   __classcell__r   r   rL   r   r*   Z   s     &(r*   )ro   rV   Ztensorflow.python.eagerr   Ztensorflow.python.platformr   rQ   Ztensorflow.python.utilr   r   r   Ztensorflow.tools.compatibilityr   Zget_fast_module_type_classr6   rO   Z	BoolGaugerU   r   r   r"   r)   r*   r   r   r   r   <module>   s$   