Ejemplo n.º 1
0
    def createAndCompile(self, source):
        sourcefile = '-'
        while sourcefile.find('-') != -1:
            sourcefile = tempfile.mktemp()

        if PY2:
            fd = open('%s.tmpl' % sourcefile, 'w')
        else:
            fd = open('%s.tmpl' % sourcefile, 'w', encoding='utf-8')
        fd.write(source)
        fd.close()

        wrap = CheetahWrapper.CheetahWrapper()
        wrap.main([
            'cheetah', 'compile', '--encoding=utf-8',
            '--settings=encoding="utf-8"', '--quiet', '--nobackup', sourcefile
        ])
        module_path, module_name = os.path.split(sourcefile)
        module = loadModule(module_name, [module_path])
        template = getattr(module, module_name)
        os.remove('%s.tmpl' % sourcefile)
        for sourcefile_py in glob('%s.py*' % sourcefile):  # *.py[co]
            os.remove(sourcefile_py)
        __pycache__ = os.path.join(os.path.dirname(sourcefile), '__pycache__')
        if os.path.exists(__pycache__):  # PY3
            rmtree(__pycache__)
        return template
Ejemplo n.º 2
0
    def createAndCompile(self, source):
        sourcefile = '-'
        while sourcefile.find('-') != -1:
            sourcefile = tempfile.mktemp()
        
        fd = open('%s.tmpl' % sourcefile, 'w')
        fd.write(source)
        fd.close()

        wrap = CheetahWrapper.CheetahWrapper()
        wrap.main(['cheetah', 'compile', '--nobackup', sourcefile])
        module_name = os.path.basename(sourcefile)
        module = loadModule(module_name, ['/tmp'])
        template = getattr(module, module_name)
        return template
Ejemplo n.º 3
0
    def createAndCompile(self, source):
        sourcefile = '-'
        while sourcefile.find('-') != -1:
            sourcefile = tempfile.mktemp()

        with (open('%s.tmpl' % sourcefile, 'w') if PY2 else open(
                '%s.tmpl' % sourcefile, 'w', encoding='utf-8')) as fd:
            fd.write(source)

        wrap = CheetahWrapper.CheetahWrapper()
        wrap.main([
            'cheetah', 'compile', '--encoding=utf-8',
            '--settings=encoding="utf-8"', '--quiet', '--nobackup', sourcefile
        ])
        module_path, module_name = os.path.split(sourcefile)
        module = loadModule(module_name, [module_path])
        template = getattr(module, module_name)
        return template