self.writeline('raise TemplateRuntimeError(%r)' %
'cannot assign attribute on non-namespace object')
self.outdent()
- self.writeline('%s.%s' % (ref, node.attr))
+ self.writeline('%s[%r]' % (ref, node.attr))
def visit_Const(self, node, frame):
val = node.as_const(frame.eval_ctx)
def __init__(*args, **kwargs):
self, args = args[0], args[1:]
- self.__dict__.update(dict(*args, **kwargs))
+ self.__attrs = dict(*args, **kwargs)
+
+ def __getattribute__(self, name):
+ if name == '_Namespace__attrs':
+ return object.__getattribute__(self, name)
+ try:
+ return self.__attrs[name]
+ except KeyError:
+ raise AttributeError(name)
+
+ def __setitem__(self, name, value):
+ self.__attrs[name] = value
def __repr__(self):
- return '<Namespace %r>' % self.__dict__
+ return '<Namespace %r>' % self.__attrs
# does this python version support async for in and async generators?