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
e6bf15a69ea0
Commit
b4ca625e
authored
Nov 26, 2019
by
Laurent Peuch
Browse files
[debug-toolbar/display_source_code] add function to generate html link to source code
parent
3a38f779bed5
Changes
1
Show whitespace changes
Inline
Side-by-side
cubicweb/pyramid/debug_source_code.py
View file @
e6bf15a6
...
...
@@ -36,6 +36,26 @@ DEBUG_DISPLAY_SOURCE_CODE_PATH = '_debug_display_source_code'
FILES_WHITE_LIST
=
set
()
def
_generate_link_to_source
(
file_path
,
start
=
None
,
end
=
None
,
tag_body
=
"<>"
):
if
start
:
# step back a bit so we have a bit of top padding wen displaying the page
# and the highlighted line isn't glued to top of the browser window
line_anchor
=
max
(
0
,
start
-
10
)
if
end
:
return
'<a href="../%s?file=%s&line=%s&end=%s#line-%s" target="_blank">%s</a>'
%
(
DEBUG_DISPLAY_SOURCE_CODE_PATH
,
file_path
,
start
,
end
,
line_anchor
,
tag_body
)
else
:
return
'<a href="../%s?file=%s&line=%s#line-%s" target="_blank">%s</a>'
%
(
DEBUG_DISPLAY_SOURCE_CODE_PATH
,
file_path
,
start
,
line_anchor
,
tag_body
)
return
'<a href="../%s?file=%s" target="_blank">%s</a>'
%
(
DEBUG_DISPLAY_SOURCE_CODE_PATH
,
file_path
,
tag_body
)
def
source_code_url
(
object_or_class
):
if
object_or_class
is
None
:
return
""
...
...
@@ -54,17 +74,9 @@ def source_code_url(object_or_class):
try
:
source_code
,
line
=
inspect
.
getsourcelines
(
object_or_class
)
except
OSError
:
# when we couldn't read the source code/line
return
'<a href="../%s?file=%s" target="_blank"><></a>'
%
(
DEBUG_DISPLAY_SOURCE_CODE_PATH
,
file_path
)
return
_generate_link_to_source
(
file_path
)
# step back a bit so we have a bit of top padding wen displaying the page
# and the highlighted line isn't glued to top of the browser window
line_anchor
=
max
(
0
,
line
-
10
)
return
'<a href="../%s?file=%s&line=%s&end=%s#line-%s" target="_blank"><></a>'
%
(
DEBUG_DISPLAY_SOURCE_CODE_PATH
,
file_path
,
line
,
line
+
len
(
source_code
),
line_anchor
)
return
_generate_link_to_source
(
file_path
,
line
,
line
+
len
(
source_code
))
def
debug_display_source_code
(
request
):
...
...
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