Exemplo n.º 1
0
    def _compile(self, name, tmplPath):
        if invalidate_caches:
            invalidate_caches()

        # @@ consider adding an ImportError raiser here
        code = str(Compiler(file=tmplPath, moduleName=name,
                            mainClassName=name))
        if _cacheDir:
            __file__ = os.path.join(
                _cacheDir[0], convertTmplPathToModuleName(tmplPath)) + '.py'
        else:
            __file__ = os.path.splitext(tmplPath)[0] + '.py'
        try:
            with open(__file__, 'w') as _py_file:
                _py_file.write(code)
        except (IOError, OSError):
            # @@ TR: need to add some error code here
            if self.debuglevel > 0:
                traceback.print_exc(file=sys.stderr)
            __file__ = tmplPath
        else:
            try:
                py_compile.compile(__file__)
            except IOError:
                pass
        co = compile(code + '\n', __file__, 'exec')

        mod = types.ModuleType(name)
        mod.__file__ = co.co_filename
        if _cacheDir:
            # @@TR: this is used in the WebKit filemonitoring code
            mod.__orig_file__ = tmplPath
        mod.__co__ = co
        return mod
Exemplo n.º 2
0
    def _compile(self, name, tmplPath):
        ## @@ consider adding an ImportError raiser here
        code = str(Compiler(file=tmplPath, moduleName=name, mainClassName=name))
        if _cacheDir:
            __file__ = os.path.join(_cacheDir[0], convertTmplPathToModuleName(tmplPath)) + ".py"
            try:
                open(__file__, "w").write(code)
            except OSError:
                ## @@ TR: need to add some error code here
                traceback.print_exc(file=sys.stderr)
                __file__ = tmplPath
        else:
            __file__ = tmplPath
        co = compile(code + "\n", __file__, "exec")

        mod = imp.new_module(name)
        mod.__file__ = co.co_filename
        if _cacheDir:
            mod.__orig_file__ = tmplPath  # @@TR: this is used in the WebKit
            # filemonitoring code
        mod.__co__ = co
        return mod
Exemplo n.º 3
0
    def _compile(self, name, tmplPath):
        ## @@ consider adding an ImportError raiser here
        code = str(Compiler(file=tmplPath, moduleName=name,
                            mainClassName=name))
        if _cacheDir:
            __file__ = os.path.join(
                _cacheDir[0], convertTmplPathToModuleName(tmplPath)) + '.py'
            try:
                open(__file__, 'w').write(code)
            except OSError:
                ## @@ TR: need to add some error code here
                traceback.print_exc(file=sys.stderr)
                __file__ = tmplPath
        else:
            __file__ = tmplPath
        co = compile(code + '\n', __file__, 'exec')

        mod = imp.new_module(name)
        mod.__file__ = co.co_filename
        if _cacheDir:
            mod.__orig_file__ = tmplPath  # @@TR: this is used in the WebKit
            # filemonitoring code
        mod.__co__ = co
        return mod