Skip to content
Myr

[svn] last changes from yesterday so that i can continue working in school on it

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 20eacb7 · Browse files · 5 files+76 added−5 removed
This commit

State

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

Diff stats

5 files+76 added−5 removed

  • other:+76 added−5 removed

5 files+76 added−5 removed

modified:jinja/translators/python.py+14 added-2 removed
84 unmodified lines
85 nodes.IfCondition: self.handle_if_condition,86 nodes.Cycle: self.handle_cycle,87 nodes.Print: self.handle_print,88 nodes.Macro: self.handle_macro,89 nodes.Set: self.handle_set,90 nodes.Filter: self.handle_filter,91 nodes.Block: self.handle_block,92 nodes.Include: self.handle_include,93 # used python nodes
42 unmodified lines
136 return Template(environment,137 compile(translator.translate(), filename, 'exec'))138 process = staticmethod(process)139139 # -- private methods140 # -- private helper methods141142 def indent(self, text):143 """144 Indent the current text.
1 unmodified line
146 return (' ' * (self.indention * 4)) + text147148 def filter(self, s, filter_nodes):149 """149 Apply a filter on an object.150 Apply a filter on an object that already is a python expression.151 Used to avoid redundant code in bitor and the filter directive.152 """153 filters = []154 for n in filter_nodes:155 if n.__class__ is ast.CallFunc:
59 unmodified lines
215 block.replace(node.blocks[block.name])216 node = tmpl217218 lines = [219 'from __future__ import division\n'220 'from jinja.datastructure import Undefined, LoopContext, CycleContext\n\n'221 'def generate(context, write):\n'222 ' # BOOTSTRAPPING CODE\n'223 ' environment = context.environment\n'
153 unmodified lines
377 buf.append(self.indent('context[%r] = macro' % node.name))378379 return '\n'.join(buf)380381 def handle_set(self, node):382 """383 Handle variable assignments.384 """385 return self.indent('context[%r] = %s' % (386 node.name,387 self.handle_node(node.expr)388 ))389390 def handle_filter(self, node):391 """392 Handle filter sections.393 """
327 unmodified lines
modified:jinja/datastructure.py+4 added-1 removed
164 unmodified lines
165 Used by `Environment.iterate`.166 """167168 jinja_allowed_attributes = ['index', 'index0', 'length', 'parent',169 'even', 'odd', 'revindex0', 'revindex']169 'even', 'odd', 'revindex0', 'revindex',170 'first', 'last']171172 def __init__(self, seq, parent, loop_function):173 self.loop_function = loop_function174 self.parent = parent
18 unmodified lines
193 revindex = property(lambda s: s._stack[-1]['length'] - s._stack[-1]['index'])194 length = property(lambda s: s._stack[-1]['length'])195 even = property(lambda s: s._stack[-1]['index'] % 2 == 0)196 odd = property(lambda s: s._stack[-1]['index'] % 2 == 1)197 first = property(lambda s: s._stack[-1]['index'] == 0)198 last = property(lambda s: s._stack[-1]['index'] == s._stack[-1]['length'] - 1)199200 def __iter__(self):201 s = self._stack[-1]202 for idx, item in enumerate(s['seq']):
93 unmodified lines
modified:jinja/nodes.py+20 added
201 unmodified lines
202 self.body203 )204205206class Set(Node):207 """208 Allow defining own variables.209 """210211 def __init__(self, lineno, name, expr):212 self.lineno = lineno213 self.name = name214 self.expr = expr215216 def get_items(self):217 return [self.name, self.expr]218219 def __repr__(self):220 return 'Set(%r, %r)' % (221 self.name,222 self.expr223 )224225226class Filter(Node):227 """228 Node for filter sections.229 """
73 unmodified lines
modified:jinja/parser.py+16 added-2 removed
48 unmodified lines
49 self.directives = {50 'for': self.handle_for_directive,51 'if': self.handle_if_directive,52 'cycle': self.handle_cycle_directive,53 'set': self.handle_set_directive,54 'filter': self.handle_filter_directive,55 'print': self.handle_print_directive,56 'macro': self.handle_macro_directive,57 'block': self.handle_block_directive,
67 unmodified lines
125 # ast is something like Discard(CallFunc(Name('_cycle'), ...))126 # skip that.127 return nodes.Cycle(lineno, ast.expr.args[0])128129 def handle_set_directive(self, lineno, gen):130 """131 Handle {% set foo = 'value of foo' %}.132 """133 try:134 name = gen.next()135 if name[1] != 'name' or gen.next()[1:] != ('operator', '='):136 raise ValueError()137 except (StopIteration, ValueError):138 raise TemplateSyntaxError('invalid syntax for set', lineno)139 ast = self.parse_python(lineno, gen, '(%s)')140 return nodes.Set(lineno, name[1], ast.expr)141142 def handle_filter_directive(self, lineno, gen):143 """144 Handle {% filter foo|bar %} directives.145 """
18 unmodified lines
164 return nodes.Print(lineno, arguments[0])165166 def handle_macro_directive(self, lineno, gen):167 """154 Handle {% macro foo(bar, baz) %}.168 Handle {% macro foo bar, baz %}.169 """170 try:171 macro_name = gen.next()172 except StopIteration:
56 unmodified lines
229 if len(tokens) != 1 or tokens[0][1] != 'string':230 raise TemplateSyntaxError('include requires a string', lineno)231 return nodes.Include(lineno, tokens[0][2][1:-1])232219 def parse_python(self, lineno, gen, template='%s'):233 def parse_python(self, lineno, gen, template):234 """235 Convert the passed generator into a flat string representing236 python sourcecode and return an ast node or raise a237 TemplateSyntaxError.
114 unmodified lines
added:jdebug.py+22 added
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"""11from jinja import Environment12from jinja.parser import Parser13from jinja.translators.python import PythonTranslator141516__all__ = ['e', 't', 'p']1718e = Environment()19t = e.from_string2021def p(x):22 print PythonTranslator(e, Parser(e, x).parse()).translate()