MCPcopy Index your code
hub / github.com/webpy/webpy / djangoerror

Function djangoerror

web/debugerror.py:240–318  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

238
239
240def djangoerror():
241 def _get_lines_from_file(filename, lineno, context_lines):
242 """
243 Returns context_lines before and after lineno from file.
244 Returns (pre_context_lineno, pre_context, context_line, post_context).
245 """
246 try:
247 source = open(filename).readlines()
248 lower_bound = max(0, lineno - context_lines)
249 upper_bound = lineno + context_lines
250
251 pre_context = [line.strip("\n") for line in source[lower_bound:lineno]]
252 context_line = source[lineno].strip("\n")
253 post_context = [
254 line.strip("\n") for line in source[lineno + 1 : upper_bound]
255 ]
256
257 return lower_bound, pre_context, context_line, post_context
258 except (OSError, IndexError):
259 return None, [], None, []
260
261 exception_type, exception_value, tback = sys.exc_info()
262 frames = []
263 while tback is not None:
264 filename = tback.tb_frame.f_code.co_filename
265 function = tback.tb_frame.f_code.co_name
266 lineno = tback.tb_lineno - 1
267
268 # hack to get correct line number for templates
269 lineno += tback.tb_frame.f_locals.get("__lineoffset__", 0)
270
271 (
272 pre_context_lineno,
273 pre_context,
274 context_line,
275 post_context,
276 ) = _get_lines_from_file(filename, lineno, 7)
277
278 if "__hidetraceback__" not in tback.tb_frame.f_locals:
279 frames.append(
280 web.storage(
281 {
282 "tback": tback,
283 "filename": filename,
284 "function": function,
285 "lineno": lineno,
286 "vars": tback.tb_frame.f_locals,
287 "id": id(tback),
288 "pre_context": pre_context,
289 "context_line": context_line,
290 "post_context": post_context,
291 "pre_context_lineno": pre_context_lineno,
292 }
293 )
294 )
295 tback = tback.tb_next
296 frames.reverse()
297

Callers 2

debugerrorFunction · 0.85
emailerrors_internalFunction · 0.85

Calls 6

_get_lines_from_fileFunction · 0.85
TemplateClass · 0.85
update_globals_templateFunction · 0.85
tFunction · 0.85
appendMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected