a
    .Sicm                     @   sN  d Z ddlZddlZddl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 dd	lmZ d
ai ZG dd deZdd Zdd Zdd Zdd Zd3ddZdd Zdd Zd4ddZdd Zd5d d!Zed"g d#Zd$d% Z d6d&d'Z!d(d) Z"d*d+ Z#ej$d,d- Z%d.d/ Z&G d0d1 d1e'Z(e(Z)e(d2Z*dS )7zTensor utility functions.    N)
tf_logging)decorator_utils)is_in_graph_mode)tf_contextlib)tf_decorator)
tf_inspect)doc_controlsTc                   @   s   e Zd ZdZdS )DeprecatedNamesAlreadySetzHRaised when setting deprecated names multiple times for the same symbol.N)__name__
__module____qualname____doc__ r   r   ^/var/www/html/django/DPS/env/lib/python3.9/site-packages/tensorflow/python/util/deprecation.pyr	   &   s   r	   c                 C   s>   d|du rdnd|  g}|r(| d tj| |dd|dd	S )
zBAdds a deprecation notice to a docstring for deprecated functions.z3THIS FUNCTION IS DEPRECATED. It will be removed %s.Nin a future versionafter %sInstructions for updating:zDEPRECATED FUNCTION(deprecated)
DeprecatedZnotice_type)appendr   add_notice_to_docstring)docdateinstructionsZ	main_textr   r   r   ,_add_deprecated_function_notice_to_docstring+   s    
r   c              	   C   s@   d t|}tj| |ddd||du r*dnd| f dgd	d
S )BAdds a deprecation notice to a docstring for deprecated arguments., zDEPRECATED FUNCTION ARGUMENTSz(deprecated arguments)z?SOME ARGUMENTS ARE DEPRECATED: `(%s)`. They will be removed %s.Nr   r   r   r   r   )joinsortedr   r   )r   r   r   Zdeprecated_namesdeprecation_stringr   r   r   '_add_deprecated_arg_notice_to_docstring:   s    r!   c                 C   sR   d dd t| D }|du r(dnd| }tj| |ddd	||f d
gddS )r   r   c                 s   s   | ]\}}d ||f V  qdS )z%s=%rNr   ).0keyvaluer   r   r   	<genexpr>Q   s   z@_add_deprecated_arg_value_notice_to_docstring.<locals>.<genexpr>Nr   r   z#DEPRECATED FUNCTION ARGUMENT VALUESz(deprecated argument values)zESOME ARGUMENT VALUES ARE DEPRECATED: `(%s)`. They will be removed %s.r   r   r   )r   r   itemsr   r   )r   r   r   Zdeprecated_name_value_dictr    whenr   r   r   -_add_deprecated_arg_value_notice_to_docstringM   s     

r(   c                 C   s2   | d ur"t d| s"td|  |s.tdd S )Nz20\d\d-[01]\d-[0123]\dz-Date must be in format YYYY-MM-DD. Received: z\Don't deprecate things without conversion instructions! Specify the `instructions` argument.)rematch
ValueError)r   r   r   r   r   _validate_deprecation_argsc   s    r,   Fc                 C   s8   t  jj}|o|j}| r&|dur&|}d|jj|jS )z7Returns call location given level up from current call.Nz{}:{})inspectcurrentframef_backformatf_codeco_filenamef_lineno)outerfparentr   r   r   _call_locationl   s
    
r7   c                 C   s(   | d u s|d u r | d u o|d u S | |kS Nr   )abr   r   r   _safe_eqy   s    r;   c                    s    fdd}|S )a  Indicate that one function wraps another.

  This decorator wraps a function using `tf_decorator.make_decorator`
  so that doc generation scripts can pick up original function
  signature.
  It would be better to use @functools.wrap decorator, but it would
  not update function signature to match wrapped function in Python 2.

  Args:
    wrapped_function: The function that decorated function wraps.

  Returns:
    Function that accepts wrapper function as an argument and returns
    `TFDecorator` instance.
  c                    s   t  | S r8   )r   make_decorator)Zwrapper_funcwrapped_functionr   r   wrapper   s    z _wrap_decorator.<locals>.wrapperr   )r>   r?   r   r=   r   _wrap_decorator   s    r@   c              
      sv   t r*G  fddd  S td tfddtdtj	dd S dS )ay  Deprecate a symbol in favor of a new name with identical semantics.

  This function is meant to be used when defining a backwards-compatibility
  alias for a symbol which has been moved. For example:

  module1.py:
  ```python
  class NewNameForClass: pass
  ```

  module2.py:
  ```python
  import module1

  DeprecatedNameForClass = deprecated_alias(
    deprecated_name='module2.DeprecatedNameForClass',
    name='module1.NewNameForClass',
    func_or_class=module1.NewNameForClass)
  ```

  This function works for classes and functions.

  For classes, it creates a new class which is functionally identical (it
  inherits from the original, and overrides its constructor), but which prints
  a deprecation warning when an instance is created. It also adds a deprecation
  notice to the class' docstring.

  For functions, it returns a function wrapped by `tf_decorator.make_decorator`.
  That function prints a warning when used, and has a deprecation notice in its
  docstring. This is more or less equivalent (the deprecation warning has
  slightly different text) to writing:

  ```python
  @deprecated
  def deprecated_alias(original_args):
    real_function(original_args)
  ```

  Args:
    deprecated_name: The name of the symbol that is being deprecated, to be used
      in the warning message. This should be its fully qualified name to avoid
      confusion.
    name: The name of the symbol that is to be used instead of the deprecated
      name. This should be a fully qualified name to avoid confusion.
    func_or_class: The (non-deprecated) class or function for which a deprecated
      alias should be created.
    warn_once: If True (the default), only print a deprecation warning the first
      time this function is used, or the class is instantiated.

  Returns:
    A wrapped version of `func_or_class` which prints a deprecation warning on
    use and has a modified docstring.
  c                       s^   e Zd Zejjd dddgddZj Z eddZej fd	d
Z  Z	S )z#deprecated_alias.<locals>._NewClassPlease use %s instead.zDEPRECATED CLASSr   zBTHIS CLASS IS DEPRECATED. It will be removed in a future version. r   r   T)r4   c                    sp   t  jdrjj jj_njj j_trV jtvrVrDdt j< tdt  t	 | j|i | d S )N__func__T;From %s: The name %s is deprecated. Please use %s instead.
)
hasattr__init__r   rB   _PRINT_DEPRECATION_WARNINGS_PRINTED_WARNINGloggingwarningr7   super)selfargskwargs)	_NewClass	__class__deprecated_namefunc_or_classname	warn_oncer   r   rE      s    

z,deprecated_alias.<locals>._NewClass.__init__)
r
   r   r   r   r   r   r7   r@   rE   __classcell__r   )rN   rP   rQ   rR   rS   rO   r   rN      s   	
rN   
deprecatedc                     s8   t r*tvr*rdt< tdt   | i |S )NTrC   )rF   rG   rH   rI   r7   rL   rM   )rP   rQ   rR   new_funcrS   r   r   rX      s    z"deprecated_alias.<locals>.new_funcNrA   )
r   isclassr   validate_callable	functoolswrapsr   r<   r   r   )rP   rR   rQ   rS   r   )rN   rP   rQ   rR   rX   rS   r   deprecated_alias   s    6
"r]   c                     s    fdd}|S )a  Decorator for marking endpoints deprecated.

  This decorator does not print deprecation messages.
  TODO(annarev): eventually start printing deprecation warnings when
  @deprecation_endpoints decorator is added.

  Args:
    *args: Deprecated endpoint names.

  Returns:
    A function that takes symbol as an argument and adds
    _tf_deprecated_api_names to that symbol.
    _tf_deprecated_api_names would be set to a list of deprecated
    endpoint names for the symbol.
  c                    s4   d| j v r*td| j d  d| j d | _| S )N_tf_deprecated_api_namesz Cannot set deprecated names for z to z&. Deprecated names are already set to .)__dict__r	   r
   r^   funcrL   r   r   deprecated_wrapper  s    
z0deprecated_endpoints.<locals>.deprecated_wrapperr   )rL   rd   r   rc   r   deprecated_endpoints  s    
re   c                    s   t    fdd}|S )a  Decorator for marking functions or methods deprecated.

  This decorator logs a deprecation warning whenever the decorated function is
  called. It has the following format:

    <function> (from <module>) is deprecated and will be removed after <date>.
    Instructions for updating:
    <instructions>

  If `date` is None, 'after <date>' is replaced with 'in a future version'.
  <function> will include the class name if it is a method.

  It also edits the docstring of the function: ' (deprecated)' is appended
  to the first line of the docstring and a deprecation notice is prepended
  to the rest of the docstring.

  Args:
    date: String or None. The date the function is scheduled to be removed.
      Must be ISO 8601 (YYYY-MM-DD), or None.
    instructions: String. Instructions on how to update code using the
      deprecated function.
    warn_once: Boolean. Set to `True` to warn only the first time the decorated
      function is called. Otherwise, every call will log a warning.

  Returns:
    Decorated function or method.

  Raises:
    ValueError: If date is not None or in ISO 8601 format, or instructions are
      empty.
  c              	      s   t | tr2| }|jtju r&|j d}q>|j d}nd}d}|  t d t  fdd}t	
| t |dt j}|du r|S t||| t|j|_|S dS )Deprecation wrapper.rE   __new__NrV   c                     sT   t rFtvrFrdt< tdt tj d u r:dnd   | i |S )NTzYFrom %s: %s (from %s) is deprecated and will be removed %s.
Instructions for updating:
%sr   r   )rF   rG   rH   rI   r7   r   get_qualified_namer   rW   )r   rb   r   rS   r   r   rX   X  s    z8deprecated.<locals>.deprecated_wrapper.<locals>.new_func)
isinstancetyperg   objectrE   r   rZ   r[   r\   r   Zset_deprecatedr   r<   r   r   setattr)rQ   clsZconstructor_namerX   r   r   rS   ra   r   rd   F  s6    

z&deprecated.<locals>.deprecated_wrapper)r,   )r   r   rS   rd   r   rn   r   rV   $  s     
3rV   DeprecatedArgSpec)positionhas_ok_valueok_valuec                    s   t  std|rFt| dgkrF|dd td| |ddfdd}dd	  |  fd
d}|S )a  Decorator for marking specific function arguments as deprecated.

  This decorator logs a deprecation warning whenever the decorated function is
  called with the deprecated argument. It has the following format:

    Calling <function> (from <module>) with <arg> is deprecated and will be
    removed after <date>. Instructions for updating:
      <instructions>

  If `date` is None, 'after <date>' is replaced with 'in a future version'.
  <function> includes the class name if it is a method.

  It also edits the docstring of the function: ' (deprecated arguments)' is
  appended to the first line of the docstring and a deprecation notice is
  prepended to the rest of the docstring.

  Args:
    date: String or None. The date the function is scheduled to be removed.
      Must be ISO 8601 (YYYY-MM-DD), or None.
    instructions: String. Instructions on how to update code using the
      deprecated function.
    *deprecated_arg_names_or_tuples: String or 2-Tuple (String,
      ok_val).  The string is the deprecated argument name.
      Optionally, an ok-value may be provided.  If the user provided
      argument equals this value, the warning is suppressed.
    **kwargs: If `warn_once=False` is passed, every call with a deprecated
      argument will log a warning. The default behavior is to only warn the
      first time the function is called with any given deprecated argument.
      All other kwargs raise `ValueError`.

  Returns:
    Decorated function or method.

  Raises:
    ValueError: If date is not None or in ISO 8601 format, instructions are
      empty, the deprecated arguments are not present in the function
      signature, the second element of a deprecated_tuple is not a
      list, or if a kwarg other than `warn_once` is passed.
  z%Specify which argument is deprecated.rS   Nz,Illegal argument passed to deprecated_args: Tc                     sF   i }  D ]8}t |tr0tdd|d | |d < qtddd| |< q| S )zBReturns a dict mapping arg_name to DeprecatedArgSpec w/o position.T   r   FN)ri   tuplero   )dname_or_tuple)deprecated_arg_names_or_tuplesr   r   _get_arg_names_to_ok_vals  s    
z2deprecated_args.<locals>._get_arg_names_to_ok_valsc                 S   s`   |j |j }dd t|D }i }t|  D ],\}}||v r.|| }t||j|j||< q.|S )a  Builds a dictionary from deprecated arguments to their spec.

    Returned dict is keyed by argument name.
    Each value is a DeprecatedArgSpec with the following fields:
       position: The zero-based argument position of the argument
         within the signature.  None if the argument isn't found in
         the signature.
       ok_values:  Values of this argument for which warning will be
         suppressed.

    Args:
      names_to_ok_vals: dict from string arg_name to a list of values,
        possibly empty, which should not elicit a warning.
      arg_spec: Output from tf_inspect.getfullargspec on the called function.

    Returns:
      Dictionary from arg_name to DeprecatedArgSpec.
    c                 S   s   i | ]\}}||qS r   r   )r"   posrR   r   r   r   
<dictcomp>  s   zQdeprecated_args.<locals>._get_deprecated_positional_arguments.<locals>.<dictcomp>)rL   
kwonlyargs	enumerateiterr&   ro   rq   rr   )Znames_to_ok_valsarg_specZ	arg_spaceZarg_name_to_posZdeprecated_positional_argsarg_namespecrz   r   r   r   $_get_deprecated_positional_arguments  s    

z=deprecated_args.<locals>._get_deprecated_positional_argumentsc                    s   t d t	j	v j	v t  t
krjj jjg fdd	D }t	d| d ddd  t
 	f
d	d
}tjt	 }t|d|S )Deprecation decorator.deprecated_argsc                    s   g | ]}| vr|qS r   r   )r"   r   )
known_argsr   r   
<listcomp>  s   z?deprecated_args.<locals>.deprecated_wrapper.<locals>.<listcomp>zNThe following deprecated arguments are not present in the function signature: z.. Expected arguments from the following list: r_   c                 S   sB   | |u rdS z| |k}t |tr&|W S W n ty<   Y dS 0 dS )a  A comparison operation that works for multiple object types.

      Returns True for two empty lists, two numeric values with the
      same value, etc.

      Returns False for (pd.DataFrame, None), and other pairs which
      should not be considered equivalent.

      Args:
        a: value one of the comparison.
        b: value two of the comparison.

      Returns:
        A boolean indicating whether the two inputs are the same value
        for the purposes of deprecation.
      TF)ri   bool	TypeError)r9   r:   equalityr   r   r   _same_value  s    

z@deprecated_args.<locals>.deprecated_wrapper.<locals>._same_valuec               
      sH  t  r:tr:g }tjg| R i |}t D ]6\}}|jt| k r8|j	rd || |j
s8|| q8rt| tjkr|j r|r|j D ]4}||v r| j	rԈ || | j
s|| q|D ]T}|ftvr	rdt|f< tdt tj|du r,dnd  q| i |S )rf   TziFrom %s: calling %s (from %s) with %s is deprecated and will be removed %s.
Instructions for updating:
%sNr   r   )r   IS_IN_GRAPH_MODErF   r   getcallargsr~   r&   rp   lenrq   rr   r   rL   varargsvarkwrG   rH   rI   r7   r   rh   r   )rL   rM   invalid_args
named_argsr   r   )
r   r   r   deprecated_arg_namesdeprecated_positionsrb   r   is_kwargs_deprecatedis_varargs_deprecatedrS   r   r   rX     sF    z=deprecated_args.<locals>.deprecated_wrapper.<locals>.new_funcrV   )r   rZ   r   getfullargspecr   r   r   rL   r|   r+   r[   r\   r!   r   r   keysr   r<   )rb   Zmissing_argsrX   r   r   r   r   rx   r   rS   )r   r   r   rb   r   r   r   r   rd     s<    





 #z+deprecated_args.<locals>.deprecated_wrapper)r,   r+   listr   popget)r   r   rx   rM   ry   rd   r   r   r   r     s    )

[r   c                    s,   t   std fdd}|S )aD  Decorator for marking specific function argument values as deprecated.

  This decorator logs a deprecation warning whenever the decorated function is
  called with the deprecated argument values. It has the following format:

    Calling <function> (from <module>) with <arg>=<value> is deprecated and
    will be removed after <date>. Instructions for updating:
      <instructions>

  If `date` is None, 'after <date>' is replaced with 'in a future version'.
  <function> will include the class name if it is a method.

  It also edits the docstring of the function: ' (deprecated arguments)' is
  appended to the first line of the docstring and a deprecation notice is
  prepended to the rest of the docstring.

  Args:
    date: String or None. The date the function is scheduled to be removed.
      Must be ISO 8601 (YYYY-MM-DD), or None
    instructions: String. Instructions on how to update code using the
      deprecated function.
    warn_once: If `True`, warn only the first time this function is called with
      deprecated argument values. Otherwise, every call (with a deprecated
      argument value) will log a warning.
    **deprecated_kwargs: The deprecated argument values.

  Returns:
    Decorated function or method.

  Raises:
    ValueError: If date is not None or in ISO 8601 format, or instructions are
      empty.
  z-Specify which argument values are deprecated.c                    sJ   t  d t  fdd}t j}t |d|S )r   deprecated_arg_valuesc                     s   t rtjg| R i |} D ]l\}}||v r$t|| |r$|ftvr$r^dt|f< tdt t	
j|| du rdnd   q$| i |S )rf   TzlFrom %s: calling %s (from %s) with %s=%s is deprecated and will be removed %s.
Instructions for updating:
%sNr   r   )rF   r   r   r&   r;   rG   rH   rI   r7   r   rh   r   )rL   rM   r   r   	arg_value)r   deprecated_kwargsrb   r   rS   r   r   rX   d  s$    zCdeprecated_arg_values.<locals>.deprecated_wrapper.<locals>.new_funcrV   )r   rZ   r[   r\   r(   r   r   r<   )rb   rX   r   r   r   r   rS   ra   r   rd   a  s    
z1deprecated_arg_values.<locals>.deprecated_wrapper)r,   r+   )r   r   rS   r   rd   r   r   r   r   :  s
    #
r   c                 C   s.   |dur*|dur&t d| d|  d|S |S )a  Looks up deprecated argument name and ensures both are not used.

  Args:
    new_name: new name of argument
    new_value: value of new argument (or None if not used)
    old_name: old name of argument
    old_value: value of old argument (or None if not used)
  Returns:
    The effective argument that should be used.
  Raises:
    ValueError: if new_value and old_value are both non-null
  NzCannot specify both 'z' and 'z'.)r+   )new_name	new_valueold_name	old_valuer   r   r   deprecated_argument_lookup~  s
    r   c                 C   s$   |  d| d|  d| d| S )Nz`%s`z%s:)replace)Zold_docZold_argumentZnew_argumentr   r   r   rewrite_argument_docstring  s    r   c                  c   s   t } da dV  | a dS )z)Temporarily silence deprecation warnings.FN)rF   )Zprint_deprecation_warningsr   r   r   silence  s    r   c                    s    fddS )au  Logs a warning when a module that has been moved to a new location is used.

  Copy the following code into the old module:

  ```
  import deprecation
  import new_module

  __getattr__ = deprecation.deprecate_moved_module(
      __name__, new_module, "2.9")  # adjust version number.
  ```

  Args:
    deprecated_name: Name of old module.
    new_module: Module to replace the old module.
    deletion_version: Version of TensorFlow in which the old module will be
      removed.

  Returns:
    A function that logs a warning and returns the symbol from the new module.
    Set this function as the module's `__getattr__`.
  c                    s0   t vr&tr&dt < tdj  t| S )NTzfPlease fix your imports. Module %s has been moved to %s. The old module will be deleted in version %s.)rG   rF   rH   rI   r
   getattr)rR   deletion_versionrP   getter
new_moduler   r   r     s    z&deprecate_moved_module.<locals>.getterr   )rP   r   r   r   r   r   deprecate_moved_module  s    r   c                       s    e Zd ZdZ fddZ  ZS )HiddenTfApiAttributea&  Hides a class attribute from the public API.

  Attributes in public classes can be hidden from the API by having an '_' in
  front of the name (e.g. ClassName._variables). This doesn't work when
  attributes or methods are inherited from a parent class. To hide inherited
  attributes, set their values to be `deprecation.hide_attribute_from_api`.
  For example, this is used in V2 Estimator to hide the deprecated
  export_savedmodel method:
    class EstimatorV2(Estimator):
       export_savedmodel = deprecation.hide_attribute_from_api('...')
  c                    s     fdd}t t| | d S )Nc                    s   t  d S r8   )AttributeError)Zunused_selfdeprecation_messager   r   raise_error  s    z2HiddenTfApiAttribute.__init__.<locals>.raise_error)rJ   r   rE   )rK   r   r   rU   r   r   rE     s    zHiddenTfApiAttribute.__init__)r
   r   r   r   rE   rT   r   r   rU   r   r     s   r   z#This attribute has been deprecated.)F)T)T)T)+r   collectionsr[   r-   r)   tensorflow.python.platformr   rH   tensorflow.python.utilr   r   r   r   r   Ztensorflow.tools.docsr   rF   rG   	Exceptionr	   r   r!   r(   r,   r7   r;   r@   r]   re   rV   
namedtuplero   r   r   r   r   contextmanagerr   r   propertyr   Zhide_attribute_from_apiZHIDDEN_ATTRIBUTEr   r   r   r   <module>   sL   	

s
X ;
D
	"