本文整理汇总了Python中pystache.Renderer.escape方法的典型用法代码示例。如果您正苦于以下问题:Python Renderer.escape方法的具体用法?Python Renderer.escape怎么用?Python Renderer.escape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystache.Renderer
的用法示例。
在下文中一共展示了Renderer.escape方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__escape__uses_renderer_escape
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import escape [as 别名]
def test__escape__uses_renderer_escape(self):
"""
Test that escape uses the renderer's escape function.
"""
renderer = Renderer()
renderer.escape = lambda s: "**" + s
engine = renderer._make_render_engine()
escape = engine.escape
self.assertEqual(escape("foo"), "**foo")
示例2: test__interpolate__uses_renderer_escape
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import escape [as 别名]
def test__interpolate__uses_renderer_escape(self):
"""
Test that interpolate uses the renderer's interpolate function.
"""
renderer = Renderer()
renderer.escape = lambda s: "**" + s
engine = renderer._make_render_engine()
interpolate = engine.interpolate
self.assertEqual(interpolate("foo", '', None), "**foo")
示例3: test__escape__has_access_to_original_unicode_subclass
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import escape [as 别名]
def test__escape__has_access_to_original_unicode_subclass(self):
"""
Test that escape receives strings with the unicode subclass intact.
"""
renderer = Renderer()
renderer.escape = lambda s: str(type(s).__name__)
engine = renderer._make_render_engine()
escape = engine.escape
class MyUnicode(str):
pass
self.assertEqual(escape("foo".encode('ascii')), str.__name__)
self.assertEqual(escape("foo"), str.__name__)
self.assertEqual(escape(MyUnicode("foo")), MyUnicode.__name__)
示例4: test__escape__has_access_to_original_unicode_subclass
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import escape [as 别名]
def test__escape__has_access_to_original_unicode_subclass(self):
"""
Test that escape receives strings with the unicode subclass intact.
"""
renderer = Renderer()
renderer.escape = lambda s: type(s).__name__
engine = renderer._make_render_engine()
escape = engine.escape
class MyUnicode(unicode):
pass
self.assertEquals(escape("foo"), "unicode")
self.assertEquals(escape(u"foo"), "unicode")
self.assertEquals(escape(MyUnicode("foo")), "MyUnicode")
示例5: test_escape
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import escape [as 别名]
def test_escape(self):
escape = lambda s: "**" + s
renderer = Renderer(escape=escape)
self.assertEqual(renderer.escape("bar"), "**bar")