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
040d200c
Commit
040d200c
authored
Aug 04, 1995
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added format_* functions (suggestion by Ken M)
parent
fe29c1f3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
7 deletions
+31
-7
Lib/traceback.py
Lib/traceback.py
+31
-7
No files found.
Lib/traceback.py
View file @
040d200c
...
@@ -16,12 +16,21 @@ def print_tb(tb, limit = None):
...
@@ -16,12 +16,21 @@ def print_tb(tb, limit = None):
co
=
f
.
f_code
co
=
f
.
f_code
filename
=
co
.
co_filename
filename
=
co
.
co_filename
name
=
co
.
co_name
name
=
co
.
co_name
print
' File "%s", line %d, in %s'
%
(
filename
,
lineno
,
name
)
print
' File "%s", line %d, in %s'
%
(
filename
,
lineno
,
name
)
line
=
linecache
.
getline
(
filename
,
lineno
)
line
=
linecache
.
getline
(
filename
,
lineno
)
if
line
:
print
' '
+
string
.
strip
(
line
)
if
line
:
print
' '
+
string
.
strip
(
line
)
tb
=
tb
.
tb_next
tb
=
tb
.
tb_next
n
=
n
+
1
n
=
n
+
1
def
format_tb
(
tb
,
limit
=
None
):
list
=
[]
for
filename
,
lineno
,
name
,
line
in
extract_tb
(
tb
,
limit
):
item
=
' File "%s", line %d, in %s
\
n
'
%
(
filename
,
lineno
,
name
)
if
line
:
item
=
item
+
' %s
\
n
'
%
string
.
strip
(
line
)
list
.
append
(
item
)
return
list
def
extract_tb
(
tb
,
limit
=
None
):
def
extract_tb
(
tb
,
limit
=
None
):
if
limit
is
None
:
if
limit
is
None
:
if
hasattr
(
sys
,
'tracebacklimit'
):
if
hasattr
(
sys
,
'tracebacklimit'
):
...
@@ -42,16 +51,29 @@ def extract_tb(tb, limit = None):
...
@@ -42,16 +51,29 @@ def extract_tb(tb, limit = None):
n
=
n
+
1
n
=
n
+
1
return
list
return
list
def
print_exception
(
etype
,
value
,
tb
,
limit
=
None
):
def
print_exception
(
etype
,
value
,
tb
,
limit
=
None
):
if
tb
:
if
tb
:
print
'Traceback (innermost last):'
print
'Traceback (innermost last):'
print_tb
(
tb
,
limit
)
print_tb
(
tb
,
limit
)
for
line
in
format_exception_only
(
etype
,
value
):
print
line
,
def
format_exception
(
etype
,
value
,
tb
,
limit
=
None
):
if
tb
:
list
=
[
'Traceback (innermost last):
\
n
'
]
list
=
list
+
format_tb
(
tb
,
limit
)
list
=
list
+
format_exception_only
(
etype
,
value
)
return
list
def
format_exception_only
(
etype
,
value
):
list
=
[]
if
type
(
etype
)
==
types
.
ClassType
:
if
type
(
etype
)
==
types
.
ClassType
:
stype
=
etype
.
__name__
stype
=
etype
.
__name__
else
:
else
:
stype
=
etype
stype
=
etype
if
value
is
None
:
if
value
is
None
:
print
stype
list
.
append
(
str
(
stype
)
+
'
\
n
'
)
else
:
else
:
if
etype
is
SyntaxError
:
if
etype
is
SyntaxError
:
try
:
try
:
...
@@ -60,22 +82,24 @@ def print_exception(etype, value, tb, limit = None):
...
@@ -60,22 +82,24 @@ def print_exception(etype, value, tb, limit = None):
pass
pass
else
:
else
:
if
not
filename
:
filename
=
"<string>"
if
not
filename
:
filename
=
"<string>"
print
' File "%s", line %d'
%
\
list
.
append
(
' File "%s", line %d
\
n
'
%
(
filename
,
lineno
)
(
filename
,
lineno
)
)
i
=
0
i
=
0
while
i
<
len
(
line
)
and
\
while
i
<
len
(
line
)
and
\
line
[
i
]
in
string
.
whitespace
:
line
[
i
]
in
string
.
whitespace
:
i
=
i
+
1
i
=
i
+
1
list
.
append
(
' %s
\
n
'
%
string
.
strip
(
line
))
s
=
' '
s
=
' '
print
s
+
string
.
strip
(
line
)
for
c
in
line
[
i
:
offset
-
1
]:
for
c
in
line
[
i
:
offset
-
1
]:
if
c
in
string
.
whitespace
:
if
c
in
string
.
whitespace
:
s
=
s
+
c
s
=
s
+
c
else
:
else
:
s
=
s
+
' '
s
=
s
+
' '
print
s
+
'^'
list
.
append
(
'%s^
\
n
'
%
s
)
value
=
msg
value
=
msg
print
'%s: %s'
%
(
stype
,
value
)
list
.
append
(
'%s: %s
\
n
'
%
(
str
(
stype
),
str
(
value
)))
return
list
def
print_exc
(
limit
=
None
):
def
print_exc
(
limit
=
None
):
print_exception
(
sys
.
exc_type
,
sys
.
exc_value
,
sys
.
exc_traceback
,
print_exception
(
sys
.
exc_type
,
sys
.
exc_value
,
sys
.
exc_traceback
,
...
...
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