77 return _generate_link_to_source(file_path) |
79 return _generate_link_to_source(file_path) |
78 |
80 |
79 return _generate_link_to_source(file_path, line, line + len(source_code)) |
81 return _generate_link_to_source(file_path, line, line + len(source_code)) |
80 |
82 |
81 |
83 |
|
84 def source_code_url_in_stack(stack, highlighted=False): |
|
85 new_stack = [] |
|
86 |
|
87 if highlighted: |
|
88 for i in stack.split(" File "): |
|
89 # expecting this format: |
|
90 # '<span class="nb">"/path/to/file.py"</span>, |
|
91 # line <span class="m">885</span>,...' |
|
92 if not i.startswith('<span class="nb">'): |
|
93 new_stack.append(i) |
|
94 continue |
|
95 |
|
96 # this will give: |
|
97 # ['<span class="nb">', '/file/to/path.py', '</span>, ...'] |
|
98 tag, file_path, rest = i.split(""", 2) |
|
99 |
|
100 # "rest" is like that: '</span>, line <span class="m">885</span>, ...' |
|
101 # we want to extrait "885" here |
|
102 line_number = int("".join(dropwhile(lambda x: not x.isdigit(), rest)).split("<")[0]) |
|
103 |
|
104 new_stack.append("%s%s%s" % ( |
|
105 tag, |
|
106 _generate_link_to_source(file_path, start=line_number, |
|
107 tag_body=""%s"" % file_path), |
|
108 rest, |
|
109 )) |
|
110 |
|
111 FILES_WHITE_LIST.add(file_path) |
|
112 |
|
113 new_stack = " File ".join(new_stack) |
|
114 |
|
115 # no syntax |
|
116 else: |
|
117 for i in stack.split("\n"): |
|
118 # expecting this format: |
|
119 # File "/path/to/file.py", line 885, in stuf\n some_code\nFile "/stuff.py", line... |
|
120 if not i.startswith(" File "): |
|
121 new_stack.append(i) |
|
122 continue |
|
123 |
|
124 # this will give: |
|
125 # ['File "', '/path/to/file.py', '", line 885, in stuf'] |
|
126 beginning, file_path, rest = i.split('"', 2) |
|
127 line_number = int("".join(dropwhile(lambda x: not x.isdigit(), rest)).split(",")[0]) |
|
128 |
|
129 new_stack.append("%s%s%s" % ( |
|
130 beginning, |
|
131 _generate_link_to_source(file_path, start=line_number, |
|
132 tag_body='"%s"' % file_path), |
|
133 rest, |
|
134 )) |
|
135 |
|
136 FILES_WHITE_LIST.add(file_path) |
|
137 |
|
138 new_stack = "\n".join(new_stack) |
|
139 |
|
140 return new_stack |
|
141 |
|
142 |
82 def debug_display_source_code(request): |
143 def debug_display_source_code(request): |
83 """ |
144 """ |
84 This view display a python source file content for making debugging easier. |
145 This view display a python source file content for making debugging easier. |
85 |
146 |
86 It is only activated on debug mode (-D) for pyramid during development. |
147 It is only activated on debug mode (-D) for pyramid during development. |