MCPcopy Index your code
hub / github.com/nodejs/node / fake_exc_info

Function fake_exc_info

tools/inspector_protocol/jinja2/debug.py:228–295  ·  view source on GitHub ↗

Helper for `translate_exception`.

(exc_info, filename, lineno)

Source from the content-addressed store, hash-verified

226
227
228def fake_exc_info(exc_info, filename, lineno):
229 """Helper for `translate_exception`."""
230 exc_type, exc_value, tb = exc_info
231
232 # figure the real context out
233 if tb is not None:
234 locals = get_jinja_locals(tb.tb_frame.f_locals)
235
236 # if there is a local called __jinja_exception__, we get
237 # rid of it to not break the debug functionality.
238 locals.pop('__jinja_exception__', None)
239 else:
240 locals = {}
241
242 # assamble fake globals we need
243 globals = {
244 '__name__': filename,
245 '__file__': filename,
246 '__jinja_exception__': exc_info[:2],
247
248 # we don't want to keep the reference to the template around
249 # to not cause circular dependencies, but we mark it as Jinja
250 # frame for the ProcessedTraceback
251 '__jinja_template__': None
252 }
253
254 # and fake the exception
255 code = compile('\n' * (lineno - 1) + raise_helper, filename, 'exec')
256
257 # if it's possible, change the name of the code. This won't work
258 # on some python environments such as google appengine
259 try:
260 if tb is None:
261 location = 'template'
262 else:
263 function = tb.tb_frame.f_code.co_name
264 if function == 'root':
265 location = 'top-level template code'
266 elif function.startswith('block_'):
267 location = 'block "%s"' % function[6:]
268 else:
269 location = 'template'
270
271 if PY2:
272 code = CodeType(0, code.co_nlocals, code.co_stacksize,
273 code.co_flags, code.co_code, code.co_consts,
274 code.co_names, code.co_varnames, filename,
275 location, code.co_firstlineno,
276 code.co_lnotab, (), ())
277 else:
278 code = CodeType(0, code.co_kwonlyargcount,
279 code.co_nlocals, code.co_stacksize,
280 code.co_flags, code.co_code, code.co_consts,
281 code.co_names, code.co_varnames, filename,
282 location, code.co_firstlineno,
283 code.co_lnotab, (), ())
284 except Exception as e:
285 pass

Callers 2

translate_syntax_errorFunction · 0.85
translate_exceptionFunction · 0.85

Calls 5

get_jinja_localsFunction · 0.85
compileFunction · 0.85
popMethod · 0.80
exc_infoMethod · 0.80
execFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…