Skip to content
Myr

fixed setup.py, a type and removed the possibility to use multiple statements per block. The latter makes it easier to write custom tags

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 7324eb8 · Browse files · 5 files+11 added−34 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+11 added−34 removed

  • other:+11 added−34 removed

5 files+11 added−34 removed

modified:jinja2/ext.py+1 added
32 unmodified lines
33 """Called if one of the tags matched."""343536class CacheExtension(Extension):37 """An example extension that adds cacheable blocks."""38 tags = set(['cache'])3940 def parse(self, parser):41 lineno = parser.stream.next().lineno
8 unmodified lines
modified:jinja2/i18n.py+1 added-2 removed
148 unmodified lines
149 parser.stream.next()150 referenced.update(plural_names)151 else:152 parser.stream.next()153 parser.end_statement()153154 # register free names as simple name expressions155 for var in referenced:156 if var not in variables:
14 unmodified lines
171 if variables:172 variables = nodes.Dict([nodes.Pair(nodes.Const(x, lineno=lineno), y)173 for x, y in variables.items()])174 else:176 vairables = None175 variables = None176177 node = self._make_node(singular, plural, variables, plural_expr)178 node.set_lineno(lineno)179 return node
57 unmodified lines
modified:jinja2/lexer.py+2 added-3 removed
36 unmodified lines
3738# set of used keywords39keywords = set(['and', 'block', 'elif', 'else', 'endblock', 'print',40 'endfilter', 'endfor', 'endif', 'endmacro', 'endraw',41 'extends', 'filter', 'for', 'if', 'in',42 'include', 'is', 'macro', 'not', 'or', 'raw',43 'recursive', 'set', 'call', 'endcall'])41 'extends', 'filter', 'for', 'if', 'in', 'include'42 'is', 'macro', 'not', 'or', 'raw', 'call', 'endcall'])4344# bind operators to token types45operators = {46 '+': 'add',
452 unmodified lines
modified:jinja2/parser.py+6 added-28 removed
14 unmodified lines
1516_statement_keywords = frozenset(['for', 'if', 'block', 'extends', 'print',17 'macro', 'include'])18_compare_operators = frozenset(['eq', 'ne', 'lt', 'lteq', 'gt', 'gteq', 'in'])19statement_end_tokens = set(['elif', 'else', 'endblock', 'endfilter',20 'endfor', 'endif', 'endmacro', 'variable_end',21 'in', 'recursive', 'endcall', 'block_end'])19statement_end_tokens = set(['variable_end', 'block_end', 'in'])202122class Parser(object):23 """The template parser class.
13 unmodified lines
37 for extension in environment.extensions:38 for tag in extension.tags:39 self.extensions[tag] = extension.parse4043 def end_statement(self):44 """Make sure that the statement ends properly."""45 if self.stream.current.type is 'semicolon':46 self.stream.next()47 elif self.stream.current.type not in statement_end_tokens:48 raise TemplateSyntaxError('ambigous end of statement',49 self.stream.current.lineno,50 self.filename)5141 def parse_statement(self):42 """Parse a single statement."""43 token_type = self.stream.current.type44 if token_type in _statement_keywords:
11 unmodified lines
56 if self.stream.current.type == 'assign':57 result = self.parse_assign(expr)58 else:59 result = nodes.ExprStmt(expr, lineno=lineno)71 self.end_statement()60 return result6162 def parse_assign(self, target):63 """Parse an assign statement."""
2 unmodified lines
66 raise TemplateSyntaxError("can't assign to '%s'" %67 target, target.lineno,68 self.filename)69 expr = self.parse_tuple()82 self.end_statement()70 target.set_ctx('store')71 return nodes.Assign(target, expr, lineno=lineno)7273 def parse_statements(self, end_tokens, drop_needle=False):
4 unmodified lines
78 # the first token may be a colon for python compatibility79 if self.stream.current.type is 'colon':80 self.stream.next()8195 if self.stream.current.type is 'block_end':96 self.stream.next()97 result = self.subparse(end_tokens)98 else:99 result = []100 while not self.stream.current.test_many(end_tokens):101 if self.stream.current.type is 'block_end':102 self.stream.next()103 result.extend(self.subparse(end_tokens))104 break105 result.append(self.parse_statement())82 # in the future it would be possible to add whole code sections83 # by adding some sort of end of statement token and parsing those here.84 self.stream.expect('block_end')85 result = self.subparse(end_tokens)8687 if drop_needle:88 self.stream.next()89 return result90
48 unmodified lines
139140 def parse_extends(self):141 node = nodes.Extends(lineno=self.stream.expect('extends').lineno)142 node.template = self.parse_expression()162 self.end_statement()143 return node144145 def parse_include(self):146 node = nodes.Include(lineno=self.stream.expect('include').lineno)
12 unmodified lines
159 node.template = self.parse_expression()160 else:161 node.target = None162 node.template = expr183 self.end_statement()163 return node164165 def parse_signature(self, node):166 node.args = args = []
50 unmodified lines
217 while self.stream.current.type not in statement_end_tokens:218 if node.nodes:219 self.stream.expect('comma')220 node.nodes.append(self.parse_expression())242 self.end_statement()221 return node222223 def parse_expression(self, no_condexpr=False):224 """Parse an expression."""
445 unmodified lines
modified:setup.py+1 added-1 removed
129 unmodified lines
130 Extension('jinja2._speedups', ['jinja2/_speedups.c'])131 ]132 )133 },134 extras_require={'i18n': ['Babel>=0.8']}134 extras_require={'i18n': ['Babel>=0.8']},135 entry_points="""136 [babel.extractors]137 jinja2 = jinja.i18n:babel_extract[i18n]138 """
1 unmodified line