Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
8790419e
Commit
8790419e
authored
Jul 01, 1994
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New module, formats traceback just like the C code does
parent
e739e2ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
Lib/traceback.py
Lib/traceback.py
+57
-0
No files found.
Lib/traceback.py
0 → 100644
View file @
8790419e
# Format and print Python stack traces
import
linecache
import
string
import
sys
def
print_tb
(
tb
,
limit
=
None
):
if
limit
is
None
:
if
hasattr
(
sys
,
'tracebacklimit'
):
limit
=
sys
.
tracebacklimit
n
=
0
while
tb
is
not
None
and
(
limit
is
None
or
n
<
limit
):
f
=
tb
.
tb_frame
lineno
=
tb
.
tb_lineno
co
=
f
.
f_code
filename
=
co
.
co_filename
name
=
co
.
co_name
print
' File "%s", line %d, in %s'
%
(
filename
,
lineno
,
name
)
line
=
linecache
.
getline
(
filename
,
lineno
)
if
line
:
print
' '
+
string
.
strip
(
line
)
tb
=
tb
.
tb_next
n
=
n
+
1
def
extract_tb
(
tb
,
limit
=
None
):
if
limit
is
None
:
if
hasattr
(
sys
,
'tracebacklimit'
):
limit
=
sys
.
tracebacklimit
list
=
[]
n
=
0
while
tb
is
not
None
and
(
limit
is
None
or
n
<
limit
):
f
=
tb
.
tb_frame
lineno
=
tb
.
tb_lineno
co
=
f
.
f_code
filename
=
co
.
co_filename
name
=
co
.
co_name
line
=
linecache
.
getline
(
filename
,
lineno
)
if
line
:
line
=
string
.
strip
(
line
)
else
:
line
=
None
list
.
append
(
filename
,
lineno
,
name
,
line
)
tb
=
tb
.
tb_next
n
=
n
+
1
return
list
def
print_exception
(
type
,
value
,
tb
,
limit
=
None
):
print
'Traceback (innermost last):'
print_tb
(
tb
,
limit
)
print
type
,
if
value
is
not
None
:
print
':'
,
value
,
print
def
print_exc
(
limit
=
None
):
print_exception
(
sys
.
exc_type
,
sys
.
exc_value
,
sys
.
exc_traceback
,
limit
)
def
print_last
(
limit
=
None
):
print_exception
(
sys
.
last_type
,
sys
.
last_value
,
sys
.
last_traceback
,
limit
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment