當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。