removed attribute local aliasing again because that implementation was broken
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 7f15ef8 · Browse files · 4 files·+8 added−70 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+8 added−70 removed
- other:+8 added−70 removed
Provenance
- Commit
67fdddf- Tree
3f60c4e- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
7f15ef8
4 files changed+8 added−70 removed
modified:docs/extensions.rst+5 added-1 removed
170 unmodified lines171 172 .. attribute:: filename173 174 The filename of the template the parser processes. This is **not**175- the load name of the template which is unavailable at parsing time.175+ the load name of the template. For the load name see :attr:`name`.176 For templates that were not loaded form the file system this is177 `None`.178 179+ .. attribute:: name180+181+ The load name of the template.182+183 .. attribute:: stream184 185 The current :class:`~jinja2.lexer.TokenStream`186 41 unmodified linesmodified:jinja2/compiler.py-67 removed
105 unmodified lines106 107 # names that are declared by parameters108 self.declared_parameter = set()109 110- # static subscribes111- self.static_subscribes = {}112-110 def add_special(self, name):111 """Register a special name like `loop`."""112 self.undeclared.discard(name)113 self.declared.add(name)34 unmodified lines148 149 # the name of the block we're in, otherwise None.150 self.block = parent and parent.block or None151 155- # node overlays. see `CodeGenerator.overlay` for more details156- self.overlays = {}157-152 # the parent of this frame153 self.parent = parent154 155 if parent is not None:99 unmodified lines255 elif node.ctx == 'load' and not \256 self.identifiers.is_declared(node.name, self.hard_scope):257 self.identifiers.undeclared.add(node.name)258 265- def visit_Subscript(self, node):266- """Under some circumstances subscripts are aliased with local names:267-268- - the subscript node is either already aliased or a name that was not269- reassigned.270- - and the subscription argument is a constant string.271- """272- self.generic_visit(node)273- if isinstance(node.arg, nodes.Const) and \274- isinstance(node.arg.value, basestring) and \275- ((isinstance(node.node, nodes.Name) and276- # this code ignores parameter declared names as the may only277- # occour at the very beginning of a scope and we pull the278- # attributes afterwards.279- node.node.name not in (self.identifiers.declared_locally)) or280- node.node in self.identifiers.static_subscribes):281- if node in self.identifiers.static_subscribes:282- self.identifiers.static_subscribes[node] += 1283- else:284- self.identifiers.static_subscribes[node] = 1285-259 def visit_Macro(self, node):260 self.identifiers.declared_locally.add(node.name)261 262 def visit_Import(self, node):206 unmodified lines469 touch_comma()470 self.write('**')471 self.visit(node.dyn_kwargs, frame)472 500- def overlay(self, node, frame):501- """Visit an overlay and return `True` or `False` if the overlay502- does not exist or is exhausted. An overlay is used to replace a503- node with another one (or an identifier) N times. This is for504- example used to replace static subscribes before reassignments505- of a name that occour more than one time. If a node has overlays506- it's important that this method is called, otherwise the count507- will be out of sync and the generated code is broken.508- """509- if node not in frame.overlays:510- return False511- overlay, count = frame.overlays[node]512- if count is not None and count <= 0:513- return False514- if isinstance(overlay, basestring):515- self.write(overlay)516- else:517- self.visit(overlay, frame)518- frame.overlays[node] = (overlay, count - 1)519- return True520-473 def pull_locals(self, frame):474 """Pull all the references identifiers into the local scope."""475 for name in frame.identifiers.undeclared:476 self.writeline('l_%s = context.resolve(%r)' % (name, name))477 526- # find all the static subscribes with a count > 2 and527- # order them properly so that subscribes depending on other528- # subscribes are handled later.529- static_subscribes = [(node, count) for node, count in530- frame.identifiers.static_subscribes.items() if531- count >= 2]532- if static_subscribes:533- static_subscribes.sort(key=lambda x: type(x[0].node)534- is nodes.Subscript)535- for node, count in static_subscribes:536- ident = self.temporary_identifier()537- self.writeline(ident + ' = ', node)538- self.visit(node, frame)539- frame.overlays[node] = (ident, count)540-478 def pull_dependencies(self, nodes):479 """Pull all the dependencies."""480 visitor = DependencyFinderVisitor()481 for node in nodes:804 unmodified lines1286 self.write(' %s ' % operators[node.op])1287 self.visit(node.expr, frame)1288 1289 def visit_Subscript(self, node, frame):1353- # subscripts can have overlays1354- if self.overlay(node, frame):1355- return1356-1290 # slices or integer subscriptions bypass the subscribe1291 # method if we can determine that at compile time.1292 if isinstance(node.arg, nodes.Slice) or \1293 (isinstance(node.arg, nodes.Const) and89 unmodified linesmodified:jinja2/environment.py+3 added
295 unmodified lines296 297 If you are :ref:`developing Jinja2 extensions <writing-extensions>`298 this gives you a good overview of the node tree generated.299 """300+ if isinstance(filename, unicode):301+ filename = filename.encode('utf-8')302 try:303 return Parser(self, source, name, filename).parse()304 except TemplateSyntaxError, e:305 from jinja2.debug import translate_syntax_error25 unmodified lines331 source = self.parse(source, name, filename)332 if self.optimized:333 node = optimize(source, self)334 source = generate(node, self, name, filename)335+ #print source336 if raw:337 return source338 if filename is None:339 filename = '<template>'338 unmodified linesmodified:jinja2/parser.py-2 removed
23 unmodified lines24 """25 26 def __init__(self, environment, source, name=None, filename=None):27 self.environment = environment28- if isinstance(filename, unicode):29- filename = filename.encode('utf-8')28 self.source = unicode(source)29 self.name = name30 self.filename = filename31 self.closed = False722 unmodified lines