Skip to content
Myr

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

4 files+8 added−70 removed

modified:docs/extensions.rst+5 added-1 removed
170 unmodified lines
171172 .. attribute:: filename173174 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`.178179 .. attribute:: name180181 The load name of the template.182183 .. attribute:: stream184185 The current :class:`~jinja2.lexer.TokenStream`186
41 unmodified lines
modified:jinja2/compiler.py-67 removed
105 unmodified lines
106107 # names that are declared by parameters108 self.declared_parameter = set()109110 # static subscribes111 self.static_subscribes = {}112110 def add_special(self, name):111 """Register a special name like `loop`."""112 self.undeclared.discard(name)113 self.declared.add(name)
34 unmodified lines
148149 # the name of the block we're in, otherwise None.150 self.block = parent and parent.block or None151155 # node overlays. see `CodeGenerator.overlay` for more details156 self.overlays = {}157152 # the parent of this frame153 self.parent = parent154155 if parent is not None:
99 unmodified lines
255 elif node.ctx == 'load' and not \256 self.identifiers.is_declared(node.name, self.hard_scope):257 self.identifiers.undeclared.add(node.name)258265 def visit_Subscript(self, node):266 """Under some circumstances subscripts are aliased with local names:267268 - 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] = 1285259 def visit_Macro(self, node):260 self.identifiers.declared_locally.add(node.name)261262 def visit_Import(self, node):
206 unmodified lines
469 touch_comma()470 self.write('**')471 self.visit(node.dyn_kwargs, frame)472500 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 True520473 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))477526 # 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)540478 def pull_dependencies(self, nodes):479 """Pull all the dependencies."""480 visitor = DependencyFinderVisitor()481 for node in nodes:
804 unmodified lines
1286 self.write(' %s ' % operators[node.op])1287 self.visit(node.expr, frame)12881289 def visit_Subscript(self, node, frame):1353 # subscripts can have overlays1354 if self.overlay(node, frame):1355 return13561290 # 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) and
89 unmodified lines
modified:jinja2/environment.py+3 added
295 unmodified lines
296297 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_error
25 unmodified lines
331 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 lines
modified:jinja2/parser.py-2 removed
23 unmodified lines
24 """2526 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 = False
722 unmodified lines