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


Python util.read_file方法代码示例

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


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

示例1: source

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [as 别名]
def source(self):
        if self.template_source is not None:
            if self.module._source_encoding and not isinstance(
                self.template_source, compat.text_type
            ):
                return self.template_source.decode(
                    self.module._source_encoding
                )
            else:
                return self.template_source
        else:
            data = util.read_file(self.template_filename)
            if self.module._source_encoding:
                return data.decode(self.module._source_encoding)
            else:
                return data 
开发者ID:remg427,项目名称:misp42splunk,代码行数:18,代码来源:template.py

示例2: test_unicode_literal_in_tag

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [as 别名]
def test_unicode_literal_in_tag(self):
        self._do_file_test(
            "unicode_arguments.html",
            [
                u("x is: drôle de petite voix m’a réveillé"),
                u("x is: drôle de petite voix m’a réveillé"),
                u("x is: drôle de petite voix m’a réveillé"),
                u("x is: drôle de petite voix m’a réveillé"),
            ],
            filters=result_lines,
        )

        self._do_memory_test(
            util.read_file(self._file_path("unicode_arguments.html")),
            [
                u("x is: drôle de petite voix m’a réveillé"),
                u("x is: drôle de petite voix m’a réveillé"),
                u("x is: drôle de petite voix m’a réveillé"),
                u("x is: drôle de petite voix m’a réveillé"),
            ],
            filters=result_lines,
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:24,代码来源:test_template.py

示例3: test_unicode_literal_in_tag

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [as 别名]
def test_unicode_literal_in_tag(self):
        self._do_file_test(
            "unicode_arguments.html",
            [
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
            ],
            filters=result_lines
        )

        self._do_memory_test(
            util.read_file(self._file_path("unicode_arguments.html")),
            [
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
                u('x is: drôle de petite voix m’a réveillé'),
            ],
            filters=result_lines
        ) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:24,代码来源:test_template.py

示例4: _compile_from_file

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [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

示例5: _compile_from_file

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [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

示例6: source

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [as 别名]
def source(self):
        if self.template_source is not None:
            if self.module._source_encoding and \
                    not isinstance(self.template_source, compat.text_type):
                return self.template_source.decode(
                    self.module._source_encoding)
            else:
                return self.template_source
        else:
            data = util.read_file(self.template_filename)
            if self.module._source_encoding:
                return data.decode(self.module._source_encoding)
            else:
                return data 
开发者ID:jpush,项目名称:jbox,代码行数:16,代码来源:template.py

示例7: test_read_file

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [as 别名]
def test_read_file(self):
        fn = os.path.join(os.path.dirname(__file__), "test_util.py")
        data = util.read_file(fn, "rb")
        assert "test_util" in str(data)  # str() for py3k 
开发者ID:sqlalchemy,项目名称:mako,代码行数:6,代码来源:test_util.py

示例8: test_read_file

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [as 别名]
def test_read_file(self):
        fn = os.path.join(os.path.dirname(__file__), 'test_util.py')
        data = util.read_file(fn, 'rb')
        assert 'test_util' in str(data)  # str() for py3k 
开发者ID:jhpyle,项目名称:docassemble,代码行数:6,代码来源:test_util.py

示例9: test_crlf

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [as 别名]
def test_crlf(self):
        template = util.read_file(self._file_path("crlf.html"))
        nodes = Lexer(template).parse()
        self._compare(
            nodes,
            TemplateNode({}, [
                Text('<html>\r\n\r\n', (1, 1)),
                PageTag('page', {
                            'args': "a=['foo',\n                'bar']"
                        }, (3, 1), []),
                Text('\r\n\r\nlike the name says.\r\n\r\n', (4, 26)),
                ControlLine('for', 'for x in [1,2,3]:', False, (8, 1)),
                Text('        ', (9, 1)),
                Expression('x', [], (9, 9)),
                ControlLine('for', 'endfor', True, (10, 1)),
                Text('\r\n', (11, 1)),
                Expression("trumpeter == 'Miles' and "
                                "trumpeter or \\\n      'Dizzy'",
                                [], (12, 1)),
                Text('\r\n\r\n', (13, 15)),
                DefTag('def', {'name': 'hi()'}, (15, 1), [
                    Text('\r\n    hi!\r\n', (15, 19))]),
                    Text('\r\n\r\n</html>\r\n', (17, 8))
                ])
        )
        assert flatten_result(Template(template).render()) \
            == """<html> like the name says. 1 2 3 Dizzy </html>""" 
开发者ID:jhpyle,项目名称:docassemble,代码行数:29,代码来源:test_lexer.py

示例10: _do_test_traceback

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [as 别名]
def _do_test_traceback(self, utf8, memory, syntax):
        if memory:
            if syntax:
                source = u('## coding: utf-8\n<% print "m’a réveillé. '\
                        'Elle disait: « S’il vous plaît… dessine-moi un mouton! » %>')
            else:
                source = u('## coding: utf-8\n<% print u"m’a réveillé. '\
                        'Elle disait: « S’il vous plaît… dessine-moi un mouton! »" + str(5/0) %>')
            if utf8:
                source = source.encode('utf-8')
            else:
                source = source
            templateargs = {'text': source}
        else:
            if syntax:
                filename = 'unicode_syntax_error.html'
            else:
                filename = 'unicode_runtime_error.html'
            source = util.read_file(self._file_path(filename), 'rb')
            if not utf8:
                source = source.decode('utf-8')
            templateargs = {'filename': self._file_path(filename)}
        try:
            template = Template(**templateargs)
            if not syntax:
                template.render_unicode()
            assert False
        except Exception:
            tback = exceptions.RichTraceback()
            if utf8:
                assert tback.source == source.decode('utf-8')
            else:
                assert tback.source == source 
开发者ID:jhpyle,项目名称:docassemble,代码行数:35,代码来源:test_template.py

示例11: _compile_from_file

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [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

示例12: source

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [as 别名]
def source(self):
        if self.template_source is not None:
            if self.module._source_encoding and \
                    not isinstance(self.template_source, compat.text_type):
                return self.template_source.decode(
                                self.module._source_encoding)
            else:
                return self.template_source
        else:
            data = util.read_file(self.template_filename)
            if self.module._source_encoding:
                return data.decode(self.module._source_encoding)
            else:
                return data 
开发者ID:fboender,项目名称:ansible-cmdb,代码行数:16,代码来源:template.py

示例13: test_crlf

# 需要导入模块: from mako import util [as 别名]
# 或者: from mako.util import read_file [as 别名]
def test_crlf(self):
        template = util.read_file(self._file_path("crlf.html"))
        nodes = Lexer(template).parse()
        self._compare(
            nodes,
            TemplateNode(
                {},
                [
                    Text("<html>\r\n\r\n", (1, 1)),
                    PageTag(
                        "page",
                        {"args": "a=['foo',\n                'bar']"},
                        (3, 1),
                        [],
                    ),
                    Text("\r\n\r\nlike the name says.\r\n\r\n", (4, 26)),
                    ControlLine("for", "for x in [1,2,3]:", False, (8, 1)),
                    Text("        ", (9, 1)),
                    Expression("x", [], (9, 9)),
                    ControlLine("for", "endfor", True, (10, 1)),
                    Text("\r\n", (11, 1)),
                    Expression(
                        "trumpeter == 'Miles' and "
                        "trumpeter or \\\n      'Dizzy'",
                        [],
                        (12, 1),
                    ),
                    Text("\r\n\r\n", (13, 15)),
                    DefTag(
                        "def",
                        {"name": "hi()"},
                        (15, 1),
                        [Text("\r\n    hi!\r\n", (15, 19))],
                    ),
                    Text("\r\n\r\n</html>\r\n", (17, 8)),
                ],
            ),
        )
        assert (
            flatten_result(Template(template).render())
            == """<html> like the name says. 1 2 3 Dizzy </html>"""
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:44,代码来源:test_lexer.py


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