
    BVh'                         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j                         Zd	Z ej                   d
d      Zd Zd Zd Zd Z G d de      Zy)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                 N    | t         j                  vry t         j                  |    S N)r   symbol_renames)names    U/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/util/module_wrapper.pyget_rename_v2r       s$    	...		&	&t	,,    c                  "   t        j                         } | j                  j                  j                  dk(  sJ d       t        d      D ]  }| j                  }| n|}  dj                  | 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.   z{}:{})	r   currentframef_backf_codeco_namerangeformatco_filenamef_lineno)frame_parents      r   _call_locationr   &   s     
!
!
#%				$	$(G	G =<=	G 8 a\\F~E	
 
00%..	AAr   c                 &    t        d | D              S )Nc              3   :   K   | ]  }|j                   d k(    yw)
deprecatedN)decorator_name).0ds     r   	<genexpr>z1contains_deprecation_decorator.<locals>.<genexpr>>   s     B!Q-Bs   )any)
decoratorss    r   contains_deprecation_decoratorr)   =   s    	BzB	BBr   c                    t        j                  |       \  }} t        |      ryt        j                  |       ryt        j
                  |       syt        | d      syt        j                  | 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(   init_decoratorsr   s       r   has_deprecation_decoratorr2   A   sw     $**62*f#J/6"			F	#		$#**6??;/1	'	88r   c                   l     e Zd ZdZdZ	 	 	 d fd	Zd Zd Zd Zd Z	 fdZ
d	 Z fd
Zd Zd Z xZS )TFModuleWrapperzGWrapper for TF modules to support deprecation messages and lazyloading.Fc                    t         t        |   |j                         t        j                  | t        j                         t        j                  | t        j                         | j                  j                  |j                         || _        || _        || _        || _        || _        |j                  j!                  d      | _        | j                  r[t%        | j                  j'                               | j                  _        t%        | j                  j'                               | _        nt+        | j                  d      r| j                  j(                  | _        n^t-        | j                        D cg c]  }|j/                  d      s| c}| j                  _        | j                  j(                  | _        t1               | _        d| _        y c c}w )Nz
.compat.v1__all__r   r   )superr4   r+   __name__FastModuleTypeset_getattr_callback_getattr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keysr6   r/   dir
startswithset_tfmw_deprecated_checked_tfmw_warning_count)selfwrappedmodule_namepublic_apisdeprecationhas_liteattr	__class__s          r   r+   zTFModuleWrapper.__init___   sv    
/4)'*:*:;''o.F.FG,,T-<-J-JLMM))* !(D(D(D,7D)"D&//88FD*.t/E/E/J/J/L*Md'$005578dl	**I	60088 !!:!:;-
??3' -
!!) 0088 %(ED! D-
s   ?Gc                    | j                   t        k  r|| j                  vr| j                  j                  |       | j                  rd| j                  d|}nd|z  }t        |      }|r\t        |      sQt               }|j                  d      s6t        j                  dt               ||       | xj                   dz  c_         yy)	z@Print deprecation warning for attr with given name if necessary.ztf..ztf.%s<z;From %s: The name %s is deprecated. Please use %s instead.
r	   TF)rM   _PER_MODULE_WARNING_LIMITrL   addrA   r   r2   r   rJ   loggingwarning)rN   r   rT   	full_namerenamecall_locations         r   r   z-TFModuleWrapper._tfmw_add_deprecation_warning   s      #<<D111
##''-			"&"8"8$?	dN	Y'f	1$7&('',
//L	63 
"
"a
'
"r   c                    | j                   rC|dk7  r>t        j                  s.dt        _        t        j	                         j                  d       | j                  |   }|d   r(t        j                  |d         }t        ||d         }nt        j                  |d         }t        | j                  ||       || j                  |<   | j                  ||       |S )zLazily loading the modules.appTr   r	   )rF   r4   compat_v1_usage_recordedcompat_v1_usage_gaugeget_cellrK   rB   	importlibimport_modulegetattrsetattrr@   r>   _fastdict_insert)rN   r   symbol_loc_infomodulerT   s        r   _tfmw_import_modulez#TFModuleWrapper._tfmw_import_module   s    
 	DEM4415o.$$&**40,,T2Oq&&q'9:fV_Q/0d$$_Q%78dD%%tT2DMM$$%Kr   c                    t         j                  | d      }|dk(  r?| j                  r3| j                  |      }t	        | j
                  d|        |||       |S t         j                  | |      }|j                  d      s"|j                  d      s|j                  d      r |||       |S | j                  r| j                  ||      s	 |||       |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.
    ri   lite___tfmw_
_fastdict_)	object__getattribute__rD   rl   rh   r@   rJ   rC   r   )rN   r   func__fastdict_insertrT   s       r   r=   zTFModuleWrapper._getattribute   s     #33D:LM v~			''-))648dD) ""4.D t 9T__>D$'k 11..tT:D$'Kr   c                     	 t        | j                  |      }| j
                  r| j                  ||       |S # t        $ r0 | j                  s || j                  vr | j	                  |      }Y Xw xY w)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.
    )rg   r@   AttributeErrorrB   rl   rC   r   )rN   r   rT   s      r   r;   zTFModuleWrapper._getattr   sy    	,T..5d ,,
((t4K  , ##	T++	+%%d+d,s   8 6A10A1c                 >   |j                  d      swt        | j                  ||       || j                  |<   || j                  vr |dk7  r| j                  j                  |       | j                  |      r| j                  ||       t        t        | +  ||       y )Nrp   r6   )rJ   rh   r@   r>   r6   append_fastdict_key_inri   r7   r4   __setattr__)rN   argvalrU   s      r   rz   zTFModuleWrapper.__setattr__   s    >>(#d''c2dmmC	DLL	 SI%5C 			s	#c3'	/4,S#6r   c                 :   | j                   rvt        t        | j                   j                               j	                  t        t        | j                        D cg c]  }|j                  d      s| c}                  S t        | j                        S c c}w )Nr   )rB   rG   rK   rH   unionrI   r@   rJ   )rN   rT   s     r   __dir__zTFModuleWrapper.__dir__  s    
d$$))+
,
2
2#&t'@'@#A-    **++s   Bc                 &   |j                  d      rt        t        |   |       y t	        | j
                  |       | j                  j                  |       || j                  v r| j                  j                  |       | j                  |       y )Nrp   )rJ   r7   r4   __delattr__delattrr@   r>   popr6   remove_fastdict_pop)rN   r   rU   s     r   r   zTFModuleWrapper.__delattr__  sl    x OT.t4d''.
mm		D!
r   c                 6    | j                   j                         S r   )r@   __repr__rN   s    r   r   zTFModuleWrapper.__repr__  s    $$--//r   c                 <    t         j                  | j                  ffS r   )re   rf   r8   r   s    r   
__reduce__zTFModuleWrapper.__reduce__  s    ""T]]$444r   )NTF)r8   
__module____qualname____doc__rb   r+   r   rl   r=   r;   rz   r   r   r   r   __classcell__)rU   s   @r   r4   r4   Z   sK    O" $!L.,&P8	7	,05r   r4   )r   re   tensorflow.python.eagerr   tensorflow.python.platformr   r[   tensorflow.python.utilr   r   r   tensorflow.tools.compatibilityr   get_fast_module_type_classr9   rY   	BoolGaugerc   r   r   r)   r2   r4    r   r   <module>r      st    /  . < 3 / - 9<!<<> ,
,,-H->@ -B.C92A5n A5r   