Format: application/x-python-code
1 o
2
3 ��h\� � @ s d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl Z ddl
4 Z
5 ddl
6 mZ ddlm
7 Z
8 mZmZmZ ddlZddlmZ ddlmZ ddlm mZ ddlmZ dd lmZ dd
9 lmZ ddlm Z ddl!m"Z" dd
10 l!m#Z$ ddl!m%Z% ddl&m'Z' dZ(dZ)dZ*e�+� de,de-fdd��Z.de
11 j/de-fdd�Z0e,fdd�Z1de2fdd�Z3dd � Z4dd!�d"d#�Z5G d$d%� d%ej6�Z7G d&d'� d'e7�Z8G d(d)� d)�Z9G d*d+� d+e7�Z:G d,d-� d-e:e8�Z;G d.d/� d/e;�Z<G d0d1� d1e;�Z=G d2d3� d3e8�Z>d4d5� Z?e?fd6d7�Z@e?fd8d9�ZAdS ):a]
12 Verbose and colourful traceback formatting.
13
14 **ColorTB**
15
16 I've always found it a bit hard to visually parse tracebacks in Python. The
17 ColorTB class is a solution to that problem. It colors the different parts of a
18 traceback in a manner similar to what you would expect from a syntax-highlighting
19 text editor.
20
21 Installation instructions for ColorTB::
22
23 import sys,ultratb
24 sys.excepthook = ultratb.ColorTB()
25
26 **VerboseTB**
27
28 I've also included a port of Ka-Ping Yee's "cgitb.py" that produces all kinds
29 of useful info when a traceback occurs. Ping originally had it spit out HTML
30 and intended it for CGI programmers, but why should they have all the fun? I
31 altered it to spit out colored text to the terminal. It's a bit overwhelming,
32 but kind of neat, and maybe useful for long-running programs that you believe
33 are bug-free. If a crash *does* occur in that type of program you want details.
34 Give it a shot--you'll love it or you'll hate it.
35
36 .. note::
37
38 The Verbose mode prints the variables currently visible where the exception
39 happened (shortening their strings if too long). This can potentially be
40 very slow, if you happen to have a huge data structure whose string
41 representation is complex to compute. Your computer may appear to freeze for
42 a while with cpu usage at 100%. If this occurs, you can cancel the traceback
43 with Ctrl-C (maybe hitting it more than once).
44
45 If you encounter this kind of situation often, you may want to use the
46 Verbose_novars mode instead of the regular Verbose, which avoids formatting
47 variables (but otherwise includes the information and context given by
48 Verbose).
49
50 .. note::
51
52 The verbose mode print all variables in the stack, which means it can
53 potentially leak sensitive information like access keys, or unencrypted
54 password.
55
56 Installation instructions for VerboseTB::
57
58 import sys,ultratb
59 sys.excepthook = ultratb.VerboseTB()
60
61 Note: Much of the code in this module was lifted verbatim from the standard
62 library module 'traceback.py' and Ka-Ping Yee's 'cgitb.py'.
63
64 Color schemes
65 -------------
66
67 The colors are defined in the class TBTools through the use of the
68 ColorSchemeTable class. Currently the following exist:
69
70 - NoColor: allows all of this module to be used in any terminal (the color
71 escapes are just dummy blank strings).
72
73 - Linux: is meant to look good in a terminal like the Linux console (black
74 or very dark background).
75
76 - LightBG: similar to Linux but swaps dark/light colors to be more readable
77 in light background terminals.
78
79 - Neutral: a neutral color scheme that should be readable on both light and
80 dark background
81
82 You can implement other color schemes easily, the syntax is fairly
83 self-explanatory. Please send back new schemes you develop to the author for
84 possible inclusion in future releases.
85
86 Inheritance diagram:
87
88 .. inheritance-diagram:: IPython.core.ultratb
89 :parts: 3
90 � )�SequenceN)�
91 TracebackType)�Any�List�Optional�Tuple)�Terminal256Formatter)�get_style_by_name)�get_ipython)�debugger)�DisplayTrap)�exception_colors)�
92 PyColorize)�path)� py3compat)�get_terminal_size� �NoColori'