Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: third_party/jinja2/meta.py

Issue 23506004: Update Jinja2 (Python template library) to 2.7.1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/jinja2/loaders.py ('k') | third_party/jinja2/nodes.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 """ 2 """
3 jinja2.meta 3 jinja2.meta
4 ~~~~~~~~~~~ 4 ~~~~~~~~~~~
5 5
6 This module implements various functions that exposes information about 6 This module implements various functions that exposes information about
7 templates that might be interesting for various kinds of applications. 7 templates that might be interesting for various kinds of applications.
8 8
9 :copyright: (c) 2010 by the Jinja Team, see AUTHORS for more details. 9 :copyright: (c) 2010 by the Jinja Team, see AUTHORS for more details.
10 :license: BSD, see LICENSE for more details. 10 :license: BSD, see LICENSE for more details.
11 """ 11 """
12 from jinja2 import nodes 12 from jinja2 import nodes
13 from jinja2.compiler import CodeGenerator 13 from jinja2.compiler import CodeGenerator
14 from jinja2._compat import string_types
14 15
15 16
16 class TrackingCodeGenerator(CodeGenerator): 17 class TrackingCodeGenerator(CodeGenerator):
17 """We abuse the code generator for introspection.""" 18 """We abuse the code generator for introspection."""
18 19
19 def __init__(self, environment): 20 def __init__(self, environment):
20 CodeGenerator.__init__(self, environment, '<introspection>', 21 CodeGenerator.__init__(self, environment, '<introspection>',
21 '<introspection>') 22 '<introspection>')
22 self.undeclared_identifiers = set() 23 self.undeclared_identifiers = set()
23 24
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 """ 71 """
71 for node in ast.find_all((nodes.Extends, nodes.FromImport, nodes.Import, 72 for node in ast.find_all((nodes.Extends, nodes.FromImport, nodes.Import,
72 nodes.Include)): 73 nodes.Include)):
73 if not isinstance(node.template, nodes.Const): 74 if not isinstance(node.template, nodes.Const):
74 # a tuple with some non consts in there 75 # a tuple with some non consts in there
75 if isinstance(node.template, (nodes.Tuple, nodes.List)): 76 if isinstance(node.template, (nodes.Tuple, nodes.List)):
76 for template_name in node.template.items: 77 for template_name in node.template.items:
77 # something const, only yield the strings and ignore 78 # something const, only yield the strings and ignore
78 # non-string consts that really just make no sense 79 # non-string consts that really just make no sense
79 if isinstance(template_name, nodes.Const): 80 if isinstance(template_name, nodes.Const):
80 if isinstance(template_name.value, basestring): 81 if isinstance(template_name.value, string_types):
81 yield template_name.value 82 yield template_name.value
82 # something dynamic in there 83 # something dynamic in there
83 else: 84 else:
84 yield None 85 yield None
85 # something dynamic we don't know about here 86 # something dynamic we don't know about here
86 else: 87 else:
87 yield None 88 yield None
88 continue 89 continue
89 # constant is a basestring, direct template name 90 # constant is a basestring, direct template name
90 if isinstance(node.template.value, basestring): 91 if isinstance(node.template.value, string_types):
91 yield node.template.value 92 yield node.template.value
92 # a tuple or list (latter *should* not happen) made of consts, 93 # a tuple or list (latter *should* not happen) made of consts,
93 # yield the consts that are strings. We could warn here for 94 # yield the consts that are strings. We could warn here for
94 # non string values 95 # non string values
95 elif isinstance(node, nodes.Include) and \ 96 elif isinstance(node, nodes.Include) and \
96 isinstance(node.template.value, (tuple, list)): 97 isinstance(node.template.value, (tuple, list)):
97 for template_name in node.template.value: 98 for template_name in node.template.value:
98 if isinstance(template_name, basestring): 99 if isinstance(template_name, string_types):
99 yield template_name 100 yield template_name
100 # something else we don't care about, we could warn here 101 # something else we don't care about, we could warn here
101 else: 102 else:
102 yield None 103 yield None
OLDNEW
« no previous file with comments | « third_party/jinja2/loaders.py ('k') | third_party/jinja2/nodes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698