jdebug.py
This file
Path
jdebug.py
70 lines · 1.6 KiB · Python
Last changed by
fixed awkward lexer bug in jinja that was yet untestedArmin Ronacherbefore adoption523bf4c
History of this fileTake it
The walk stopped after 200 commits: lines older than 85ddd3b point at it.
[svn] doc changes + changes in the i18n system of jinjaArmin Ronacherbefore adoption85ddd3b
lines 1–10why, one step back1# -*- coding: utf-8 -*-2"""3 jdebug4 ~~~~~~56 Helper module to simplify jinja debugging. Use78 :copyright: 2006 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""[svn] implemented `{{ super() }}` for blocks. This checkin makes jinja much slower. I'll improve that as soon as possibleArmin Ronacherbefore adoptiona690146
lines 11–12why, one step back11import os12import sysadded `MemoryGuard` to jdebugArmin Ronacherbefore adoption116b91c
line 13why, one step back13import gc[svn] doc changes + changes in the i18n system of jinjaArmin Ronacherbefore adoption85ddd3b
lines 14–15why, one step back14from jinja import Environment15from jinja.parser import Parser[svn] implemented {% raw %} and improved jinja/django highlighterArmin Ronacherbefore adoptionb9c8ae1
line 16why, one step back16from jinja.lexer import Lexer[svn] doc changes + changes in the i18n system of jinjaArmin Ronacherbefore adoption85ddd3b
lines 17–19why, one step back17from jinja.translators.python import PythonTranslator1819added `MemoryGuard` to jdebugArmin Ronacherbefore adoption116b91c
line 20why, one step back20__all__ = ['e', 't', 'p', 'l', 'm'][svn] doc changes + changes in the i18n system of jinjaArmin Ronacherbefore adoption85ddd3b
line 21why, one step back21looking for a jinja memleakArmin Ronacherbefore adoption525c704
lines 22–23why, one step back2223_global_frame = sys._getframe()[svn] doc changes + changes in the i18n system of jinjaArmin Ronacherbefore adoption85ddd3b
lines 24–25why, one step back24e = Environment()25t = e.from_string[svn] implemented `{{ super() }}` for blocks. This checkin makes jinja much slower. I'll improve that as soon as possibleArmin Ronacherbefore adoptiona690146
lines 26–27why, one step back2627[svn] many jinja changes:Armin Ronacherbefore adoptionfb5bebc
lines 28–30why, one step back28def p(x=None, f=None):29 if x is None and f is not None:30 x = e.loader.get_source(f)[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c
line 31why, one step back31 print PythonTranslator(e, Parser(e, x, f).parse(), None).translate()[svn] implemented {% raw %} and improved jinja/django highlighterArmin Ronacherbefore adoptionb9c8ae1
lines 32–33why, one step back3233def l(x):fixed awkward lexer bug in jinja that was yet untestedArmin Ronacherbefore adoption523bf4c
line 34why, one step back34 for item in e.lexer.tokenize(x):[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c
lines 35–37why, one step back35 print '%5s %-20s %r' % (item.lineno,36 item.type,37 item.value)added `MemoryGuard` to jdebugArmin Ronacherbefore adoption116b91c
lines 38–50why, one step back3839class MemoryGuard(object):4041 def __init__(self):42 self.guarded_objects = {}43 self.clear = self.guarded_objects.clear4445 def freeze(self):46 self.clear()47 for obj in gc.get_objects():48 self.guarded_objects[id(obj)] = True4950 def get_delta(self):looking for a jinja memleakArmin Ronacherbefore adoption525c704
line 51why, one step back51 frm = sys._getframe()added `MemoryGuard` to jdebugArmin Ronacherbefore adoption116b91c
lines 52–53why, one step back52 result = []53 for obj in gc.get_objects():looking for a jinja memleakArmin Ronacherbefore adoption525c704
lines 54–55why, one step back54 if id(obj) not in self.guarded_objects and \55 obj is not frm and obj is not result:added `MemoryGuard` to jdebugArmin Ronacherbefore adoption116b91c
lines 56–61why, one step back56 result.append(obj)57 return result585960m = MemoryGuard()61[svn] many jinja changes:Armin Ronacherbefore adoptionfb5bebc
lines 62–70why, one step back6263if __name__ == '__main__':64 if len(sys.argv) > 1:65 from jinja import FileSystemLoader66 e.loader = FileSystemLoader(sys.argv[1])67 if len(sys.argv) > 2:68 p(f=sys.argv[2])69 else:70 p(sys.stdin.read())