
    0h7                        d Z ddlZddlZddlZddlmc mZ  e	ed      rej                  Z
n ej                  dg d      Z
 e	ed      rej                  Zn ej                  dg d      Zd Z e	ed      rej                  Zd	 Znej"                  Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd#dZd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d  Z%d! Z&d$d"Z'y)%z6TFDecorator-aware replacements for the inspect module.    NArgSpecargsvarargskeywordsdefaultsFullArgSpecr   r   varkwr   
kwonlyargskwonlydefaultsannotationsc           	          t        | t              r| S t        | j                  | j                  | j                  | j
                  g d i       S )Nr
   )
isinstancer	   r   r   r   r   )argspecs    W/var/www/html/engine/venv/lib/python3.12/site-packages/tf_keras/src/utils/tf_inspect.py%_convert_maybe_argspec_to_fullargspecr   4   sG    ';'\\!!     getfullargspecc                     t        |       }t        |j                  |j                  |j                  |j
                        }|S )a  A python3 version of getargspec.

        Calls `getfullargspec` and assigns args, varargs,
        varkw, and defaults to a python 2/3 compatible `ArgSpec`.

        The parameter name 'varkw' is changed to 'keywords' to fit the
        `ArgSpec` struct.

        Args:
          target: the target object to inspect.

        Returns:
          An ArgSpec with args, varargs, keywords, and defaults parameters
          from FullArgSpec.
        r   )r   r   r   r   r   r   )targetfullargspecsargspecss      r   _getargspecr   E   sC      &f-"" ((!''!**	
 r   c                 *    t        t        |             S )zA python2 version of getfullargspec.

        Args:
          target: the target object to inspect.

        Returns:
          A FullArgSpec with empty kwonlyargs, kwonlydefaults and annotations.
        )r   
getargspec)r   s    r   _getfullargspecr   a   s     5Z5GHHr   c                  6    t        j                         d   d   S )z7TFDecorator-aware replacement for inspect.currentframe.   r   _inspectstack r   r   currentframer$   m   s    >>Aq!!r   c                    t        | t        j                        rt        |       S t        j
                  j                  j                  |       \  }}t        d |D        d      }|r|S 	 t        |      S # t        $ r Y nw xY wt        |t              rJ	 t        |j                        S # t        $ r Y nw xY w	 t        |j                        S # t        $ r Y nw xY wt        t        |      j                        S )ad  TFDecorator-aware replacement for `inspect.getargspec`.

    Note: `getfullargspec` is recommended as the python 2/3 compatible
    replacement for this function.

    Args:
      obj: A function, partial function, or callable object, possibly decorated.

    Returns:
      The `ArgSpec` that describes the signature of the outermost decorator that
      changes the callable's signature, or the `ArgSpec` that describes
      the object if not decorated.

    Raises:
      ValueError: When callable's signature can not be expressed with
        ArgSpec.
      TypeError: For objects of unsupported types.
    c              3   L   K   | ]  }|j                   |j                     y wN)decorator_argspec).0ds     r   	<genexpr>zgetargspec.<locals>.<genexpr>   s*      	
"". 	
s   "$N)r   	functoolspartial_get_argspec_for_partialtf__internal__	decoratorunwrapnextr   	TypeErrortype__init____new____call__)obj
decoratorsr   specs       r   r   r   r   s    & #y(()',,2299#>J	
	

 	D 6""  &$	v// 			v~~.. 		
 tF|,,--s6   *
A5 5	B BB* *	B65B6:C 	CCc           
      p   t        | j                        }| j                  xs i }t        | j                        \  }}}}||d }t               gt        |      z  }|r||t        |       d |j                         D ]-  \  }}	||v r|j                  |      }
|	||
<   !|r$t        d       t        fdt        |      D        d      }|t        |||d      S t        |      D cg c]  \  }}|u r
||kD  r||    }}}|rt        d| d      t        |||t        ||d             S c c}}w )zImplements `getargspec` for `functools.partial` objects.

    Args:
      obj: The `functools.partial` object
    Returns:
      An `inspect.ArgSpec`
    Raises:
      ValueError: When callable's signature can not be expressed with
        ArgSpec.
    NzSFunction does not have **kwargs parameter, but contains an unknown partial keyword.c              3   2   K   | ]  \  }}|us|  y wr'   r#   )r)   idxx
no_defaults      r   r+   z+_get_argspec_for_partial.<locals>.<genexpr>   s     Jaaz6IJs   zSome arguments z| do not have default value, but they are positioned after those with default values. This can not be expressed with ArgSpec.)lenr   r   r   funcobjectitemsindex
ValueErrorr3   	enumerater   tuple)r9   n_prune_argspartial_keywordsr   r   r   r   all_defaultskwdefaultr>   first_defaultijinvalid_default_valuesr@   s                  @r   r.   r.      s   T sxx=L||)r(2388(<%D'8X D
 J<#d)+L)1c(m^%& (--/ G:**R.C 'L7  J9\2JDM
 tWh55
 l+Aq
?q=0 	Q  45 6F F
 	
 4(E,}~2N,OPPs   ,D2c                     t         j                  j                  j                  |       \  }}|D ]%  }|j                  t        |j                        c S  t        |      S )a  TFDecorator-aware replacement for `inspect.getfullargspec`.

    This wrapper emulates `inspect.getfullargspec` in[^)]* Python2.

    Args:
      obj: A callable, possibly decorated.

    Returns:
      The `FullArgSpec` that describes the signature of
      the outermost decorator that changes the callable's signature. If the
      callable is not decorated, `inspect.getfullargspec()` will be called
      directly on the callable.
    )r/   r0   r1   r2   r(   r   r   )r9   r:   r   r*   s       r   r   r     s^     2299#>J N*89L9LMMN 6""r   c                  b   | d   }| dd }t        |      }|j                         }t        |dd      xs t        |dd      }t        |      r|r|f|z   }|j                  D cg c]	  }||vs| }}|j                  t        t        ||                   |j                  sdnt        |j                        }	|	r6t        |j                  |	 d |j                        D ]  \  }}
||vs|
||<    |j                  ,|j                  j                         D ]  \  }}||vs|||<    |S c c}w )an  TFDecorator-aware replacement for inspect.getcallargs.

    Args:
      *func_and_positional: A callable, possibly decorated, followed by any
        positional arguments that would be passed to `func`.
      **named: The named argument dictionary that would be passed to `func`.

    Returns:
      A dictionary mapping `func`'s named arguments to the values they would
      receive if `func(*positional, **named)` were called.

    `getcallargs` will use the argspec from the outermost decorator that
    provides it. If no attached decorators modify argspec, the final unwrapped
    target's argspec will be used.
    r   r   Nim_self__self__)r   copygetattrismethodr   updatedictzipr   rA   r   rD   )func_and_positionalnamedrB   
positionalr   	call_argsthisargremaining_positionalsdefault_countvaluekvs                r   getcallargsrg   !  sL     q!D$QR(JT"G

I4D)LWT:t-LD~$Wz)
||s)';  T#3Z@AB$--A3w7G7G3HMgllM>?;W=M=MN 	'JC)#!&	#	' )**002 	!DAq	! 	!	! s   #	D,-D,c                  ,    t        j                  | i |S r'   )r!   getframeinfo)r   kwargss     r   ri   ri   H  s      $1&11r   c                 ,    t        j                  |       S )a3  TFDecorator-aware replacement for inspect.getdoc.

    Args:
      obj: An object, possibly decorated.

    Returns:
      The docstring associated with the object.

    The outermost-decorated object is intended to have the most complete
    documentation, so the decorated parameter is not unwrapped.
    )r!   getdocr9   s    r   rl   rl   L  s     ??3r   c                     t         j                  j                  j                  |       d   }t	        |d      rd|j
                  v r|j
                  d   S t        j                  |      S )z2TFDecorator-aware replacement for inspect.getfile.r   	f_globals__file__)r/   r0   r1   r2   hasattrro   r!   getfile)r9   unwrapped_objects     r   rr   rr   [  sa    0077<Q? 	 +.*444))*55,--r   c                 .    t        j                  | |      S )z5TFDecorator-aware replacement for inspect.getmembers.)r!   
getmembers)r9   	predicates     r   ru   ru   k  s    sI..r   c                 ,    t        j                  |       S )z4TFDecorator-aware replacement for inspect.getmodule.)r!   	getmodulerm   s    r   rx   rx   p  s    c""r   c                 ,    t        j                  |       S )z1TFDecorator-aware replacement for inspect.getmro.)r!   getmro)clss    r   rz   rz   u  s    ??3r   c                     t        j                  t        j                  j                  j                  |       d         S )z4TFDecorator-aware replacement for inspect.getsource.r   )r!   	getsourcer/   r0   r1   r2   rm   s    r   r}   r}   z  -    boo77>>sCAFGGr   c                     t        j                  t        j                  j                  j                  |       d         S )z8TFDecorator-aware replacement for inspect.getsourcefile.r   )r!   getsourcefiler/   r0   r1   r2   rm   s    r   r   r     s-    !!"//";";"B"B3"G"JKKr   c                     t        j                  t        j                  j                  j                  |       d         S )z9TFDecorator-aware replacement for inspect.getsourcelines.r   )r!   getsourcelinesr/   r0   r1   r2   rm   s    r   r   r     s-    ""2??#<#<#C#CC#H#KLLr   c                     t        j                  t        j                  j                  j                  |       d         S )z4TFDecorator-aware replacement for inspect.isbuiltin.r   )r!   	isbuiltinr/   r0   r1   r2   rm   s    r   r   r     r~   r   c                     t        j                  t        j                  j                  j                  |       d         S )z2TFDecorator-aware replacement for inspect.isclass.r   )r!   isclassr/   r0   r1   r2   rm   s    r   r   r     -    BOO55<<SA!DEEr   c                     t        j                  t        j                  j                  j                  |       d         S )z5TFDecorator-aware replacement for inspect.isfunction.r   )r!   
isfunctionr/   r0   r1   r2   rm   s    r   r   r     s-    r88??DQGHHr   c                     t        j                  t        j                  j                  j                  |       d         S z3TFDecorator-aware replacement for inspect.ismodule.r   )r!   isframer/   r0   r1   r2   rm   s    r   r   r     r   r   c                     t        j                  t        j                  j                  j                  |       d         S )z6TFDecorator-aware replacement for inspect.isgenerator.r   )r!   isgeneratorr/   r0   r1   r2   rm   s    r   r   r     s-     9 9 @ @ Ea HIIr   c                     t        j                  t        j                  j                  j                  |       d         S )z>TFDecorator-aware replacement for inspect.isgeneratorfunction.r   )r!   isgeneratorfunctionr/   r0   r1   r2   rm   s    r   r   r     s2    ''
!!((-a0 r   c                     t        j                  t        j                  j                  j                  |       d         S )z3TFDecorator-aware replacement for inspect.ismethod.r   )r!   rX   r/   r0   r1   r2   rm   s    r   rX   rX     -    R__66==cB1EFFr   c                     t        j                  t        j                  j                  j                  |       d         S r   )r!   ismoduler/   r0   r1   r2   rm   s    r   r   r     r   r   c                     t        j                  t        j                  j                  j                  |       d         S )z4TFDecorator-aware replacement for inspect.isroutine.r   )r!   	isroutiner/   r0   r1   r2   rm   s    r   r   r     r~   r   c                 2    t        j                  |       dd S )z0TFDecorator-aware replacement for inspect.stack.r   Nr    )contexts    r   r"   r"     s    >>'"12&&r   r'   )r   )(__doc__collectionsr,   inspectr!   tensorflow.compat.v2compatv2r/   rq   r   
namedtupler	   r   r   r   r   r   r$   r.   rg   ri   rl   rr   ru   rx   rz   r}   r   r   r   r   r   r   r   r   rX   r   r   r"   r#   r   r   <module>r      s6   =    ! !
8YG$k$$	
G 8]#&&K(+((	
K 8%&--O4 %%K	I"
6.r]Q@#,$N2 . /
#
 
H
L
M
H
F
I
F
J
G
G
H
'r   