B
    лde                 @   s   d Z ddl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	 e
 aejejeddfZe	ddd Ze	d	d
d Ze	ddd Zdd Zdd Zdd ZdS )zBUtilities related to TensorFlow exception stack trace prettifying.    N)tf_decorator)	tf_exportz..z(debugging.is_traceback_filtering_enabledc              C   s   t tdd} | S )a  Check whether traceback filtering is currently enabled.

  See also `tf.debugging.enable_traceback_filtering()` and
  `tf.debugging.disable_traceback_filtering()`. Note that filtering out
  internal frames from the tracebacks of exceptions raised by TensorFlow code
  is the default behavior.

  Returns:
    True if traceback filtering is enabled
    (e.g. if `tf.debugging.enable_traceback_filtering()` was called),
    and False otherwise (e.g. if `tf.debugging.disable_traceback_filtering()`
    was called).
  valueT)getattr_ENABLE_TRACEBACK_FILTERING)r    r   X/var/www/html/venv/lib/python3.7/site-packages/tensorflow/python/util/traceback_utils.pyis_traceback_filtering_enabled    s    r	   z$debugging.enable_traceback_filteringc               C   s2   t jjdkst jjdk r(tdt j dt_dS )a  Enable filtering out TensorFlow-internal frames in exception stack traces.

  Raw TensorFlow stack traces involve many internal frames, which can be
  challenging to read through, while not being actionable for end users.
  By default, TensorFlow filters internal frames in most exceptions that it
  raises, to keep stack traces short, readable, and focused on what's
  actionable for end users (their own code).

  If you have previously disabled traceback filtering via
  `tf.debugging.disable_traceback_filtering()`, you can re-enable it via
  `tf.debugging.enable_traceback_filtering()`.

  Raises:
    RuntimeError: If Python version is not at least 3.7.
        zVTraceback filtering is only available with Python 3.7 or higher. This Python version: TN)sysversion_infomajorminorRuntimeErrorversionr   r   r   r   r   r   enable_traceback_filtering3   s    r   z%debugging.disable_traceback_filteringc               C   s
   dt _dS )aQ  Disable filtering out TensorFlow-internal frames in exception stack traces.

  Raw TensorFlow stack traces involve many internal frames, which can be
  challenging to read through, while not being actionable for end users.
  By default, TensorFlow filters internal frames in most exceptions that it
  raises, to keep stack traces short, readable, and focused on what's
  actionable for end users (their own code).

  Calling `tf.debugging.disable_traceback_filtering` disables this filtering
  mechanism, meaning that TensorFlow exceptions stack traces will include
  all frames, in particular TensorFlow-internal ones.

  **If you are debugging a TensorFlow-internal issue, you need to call
  `tf.debugging.disable_traceback_filtering`**.
  To re-enable traceback filtering afterwards, you can call
  `tf.debugging.enable_traceback_filtering()`.
  FN)r   r   r   r   r   r   disable_traceback_filteringL   s    r   c             C   s   xt D ]}|| krdS qW dS )NFT)_EXCLUDED_PATHS)fnameZ	exclusionr   r   r   include_framec   s    
r   c             C   st   d }t t| }x2t|D ]&\}}t|jjrt|||j	|}qW |d krp|rp|d \}}t|||j	|}|S )N)
list	tracebackwalk_tbreversedr   f_codeco_filenametypesTracebackTypef_lasti)tbZnew_tbZtb_listfline_nor   r   r   _process_traceback_framesj   s    r$   c                s4   t jjdkst jjdk r S  fdd}t |S )a{  Decorator to filter out TF-internal stack trace frames in exceptions.

  Raw TensorFlow stack traces involve many internal frames, which can be
  challenging to read through, while not being actionable for end users.
  By default, TensorFlow filters internal frames in most exceptions that it
  raises, to keep stack traces short, readable, and focused on what's
  actionable for end users (their own code).

  Arguments:
    fn: The function or method to decorate. Any exception raised within the
      function will be reraised with its internal stack trace frames filtered
      out.

  Returns:
    Decorated function or method.
  r
   r   c           
      s   yt  s | |S W n tk
r.    | |S X d }zHy
 | |S  tk
rx } zt|j}||d W d d }~X Y nX W d ~X d S )N)r	   	NameError	Exceptionr$   __traceback__with_traceback)argskwargsZfiltered_tbe)fnr   r   error_handler   s    

"z'filter_traceback.<locals>.error_handler)r   r   r   r   r   make_decorator)r,   r-   r   )r,   r   filter_tracebackv   s    r/   )__doc__osr   	threadingr   r   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   localr   pathabspathjoin__file__r   r	   r   r   r   r$   r/   r   r   r   r   <module>   s   