def init_context(self, outspace): self.fromspace(outspace) for node in self.contexts: node.globalspace = self.space self.node[node.name] = Space(node.activate()) self.space += self.node[node.name]
def __init__(self, nodelist=[], init_space={}): self.node = {} #OrderedDict() self.nodelist = OrderedDict() self.space = Space(init_space) for node in nodelist: node.globalspace = self.space self.nodelist[node.name] = node
class ContextHandler(NodeHandler): __desc__ = "Context" @staticmethod def make(node): value = {} codetext = node.text.strip().replace('\r\n', '\n') #codetext = '#coding=utf-8\n' + node.text.strip().replace('\r\n', '\n') try: exec codetext in node.globalspace.__dict__.copy(), value except Exception, err: import traceback traceback.print_exc() raise NodeError, "Fail in Activating %s, err info: %s " % (node, err) return Space(value)
def test_emptytemplate(): text = " " node = Node('test', text, NodeHandlers.Template) node.globalspace = Space(dict(name='EK')) print repr(node.activate()) print node.globalspace
def test_templatenode(): text = "HELLO, $name" node = Node('test', text, NodeHandlers.Template) node.globalspace = Space(dict(name='EK')) print node.activate() print node.globalspace
def test_contextnode(): text = "print 'test_contextnode'\na = 114\nb = {}\n" node = Node('test', text, NodeHandlers.Context) node.globalspace = Space() print node.activate() print node.globalspace
def tospace(self): return Space((node.name, node.value) for node in self)