a
    Sic6                     @   sN  d Z ddlZddlZddlZddlm  mZ ej	Z	e
edrFejZnedg dZdd Ze
edrxejZdd	 ZnejZd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd<ddZdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Z d-d. Z!d/d0 Z"d1d2 Z#d3d4 Z$d5d6 Z%d7d8 Z&d=d:d;Z'dS )>z6TFDecorator-aware replacements for the inspect module.    NFullArgSpecargsvarargsvarkwdefaults
kwonlyargskwonlydefaultsannotationsc              	   C   s,   t | tr| S t| j| j| j| jg d i dS )Nr   )
isinstancer   r   r   keywordsr   )argspec r   R/var/www/html/django/DPS/env/lib/python3.9/site-packages/keras/utils/tf_inspect.py%_convert_maybe_argspec_to_fullargspec*   s    
r   getfullargspecc                 C   s$   t | }t|j|j|j|jd}|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   ArgSpecr   r   r   r   )targetfullargspecsargspecsr   r   r   _getargspec;   s    r   c                 C   s   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   r   r   r   _getfullargspecW   s    	r   c                   C   s   t  d d S )z7TFDecorator-aware replacement for inspect.currentframe.   r   _inspectstackr   r   r   r   currentframec   s    r   c                 C   s   t | tjrt| S tjj| \}}tdd |D d}|rB|S z
t	|W S  t
y^   Y n0 t |trzt	|jW S  t
y   Y n0 zt	|jW S  t
y   Y n0 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                 s   s   | ]}|j d ur|j V  qd S N)decorator_argspec).0dr   r   r   	<genexpr>   s   
zgetargspec.<locals>.<genexpr>N)r   	functoolspartial_get_argspec_for_partialtf__internal__	decoratorunwrapnextr   	TypeErrortype__init____new____call__)obj
decoratorsr   specr   r   r   r   h   s2    

r   c                    s  t | j}| jpi }t| j\ }}} |d  t gt   }|r\||t | d< | D ]0\}}| v r |}	|||	< qd|sdtdqdt	fddt
|D ddu rt ||dS  fddt
|D }
|
rtd|
 dt ||t|d S )	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   s   | ]\}}| ur|V  qd S r   r   )r    idxx)
no_defaultr   r   r"          z+_get_argspec_for_partial.<locals>.<genexpr>c                    s(   g | ] \}}|u r|kr | qS r   r   )r    ijr   first_defaultr5   r   r   
<listcomp>   s   z,_get_argspec_for_partial.<locals>.<listcomp>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
ValueErrorr*   	enumerater   tuple)r0   n_prune_argspartial_keywordsr   r   r   all_defaultskwdefaultr3   invalid_default_valuesr   r9   r   r%      s:    *




r%   c                 C   s<   t jj| \}}|D ]}|jdurt|j  S q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.
    N)r&   r'   r(   r)   r   r   r   )r0   r1   r   r!   r   r   r   r     s
    
c                     s   | d }| dd }t |}|  t|ddp:t|dd}t|rR|rR|f| } fdd|jD } tt|| |jsdnt	|j}|rt|j| d |jD ]\}}	| vr|	 |< q|j
dur|j
 D ]\}
}|
 vr| |
< q؈ S )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__c                    s   g | ]}| vr|qS r   r   )r    arg	call_argsr   r   r;   .  s   zgetcallargs.<locals>.<listcomp>)r   copygetattrismethodr   updatedictzipr   r<   r	   r?   )func_and_positionalnamedr=   
positionalr   thisremaining_positionalsdefault_countrL   valuekvr   rM   r   getcallargs  s*    

 


r^   c                  O   s   t j| i |S r   )r   getframeinfo)r   kwargsr   r   r   r_   >  s    r_   c                 C   s
   t | 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r0   r   r   r   ra   B  s    ra   c                 C   s:   t jj| d }t|dr0d|jv r0|jd S t|S )z2TFDecorator-aware replacement for inspect.getfile.r   	f_globals__file__)r&   r'   r(   r)   hasattrrc   r   getfile)r0   unwrapped_objectr   r   r   rf   Q  s    
rf   c                 C   s   t | |S )z5TFDecorator-aware replacement for inspect.getmembers.)r   
getmembers)r0   	predicater   r   r   rh   a  s    rh   c                 C   s
   t | S )z4TFDecorator-aware replacement for inspect.getmodule.)r   	getmodulerb   r   r   r   rj   f  s    rj   c                 C   s
   t | S )z1TFDecorator-aware replacement for inspect.getmro.)r   getmro)clsr   r   r   rk   k  s    rk   c                 C   s   t tjj| d S )z4TFDecorator-aware replacement for inspect.getsource.r   )r   	getsourcer&   r'   r(   r)   rb   r   r   r   rm   p  s    rm   c                 C   s   t tjj| d S )z8TFDecorator-aware replacement for inspect.getsourcefile.r   )r   getsourcefiler&   r'   r(   r)   rb   r   r   r   rn   u  s    rn   c                 C   s   t tjj| d S )z9TFDecorator-aware replacement for inspect.getsourcelines.r   )r   getsourcelinesr&   r'   r(   r)   rb   r   r   r   ro   z  s    ro   c                 C   s   t tjj| d S )z4TFDecorator-aware replacement for inspect.isbuiltin.r   )r   	isbuiltinr&   r'   r(   r)   rb   r   r   r   rp     s    rp   c                 C   s   t tjj| d S )z2TFDecorator-aware replacement for inspect.isclass.r   )r   isclassr&   r'   r(   r)   rb   r   r   r   rq     s    rq   c                 C   s   t tjj| d S )z5TFDecorator-aware replacement for inspect.isfunction.r   )r   
isfunctionr&   r'   r(   r)   rb   r   r   r   rr     s    rr   c                 C   s   t tjj| d S z3TFDecorator-aware replacement for inspect.ismodule.r   )r   isframer&   r'   r(   r)   rb   r   r   r   rt     s    rt   c                 C   s   t tjj| d S )z6TFDecorator-aware replacement for inspect.isgenerator.r   )r   isgeneratorr&   r'   r(   r)   rb   r   r   r   ru     s    ru   c                 C   s   t tjj| d S )z>TFDecorator-aware replacement for inspect.isgeneratorfunction.r   )r   isgeneratorfunctionr&   r'   r(   r)   rb   r   r   r   rv     s    rv   c                 C   s   t tjj| d S )z3TFDecorator-aware replacement for inspect.ismethod.r   )r   rQ   r&   r'   r(   r)   rb   r   r   r   rQ     s    rQ   c                 C   s   t tjj| d S rs   )r   ismoduler&   r'   r(   r)   rb   r   r   r   rw     s    rw   c                 C   s   t tjj| d S )z4TFDecorator-aware replacement for inspect.isroutine.r   )r   	isroutiner&   r'   r(   r)   rb   r   r   r   rx     s    rx   r   c                 C   s   t | dd S )z0TFDecorator-aware replacement for inspect.stack.r   Nr   )contextr   r   r   r     s    r   )N)r   )(__doc__collectionsr#   inspectr   tensorflow.compat.v2compatv2r&   r   re   r   
namedtupler   r   r   r   r   r   r%   r^   r_   ra   rf   rh   rj   rk   rm   rn   ro   rp   rq   rr   rt   ru   rv   rQ   rw   rx   r   r   r   r   r   <module>   sR   


9`'
