Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubicweb
Commits
38f22b8b4459
Commit
f67623ea
authored
Sep 27, 2019
by
Laurent Peuch
Browse files
[debug-toolbar/display_source_code] add a function to add links to source file in traceback
Closes #17256791
parent
e6bf15a69ea0
Changes
1
Hide whitespace changes
Inline
Side-by-side
cubicweb/pyramid/debug_source_code.py
View file @
38f22b8b
...
...
@@ -25,6 +25,8 @@ import os
import
logging
import
inspect
from
itertools
import
dropwhile
from
pyramid.response
import
Response
from
mako.template
import
Template
...
...
@@ -79,6 +81,65 @@ def source_code_url(object_or_class):
return
_generate_link_to_source
(
file_path
,
line
,
line
+
len
(
source_code
))
def
source_code_url_in_stack
(
stack
,
highlighted
=
False
):
new_stack
=
[]
if
highlighted
:
for
i
in
stack
.
split
(
" File "
):
# expecting this format:
# '<span class="nb">"/path/to/file.py"</span>,
# line <span class="m">885</span>,...'
if
not
i
.
startswith
(
'<span class="nb">'
):
new_stack
.
append
(
i
)
continue
# this will give:
# ['<span class="nb">', '/file/to/path.py', '</span>, ...']
tag
,
file_path
,
rest
=
i
.
split
(
"""
,
2
)
# "rest" is like that: '</span>, line <span class="m">885</span>, ...'
# we want to extrait "885" here
line_number
=
int
(
""
.
join
(
dropwhile
(
lambda
x
:
not
x
.
isdigit
(),
rest
)).
split
(
"<"
)[
0
])
new_stack
.
append
(
"%s%s%s"
%
(
tag
,
_generate_link_to_source
(
file_path
,
start
=
line_number
,
tag_body
=
""%s""
%
file_path
),
rest
,
))
FILES_WHITE_LIST
.
add
(
file_path
)
new_stack
=
" File "
.
join
(
new_stack
)
# no syntax
else
:
for
i
in
stack
.
split
(
"
\n
"
):
# expecting this format:
# File "/path/to/file.py", line 885, in stuf\n some_code\nFile "/stuff.py", line...
if
not
i
.
startswith
(
" File "
):
new_stack
.
append
(
i
)
continue
# this will give:
# ['File "', '/path/to/file.py', '", line 885, in stuf']
beginning
,
file_path
,
rest
=
i
.
split
(
'"'
,
2
)
line_number
=
int
(
""
.
join
(
dropwhile
(
lambda
x
:
not
x
.
isdigit
(),
rest
)).
split
(
","
)[
0
])
new_stack
.
append
(
"%s%s%s"
%
(
beginning
,
_generate_link_to_source
(
file_path
,
start
=
line_number
,
tag_body
=
'"%s"'
%
file_path
),
rest
,
))
FILES_WHITE_LIST
.
add
(
file_path
)
new_stack
=
"
\n
"
.
join
(
new_stack
)
return
new_stack
def
debug_display_source_code
(
request
):
"""
This view display a python source file content for making debugging easier.
...
...
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