def __init__(self, environment): CodeGenerator.__init__(self, environment, '<introspection>', '<introspection>') self._getattr_stack = 0 self._varstack = [] self._undeclared = set()
def generate(self, templates=None): for name in templates if templates is not None else self.get_all_templates(): template, filename, uptodate = self.loader.get_source(self.environment, name) generator = CodeGenerator(self.environment, name, filename) source = env.parse(template, name, filename) generator.visit(source) yield generator.stream.getvalue(), name, filename
def visit_Compare(self, node, frame): if node.ops[0].op not in ('in', 'notin'): CodeGenerator.visit_Compare(self, node, frame) return oper = node.ops[0] if oper.op == 'notin': self.write('!') self.write('Jasinja.utils.contains(') self.visit(node.expr, frame) self.write(', ') self.visit(oper.expr, frame) self.write(')')
def __init__(self, environment): CodeGenerator.__init__(self, environment, '<introspection>', '<introspection>') self.undeclared_identifiers = set()
def enter_frame(self, frame): """Remember all undeclared identifiers.""" CodeGenerator.enter_frame(self, frame) for _, (action, param) in iteritems(frame.symbols.loads): if action == 'resolve': self.undeclared_identifiers.add(param)
def _generate(self, source, name, filename, defer_init=False): generator = CodeGenerator(self, name, filename) generator.visit(source) return generator.stream.getvalue()
def __init__(self, *args, **kwargs): CodeGenerator.__init__(self, *args, **kwargs) self.args = {} self.prototype = None
def pygen(env, name): src, fn, up = env.loader.get_source(env, name) gen = CodeGenerator(env, 'blah', 'index.html', None, False) gen.visit(compile(env, src)) return gen.stream.getvalue()