Ejemplo n.º 1
0
    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]
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
 def test_emptytemplate():
     text = " "
     node = Node('test', text, NodeHandlers.Template)
     node.globalspace = Space(dict(name='EK'))
     print repr(node.activate())
     print node.globalspace
Ejemplo n.º 5
0
 def test_templatenode():
     text = "HELLO, $name"
     node = Node('test', text, NodeHandlers.Template)
     node.globalspace = Space(dict(name='EK'))
     print node.activate()
     print node.globalspace
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 def tospace(self):
     return Space((node.name, node.value) for node in self)