示例#1
0
 def __init__(self, text='', filename='', lookup=None):
     if filename: text = open(filename, 'r').read()
     self.source = text
     self.parser = TemplateParser(lookup)
     self.module_source = self.parser.translate(text, filename)
     self.module_id = "memory:" + hex(id(self))
     self.code = compile(self.module_source, self.module_id, 'exec')
     self.module = ModuleType(self.module_id)
示例#2
0
 def __init__(self, text='', filename='', lookup=None):
     if filename: text = open(filename, 'r').read()
     self.source = text
     self.parser = TemplateParser(lookup)
     self.module_source = self.parser.translate(text, filename)
     self.module_id = "memory:" + hex(id(self))
     self.code = compile(self.module_source, self.module_id, 'exec')
     self.module = ModuleType(self.module_id)
示例#3
0
class Template(object):
    def __init__(self, text='', filename='', lookup=None):
        if filename: text = open(filename, 'r').read()
        self.source = text
        self.parser = TemplateParser(lookup)
        self.module_source = self.parser.translate(text, filename)
        self.module_id = "memory:" + hex(id(self))
        self.code = compile(self.module_source, self.module_id, 'exec')
        self.module = ModuleType(self.module_id)

    def render(self, **kwargs):
        self.module.__dict__.update(kwargs)

        exec self.code in self.module.__dict__, self.module.__dict__

        self.module.out = TemplateOutput()
        self.module.body()
        return self.module.out.output
示例#4
0
class Template(object):
    
    def __init__(self, text='', filename='', lookup=None):
        if filename: text = open(filename, 'r').read()
        self.source = text
        self.parser = TemplateParser(lookup)
        self.module_source = self.parser.translate(text, filename)
        self.module_id = "memory:" + hex(id(self))
        self.code = compile(self.module_source, self.module_id, 'exec')
        self.module = ModuleType(self.module_id)
        
    def render(self, **kwargs):        
        self.module.__dict__.update(kwargs)
        
        exec self.code in self.module.__dict__, self.module.__dict__

        self.module.out = TemplateOutput()
        self.module.body()
        return self.module.out.output