当前位置: 首页>>代码示例>>Python>>正文


Python codegen.compile方法代码示例

本文整理汇总了Python中mako.codegen.compile方法的典型用法代码示例。如果您正苦于以下问题:Python codegen.compile方法的具体用法?Python codegen.compile怎么用?Python codegen.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mako.codegen的用法示例。


在下文中一共展示了codegen.compile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _compile

# 需要导入模块: from mako import codegen [as 别名]
# 或者: from mako.codegen import compile [as 别名]
def _compile(template, text, filename, generate_magic_comment):
    lexer = template.lexer_cls(
        text,
        filename,
        disable_unicode=template.disable_unicode,
        input_encoding=template.input_encoding,
        preprocessor=template.preprocessor,
    )
    node = lexer.parse()
    source = codegen.compile(
        node,
        template.uri,
        filename,
        default_filters=template.default_filters,
        buffer_filters=template.buffer_filters,
        imports=template.imports,
        future_imports=template.future_imports,
        source_encoding=lexer.encoding,
        generate_magic_comment=generate_magic_comment,
        disable_unicode=template.disable_unicode,
        strict_undefined=template.strict_undefined,
        enable_loop=template.enable_loop,
        reserved_names=template.reserved_names,
    )
    return source, lexer 
开发者ID:remg427,项目名称:misp42splunk,代码行数:27,代码来源:template.py

示例2: _compile_text

# 需要导入模块: from mako import codegen [as 别名]
# 或者: from mako.codegen import compile [as 别名]
def _compile_text(template, text, filename):
    identifier = template.module_id
    source, lexer = _compile(
        template,
        text,
        filename,
        generate_magic_comment=template.disable_unicode,
    )

    cid = identifier
    if not compat.py3k and isinstance(cid, compat.text_type):
        cid = cid.encode()
    module = types.ModuleType(cid)
    code = compile(source, cid, "exec")

    # this exec() works for 2.4->3.3.
    exec(code, module.__dict__, module.__dict__)
    return (source, module) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:20,代码来源:template.py

示例3: _compile

# 需要导入模块: from mako import codegen [as 别名]
# 或者: from mako.codegen import compile [as 别名]
def _compile(template, text, filename, generate_magic_comment):
    lexer = template.lexer_cls(text,
                               filename,
                               disable_unicode=template.disable_unicode,
                               input_encoding=template.input_encoding,
                               preprocessor=template.preprocessor)
    node = lexer.parse()
    source = codegen.compile(node,
                             template.uri,
                             filename,
                             default_filters=template.default_filters,
                             buffer_filters=template.buffer_filters,
                             imports=template.imports,
                             future_imports=template.future_imports,
                             source_encoding=lexer.encoding,
                             generate_magic_comment=generate_magic_comment,
                             disable_unicode=template.disable_unicode,
                             strict_undefined=template.strict_undefined,
                             enable_loop=template.enable_loop,
                             reserved_names=template.reserved_names)
    return source, lexer 
开发者ID:jpush,项目名称:jbox,代码行数:23,代码来源:template.py

示例4: _compile

# 需要导入模块: from mako import codegen [as 别名]
# 或者: from mako.codegen import compile [as 别名]
def _compile(template, text, filename, generate_magic_comment):
    lexer = template.lexer_cls(text,
                           filename,
                           disable_unicode=template.disable_unicode,
                           input_encoding=template.input_encoding,
                           preprocessor=template.preprocessor)
    node = lexer.parse()
    source = codegen.compile(node,
                            template.uri,
                            filename,
                            default_filters=template.default_filters,
                            buffer_filters=template.buffer_filters,
                            imports=template.imports,
                            future_imports=template.future_imports,
                            source_encoding=lexer.encoding,
                            generate_magic_comment=generate_magic_comment,
                            disable_unicode=template.disable_unicode,
                            strict_undefined=template.strict_undefined,
                            enable_loop=template.enable_loop,
                            reserved_names=template.reserved_names)
    return source, lexer 
开发者ID:fboender,项目名称:ansible-cmdb,代码行数:23,代码来源:template.py

示例5: _compile_from_file

# 需要导入模块: from mako import codegen [as 别名]
# 或者: from mako.codegen import compile [as 别名]
def _compile_from_file(self, path, filename):
        if path is not None:
            util.verify_directory(os.path.dirname(path))
            filemtime = os.stat(filename)[stat.ST_MTIME]
            if (
                not os.path.exists(path)
                or os.stat(path)[stat.ST_MTIME] < filemtime
            ):
                data = util.read_file(filename)
                _compile_module_file(
                    self, data, filename, path, self.module_writer
                )
            module = compat.load_module(self.module_id, path)
            del sys.modules[self.module_id]
            if module._magic_number != codegen.MAGIC_NUMBER:
                data = util.read_file(filename)
                _compile_module_file(
                    self, data, filename, path, self.module_writer
                )
                module = compat.load_module(self.module_id, path)
                del sys.modules[self.module_id]
            ModuleInfo(module, path, self, filename, None, None, None)
        else:
            # template filename and no module directory, compile code
            # in memory
            data = util.read_file(filename)
            code, module = _compile_text(self, data, filename)
            self._source = None
            self._code = code
            ModuleInfo(module, None, self, filename, code, None, None)
        return module 
开发者ID:remg427,项目名称:misp42splunk,代码行数:33,代码来源:template.py

示例6: _compile_from_file

# 需要导入模块: from mako import codegen [as 别名]
# 或者: from mako.codegen import compile [as 别名]
def _compile_from_file(self, path, filename):
        if path is not None:
            util.verify_directory(os.path.dirname(path))
            filemtime = os.stat(filename)[stat.ST_MTIME]
            if not os.path.exists(path) or \
                    os.stat(path)[stat.ST_MTIME] < filemtime:
                data = util.read_file(filename)
                _compile_module_file(
                    self,
                    data,
                    filename,
                    path,
                    self.module_writer)
            module = compat.load_module(self.module_id, path)
            del sys.modules[self.module_id]
            if module._magic_number != codegen.MAGIC_NUMBER:
                data = util.read_file(filename)
                _compile_module_file(
                    self,
                    data,
                    filename,
                    path,
                    self.module_writer)
                module = compat.load_module(self.module_id, path)
                del sys.modules[self.module_id]
            ModuleInfo(module, path, self, filename, None, None)
        else:
            # template filename and no module directory, compile code
            # in memory
            data = util.read_file(filename)
            code, module = _compile_text(
                self,
                data,
                filename)
            self._source = None
            self._code = code
            ModuleInfo(module, None, self, filename, code, None)
        return module 
开发者ID:jpush,项目名称:jbox,代码行数:40,代码来源:template.py

示例7: _compile_text

# 需要导入模块: from mako import codegen [as 别名]
# 或者: from mako.codegen import compile [as 别名]
def _compile_text(template, text, filename):
    identifier = template.module_id
    source, lexer = _compile(template, text, filename,
                             generate_magic_comment=template.disable_unicode)

    cid = identifier
    if not compat.py3k and isinstance(cid, compat.text_type):
        cid = cid.encode()
    module = types.ModuleType(cid)
    code = compile(source, cid, 'exec')

    # this exec() works for 2.4->3.3.
    exec(code, module.__dict__, module.__dict__)
    return (source, module) 
开发者ID:jpush,项目名称:jbox,代码行数:16,代码来源:template.py

示例8: _compile_from_file

# 需要导入模块: from mako import codegen [as 别名]
# 或者: from mako.codegen import compile [as 别名]
def _compile_from_file(self, path, filename):
        if path is not None:
            util.verify_directory(os.path.dirname(path))
            filemtime = os.stat(filename)[stat.ST_MTIME]
            if not os.path.exists(path) or \
                        os.stat(path)[stat.ST_MTIME] < filemtime:
                data = util.read_file(filename)
                _compile_module_file(
                            self,
                            data,
                            filename,
                            path,
                            self.module_writer)
            module = compat.load_module(self.module_id, path)
            del sys.modules[self.module_id]
            if module._magic_number != codegen.MAGIC_NUMBER:
                data = util.read_file(filename)
                _compile_module_file(
                            self,
                            data,
                            filename,
                            path,
                            self.module_writer)
                module = compat.load_module(self.module_id, path)
                del sys.modules[self.module_id]
            ModuleInfo(module, path, self, filename, None, None)
        else:
            # template filename and no module directory, compile code
            # in memory
            data = util.read_file(filename)
            code, module = _compile_text(
                                self,
                                data,
                                filename)
            self._source = None
            self._code = code
            ModuleInfo(module, None, self, filename, code, None)
        return module 
开发者ID:fboender,项目名称:ansible-cmdb,代码行数:40,代码来源:template.py

示例9: _compile_text

# 需要导入模块: from mako import codegen [as 别名]
# 或者: from mako.codegen import compile [as 别名]
def _compile_text(template, text, filename):
    identifier = template.module_id
    source, lexer = _compile(template, text, filename,
                        generate_magic_comment=template.disable_unicode)

    cid = identifier
    if not compat.py3k and isinstance(cid, compat.text_type):
        cid = cid.encode()
    module = types.ModuleType(cid)
    code = compile(source, cid, 'exec')

    # this exec() works for 2.4->3.3.
    exec(code, module.__dict__, module.__dict__)
    return (source, module) 
开发者ID:fboender,项目名称:ansible-cmdb,代码行数:16,代码来源:template.py


注:本文中的mako.codegen.compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。