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

Function _get_lines_from_file

web/debugerror.py:241–259  ·  view source on GitHub ↗

Returns context_lines before and after lineno from file. Returns (pre_context_lineno, pre_context, context_line, post_context).

(filename, lineno, context_lines)

Source from the content-addressed store, hash-verified

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 = []

Callers 1

djangoerrorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected