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


Python Template.render_unicode方法代码示例

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


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

示例1: test_html_error_template

# 需要导入模块: from choco.template import Template [as 别名]
# 或者: from choco.template.Template import render_unicode [as 别名]
    def test_html_error_template(self):
        """test the html_error_template"""
        code = """
% i = 0
"""
        try:
            template = Template(code)
            template.render_unicode()
            assert False
        except errors.CompileException:
            html_error = errors.html_error_template().render_unicode()
            assert ("CompileException: Fragment 'i = 0' is not "
                    "a partial control statement at line: 2 char: 1") in html_error
            assert '<style>' in html_error
            html_error_stripped = html_error.strip()
            assert html_error_stripped.startswith('<html>')
            assert html_error_stripped.endswith('</html>')

            not_full = errors.html_error_template().\
                                    render_unicode(full=False)
            assert '<html>' not in not_full
            assert '<style>' in not_full

            no_css = errors.html_error_template().\
                                    render_unicode(css=False)
            assert '<style>' not in no_css
        else:
            assert False, ("This function should trigger a CompileException, "
                           "but didn't")
开发者ID:whiteclover,项目名称:Choco,代码行数:31,代码来源:test_exceptions.py

示例2: _do_test_traceback

# 需要导入模块: from choco.template import Template [as 别名]
# 或者: from choco.template.Template import render_unicode [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 = errors.RichTraceback()
         if utf8:
             assert tback.source == source.decode('utf-8')
         else:
             assert tback.source == source
开发者ID:whiteclover,项目名称:Choco,代码行数:35,代码来源:test_template.py

示例3: test_text_error_template

# 需要导入模块: from choco.template import Template [as 别名]
# 或者: from choco.template.Template import render_unicode [as 别名]
    def test_text_error_template(self):
        code = """
% i = 0
"""
        try:
            template = Template(code)
            template.render_unicode()
            assert False
        except errors.CompileException:
            text_error = errors.text_error_template().render_unicode()
            assert 'Traceback (most recent call last):' in text_error
            assert ("CompileException: Fragment 'i = 0' is not a partial "
                    "control statement") in text_error
开发者ID:whiteclover,项目名称:Choco,代码行数:15,代码来源:test_exceptions.py

示例4: test_encode_filter_non_str

# 需要导入模块: from choco.template import Template [as 别名]
# 或者: from choco.template.Template import render_unicode [as 别名]
 def test_encode_filter_non_str(self):
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """, default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=3).strip(),
         u("some stuff.... 3")
     )
开发者ID:whiteclover,项目名称:Choco,代码行数:10,代码来源:test_filters.py

示例5: test_encode_filter

# 需要导入模块: from choco.template import Template [as 别名]
# 或者: from choco.template.Template import render_unicode [as 别名]
 def test_encode_filter(self):
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """, default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=u("voix m’a réveillé")).strip(),
         u("some stuff.... voix m’a réveillé")
     )
开发者ID:whiteclover,项目名称:Choco,代码行数:10,代码来源:test_filters.py

示例6: test_utf8_html_error_template_pygments

# 需要导入模块: from choco.template import Template [as 别名]
# 或者: from choco.template.Template import render_unicode [as 别名]
    def test_utf8_html_error_template_pygments(self):
        """test the html_error_template with a Template containing UTF-8
        chars"""

        if compat.py3k:
            code = """# -*- coding: utf-8 -*-
% if 2 == 2: /an error
${'привет'}
% endif
"""
        else:
            code = """# -*- coding: utf-8 -*-
% if 2 == 2: /an error
${u'привет'}
% endif
"""
        try:
            template = Template(code)
            template.render_unicode()
        except errors.CompileException:
            html_error = errors.html_error_template().render()
            if compat.py3k:
                assert ("CompileException: Fragment &#39;if 2 == 2: /an "
                    "error&#39; is not a partial control statement "
                    "at line: 2 char: 1").encode(sys.getdefaultencoding(), 'htmlentityreplace') in \
                    html_error
            else:
                assert ("CompileException: Fragment &#39;if 2 == 2: /an "
                        "error&#39; is not a partial control statement "
                        "at line: 2 char: 1") in \
                        html_error

            if compat.py3k:
                assert "".encode(sys.getdefaultencoding(),
                                        'htmlentityreplace') in html_error
            else:
                assert 'u&#39;'\
                        '&#x43F;&#x440;&#x438;&#x432;&#x435;&#x442;'\
                        '&#39;</span><span class="cp">}</span>'.encode(
                                sys.getdefaultencoding(),
                                'htmlentityreplace') in html_error
        else:
            assert False, ("This function should trigger a CompileException, "
                           "but didn't")
开发者ID:whiteclover,项目名称:Choco,代码行数:46,代码来源:test_exceptions.py

示例7: test_encode_filter_non_str_we_return_bytes

# 需要导入模块: from choco.template import Template [as 别名]
# 或者: from choco.template.Template import render_unicode [as 别名]
 def test_encode_filter_non_str_we_return_bytes(self):
     class Foo(object):
         def __str__(self):
             return compat.b("å")
     t = Template("""# coding: utf-8
         some stuff.... ${x}
     """, default_filters=['decode.utf8'])
     eq_(
         t.render_unicode(x=Foo()).strip(),
         u("some stuff.... å")
     )
开发者ID:whiteclover,项目名称:Choco,代码行数:13,代码来源:test_filters.py


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