Skip to content
Myr

Don't allow setting real attributes on ns objects

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

https://github.com/pallets/jinja/pull/684#issuecomment-291958060

authored by Adrian Moennich · committed by Adrian Moennich · parent cc1d287 · Browse files · 2 files+14 added−3 removed
This commit

State

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

Trailers

  • https: //github.com/pallets/jinja/pull/684#issuecomment-291958060

Diff stats

2 files+14 added−3 removed

  • other:+14 added−3 removed

2 files+14 added−3 removed

modified:jinja2/compiler.py+1 added-1 removed
1411 unmodified lines
1412 self.indent()1413 self.writeline('raise TemplateRuntimeError(%r)' %1414 'cannot assign attribute on non-namespace object')1415 self.outdent()1416 self.writeline('%s.%s' % (ref, node.attr))1416 self.writeline('%s[%r]' % (ref, node.attr))14171418 def visit_Const(self, node, frame):1419 val = node.as_const(frame.eval_ctx)1420 if isinstance(val, float):
289 unmodified lines
modified:jinja2/utils.py+13 added-2 removed
616 unmodified lines
617 initialized from a dictionary or with keyword argments."""618619 def __init__(*args, **kwargs):620 self, args = args[0], args[1:]621 self.__dict__.update(dict(*args, **kwargs))621 self.__attrs = dict(*args, **kwargs)622623 def __getattribute__(self, name):624 if name == '_Namespace__attrs':625 return object.__getattribute__(self, name)626 try:627 return self.__attrs[name]628 except KeyError:629 raise AttributeError(name)630631 def __setitem__(self, name, value):632 self.__attrs[name] = value633634 def __repr__(self):624 return '<Namespace %r>' % self.__dict__635 return '<Namespace %r>' % self.__attrs636637638# does this python version support async for in and async generators?639try:
8 unmodified lines