本文整理汇总了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")
示例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
示例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
示例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")
)
示例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é")
)
示例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 'if 2 == 2: /an "
"error' is not a partial control statement "
"at line: 2 char: 1").encode(sys.getdefaultencoding(), 'htmlentityreplace') in \
html_error
else:
assert ("CompileException: Fragment 'if 2 == 2: /an "
"error' 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''\
'привет'\
''</span><span class="cp">}</span>'.encode(
sys.getdefaultencoding(),
'htmlentityreplace') in html_error
else:
assert False, ("This function should trigger a CompileException, "
"but didn't")
示例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.... å")
)