本文整理匯總了Python中pystache.renderer.Renderer.decode_errors方法的典型用法代碼示例。如果您正苦於以下問題:Python Renderer.decode_errors方法的具體用法?Python Renderer.decode_errors怎麽用?Python Renderer.decode_errors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pystache.renderer.Renderer
的用法示例。
在下文中一共展示了Renderer.decode_errors方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_unicode__decode_errors
# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import decode_errors [as 別名]
def test_unicode__decode_errors(self):
"""
Test that the decode_errors attribute is respected.
"""
renderer = Renderer()
renderer.default_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_read__decode_errors
# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import decode_errors [as 別名]
def test_read__decode_errors(self):
filename = 'nonascii.mustache'
renderer = Renderer()
self.assertRaises(UnicodeDecodeError, self._read, renderer, filename)
renderer.decode_errors = 'ignore'
actual = self._read(renderer, filename)
self.assertEquals(actual, 'non-ascii: ')
示例3: test_render__nonascii_template
# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import decode_errors [as 別名]
def test_render__nonascii_template(self):
"""
Test passing a non-unicode template with non-ascii characters.
"""
renderer = Renderer()
template = "déf"
# Check that decode_errors and default_encoding are both respected.
renderer.decode_errors = 'ignore'
renderer.default_encoding = 'ascii'
self.assertEquals(renderer.render(template), "df")
renderer.default_encoding = 'utf_8'
self.assertEquals(renderer.render(template), u"déf")