本文整理汇总了Python中pystache.Renderer.unicode方法的典型用法代码示例。如果您正苦于以下问题:Python Renderer.unicode方法的具体用法?Python Renderer.unicode怎么用?Python Renderer.unicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystache.Renderer
的用法示例。
在下文中一共展示了Renderer.unicode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unicode__decode_errors
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import unicode [as 别名]
def test_unicode__decode_errors(self):
"""
Test that the decode_errors attribute is respected.
"""
renderer = Renderer()
renderer.string_encoding = "ascii"
s = "déf"
renderer.decode_errors = "ignore"
self.assertEquals(renderer.unicode(s), "df")
renderer.decode_errors = "replace"
# U+FFFD is the official Unicode replacement character.
self.assertEquals(renderer.unicode(s), u'd\ufffd\ufffdf')
示例2: test__escape__uses_renderer_unicode
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import unicode [as 别名]
def test__escape__uses_renderer_unicode(self):
"""
Test that escape uses the renderer's unicode function.
"""
renderer = Renderer()
renderer.unicode = lambda s: s.upper()
engine = renderer._make_render_engine()
escape = engine.escape
self.assertEquals(escape("foo"), "FOO")
示例3: test__literal__uses_renderer_unicode
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import unicode [as 别名]
def test__literal__uses_renderer_unicode(self):
"""
Test that literal uses the renderer's unicode function.
"""
renderer = Renderer()
renderer.unicode = lambda s: s.upper()
engine = renderer._make_render_engine()
literal = engine.literal
self.assertEquals(literal("foo"), "FOO")
示例4: test_unicode__string_encoding
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import unicode [as 别名]
def test_unicode__string_encoding(self):
"""
Test that the string_encoding attribute is respected.
"""
renderer = Renderer()
s = "é"
renderer.string_encoding = "ascii"
self.assertRaises(UnicodeDecodeError, renderer.unicode, s)
renderer.string_encoding = "utf-8"
self.assertEquals(renderer.unicode(s), u"é")
示例5: test__escape__uses_renderer_unicode
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import unicode [as 别名]
def test__escape__uses_renderer_unicode(self):
"""
Test that escape uses the renderer's unicode function.
"""
renderer = Renderer()
renderer.unicode = mock_unicode
engine = renderer._make_render_engine()
escape = engine.escape
b = u"foo".encode('ascii')
self.assertEqual(escape(b), "FOO")
示例6: test__make_loader__attributes
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import unicode [as 别名]
def test__make_loader__attributes(self):
"""
Test that _make_loader() sets all attributes correctly..
"""
unicode_ = lambda x: x
renderer = Renderer()
renderer.file_encoding = 'enc'
renderer.file_extension = 'ext'
renderer.unicode = unicode_
loader = renderer._make_loader()
self.assertEquals(loader.extension, 'ext')
self.assertEquals(loader.file_encoding, 'enc')
self.assertEquals(loader.to_unicode, unicode_)