Skip to content
Myr

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 file

Take 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 back
1# -*- 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 back
11import os
12import sys

added `MemoryGuard` to jdebugArmin Ronacherbefore adoption116b91c

line 13why, one step back
13import gc

[svn] doc changes + changes in the i18n system of jinjaArmin Ronacherbefore adoption85ddd3b

lines 14–15why, one step back
14from jinja import Environment
15from jinja.parser import Parser

[svn] implemented {% raw %} and improved jinja/django highlighterArmin Ronacherbefore adoptionb9c8ae1

line 16why, one step back
16from jinja.lexer import Lexer

[svn] doc changes + changes in the i18n system of jinjaArmin Ronacherbefore adoption85ddd3b

lines 17–19why, one step back
17from jinja.translators.python import PythonTranslator
1819

added `MemoryGuard` to jdebugArmin Ronacherbefore adoption116b91c

line 20why, one step back
20__all__ = ['e', 't', 'p', 'l', 'm']

[svn] doc changes + changes in the i18n system of jinjaArmin Ronacherbefore adoption85ddd3b

line 21why, one step back
21

looking for a jinja memleakArmin Ronacherbefore adoption525c704

lines 22–23why, one step back
22
23_global_frame = sys._getframe()

[svn] doc changes + changes in the i18n system of jinjaArmin Ronacherbefore adoption85ddd3b

lines 24–25why, one step back
24e = 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 back
26
27

[svn] many jinja changes:Armin Ronacherbefore adoptionfb5bebc

lines 28–30why, one step back
28def 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 back
31 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 back
32
33def l(x):

fixed awkward lexer bug in jinja that was yet untestedArmin Ronacherbefore adoption523bf4c

line 34why, one step back
34 for item in e.lexer.tokenize(x):

[svn] merged newparser into trunkArmin Ronacherbefore adoption1cc232c

lines 35–37why, one step back
35 print '%5s %-20s %r' % (item.lineno,
36 item.type,37 item.value)

added `MemoryGuard` to jdebugArmin Ronacherbefore adoption116b91c

lines 38–50why, one step back
38
39class 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 back
51 frm = sys._getframe()

added `MemoryGuard` to jdebugArmin Ronacherbefore adoption116b91c

lines 52–53why, one step back
52 result = []
53 for obj in gc.get_objects():

looking for a jinja memleakArmin Ronacherbefore adoption525c704

lines 54–55why, one step back
54 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 back
56 result.append(obj)
57 return result585960m = MemoryGuard()61

[svn] many jinja changes:Armin Ronacherbefore adoptionfb5bebc

lines 62–70why, one step back
62
63if __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())