Skip to content
Myr

added `MemoryGuard` to jdebug

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 f0a65a6 · Browse files · 2 files+29 added−1 removed
This commit

State

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

Diff stats

2 files+29 added−1 removed

  • other:+29 added−1 removed

2 files+29 added−1 removed

modified:jinja/datastructure.py+1 added
533 unmodified lines
534535 def next(self):536 token = self._stream.current537 if token.type == 'eof':538 self._stream.close()539 raise StopIteration()540 self._stream.next()541 return token542
166 unmodified lines
modified:jdebug.py+28 added-1 removed
8 unmodified lines
9 :license: BSD, see LICENSE for more details.10"""11import os12import sys13import gc14from jinja import Environment15from jinja.parser import Parser16from jinja.lexer import Lexer17from jinja.translators.python import PythonTranslator181919__all__ = ['e', 't', 'p', 'l']20__all__ = ['e', 't', 'p', 'l', 'm']2122e = Environment()23t = e.from_string24
19 unmodified lines
44 print '%5s %-20s %r' % (item.lineno,45 item.type,46 item.value)4748class MemoryGuard(object):4950 def __init__(self):51 self.guarded_objects = {}52 self.clear = self.guarded_objects.clear5354 def freeze(self):55 self.clear()56 self.update()5758 def update(self):59 self.guarded_objects.clear()60 for obj in gc.get_objects():61 self.guarded_objects[id(obj)] = True6263 def get_delta(self):64 result = []65 for obj in gc.get_objects():66 if id(obj) not in self.guarded_objects:67 result.append(obj)68 return result697071m = MemoryGuard()727374if __name__ == '__main__':75 if len(sys.argv) > 1:76 from jinja import FileSystemLoader77 e.loader = FileSystemLoader(sys.argv[1])
4 unmodified lines