| 1416 | self.write(ref) |
| 1417 | |
| 1418 | def visit_NSRef(self, node, frame): |
| 1419 | # NSRefs can only be used to store values; since they use the normal |
| 1420 | # `foo.bar` notation they will be parsed as a normal attribute access |
| 1421 | # when used anywhere but in a `set` context |
| 1422 | ref = frame.symbols.ref(node.name) |
| 1423 | self.writeline('if not isinstance(%s, Namespace):' % ref) |
| 1424 | self.indent() |
| 1425 | self.writeline('raise TemplateRuntimeError(%r)' % |
| 1426 | 'cannot assign attribute on non-namespace object') |
| 1427 | self.outdent() |
| 1428 | self.writeline('%s[%r]' % (ref, node.attr)) |
| 1429 | |
| 1430 | def visit_Const(self, node, frame): |
| 1431 | val = node.as_const(frame.eval_ctx) |