Skip to content
Myr

[svn] some small code cleanups in jinja

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent a7804ef · Browse files · 3 files+42 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+42 added−17 removed

  • other:+42 added−17 removed

3 files+42 added−17 removed

modified:jinja/_debugger.c+6 added-2 removed
4 unmodified lines
5 * this module allows the jinja debugger to set the tb_next flag6 * on traceback objects. This is required to inject a traceback into7 * another one.8 *9 * For better windows support (not everybody has a visual studio 200310 * at home) it would be a good thing to have a ctypes implementation, but11 * because the struct is not exported there is currently no sane way.12 *13 * :copyright: 2007 by Armin Ronacher.14 * :license: BSD, see LICENSE for more details.15 */16
9 unmodified lines
26 PyObject *tb, *next;2728 if (!PyArg_ParseTuple(args, "OO", &tb, &next))29 return NULL;26 if (!(PyTraceBack_Check(tb) && (PyTraceBack_Check(next) || next == Py_None))) {30 if (!(PyTraceBack_Check(tb) && (PyTraceBack_Check(next) ||31 next == Py_None))) {32 PyErr_SetString(PyExc_TypeError, "traceback object required.");33 return NULL;34 }35
9 unmodified lines
45 "Set the tb_next member of a traceback object."},46 {NULL, NULL, 0, NULL} /* Sentinel */47};484449#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */50#define PyMODINIT_FUNC void51#endif52PyMODINIT_FUNC
6 unmodified lines
modified:jinja/_native.py+4 added-12 removed
32 unmodified lines
33 return list(self._stack)[::-1]34 stack = property(stack)3536 def pop(self):37 """38 Pop the last layer from the stack and return it.39 """37 """Pop the last layer from the stack and return it."""38 rv = self._pop()39 self.current = self._stack[0]40 return rv41
26 unmodified lines
68 return rv69 return self._undefined_singleton7071 def __setitem__(self, name, value):74 """75 Set a variable in the outermost layer.76 """72 """Set a variable in the outermost layer."""73 self.current[name] = value7475 def __delitem__(self, name):80 """81 Delete an variable in the outermost layer.82 """76 """Delete a variable in the outermost layer."""77 if name in self.current:78 del self.current[name]7980 def __contains__(self, name):87 """88 Check if the context contains a given variable.89 """81 """ Check if the context contains a given variable."""82 for layer in self._stack:83 if name in layer:84 return True85 return False
modified:jinja/debugger.py+32 added-3 removed
1 unmodified line
2"""3 jinja.debugger4 ~~~~~~~~~~~~~~56 The debugger module of awesomeness.6 This module implements helper function Jinja uses to give the users a7 possibility to develop Jinja templates like they would debug python code.8 It seamlessly integreates into the python traceback system, in fact it9 just modifies the trackback stack so that the line numbers are correct10 and the frame information are bound to the context and not the frame of11 the template evaluation loop.1213 To achive this it raises the exception it cought before in an isolated14 namespace at a given line. The locals namespace is set to the current15 template context.1617 The traceback generated by raising that exception is then either returned18 or linked with the former traceback if the `jinja._debugger` module is19 available. Because it's not possible to modify traceback objects from the20 python space this module is needed for this process.2122 If it's not available it just ignores the other frames. Because this can23 lead to actually harder to debug code there is a setting on the jinja24 environment to disable the debugging system.2526 The isolated namespace which is used to raise the exception also contains27 a `__loader__` name that helds a reference to a PEP 302 compatible loader.28 Because there are currently some traceback systems (such as the paste29 evalexception debugger) that do not provide the frame globals when30 retrieving the source from the linecache module, Jinja injects the source31 to the linecache module itself and changes the filename to a URL style32 "virtual filename" so that Jinja doesn't acidentally override other files33 in the linecache.3435 :copyright: 2007 by Armin Ronacher.36 :license: BSD, see LICENSE for more details.37"""38
37 unmodified lines
76 if isinstance(filename, unicode):77 filename = filename.encode('utf-8')7879 # generate an jinja unique filename used so that linecache53 # gets data that doesn't interferes with other modules80 # gets data that doesn't interfere with other modules81 if filename is None:82 vfilename = 'jinja://~%d' % randrange(0, 10000)83 filename = '<string>'84 else:
19 unmodified lines
104 exec code in globals, namespace105 except:106 exc_info = sys.exc_info()10781 # if we have an extended debugger we set the tb_next flag108 # if we have an extended debugger we set the tb_next flag so that109 # we don't loose the higher stack items.110 if has_extended_debugger and traceback is not None:111 tb_set_next(exc_info[2].tb_next, traceback.tb_next)112113 # otherwise just return the exc_info from the simple debugger
67 unmodified lines
181 virtual_filename182 )183184 def get_source(self, impname):185 """Return the source as bytestring."""186 source = ''187 if self.source is not None:188 source = self.source189 elif self.loader is not None:
7 unmodified lines