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


Python Renderer.string_encoding方法代码示例

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


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

示例1: test_unicode__string_encoding

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import string_encoding [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"é")
开发者ID:chuanzhang,项目名称:pystache,代码行数:15,代码来源:test_renderer.py

示例2: test_render__nonascii_template

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import string_encoding [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 string_encoding are both respected.
        renderer.decode_errors = 'ignore'
        renderer.string_encoding = 'ascii'
        self.assertEquals(renderer.render(template), "df")

        renderer.string_encoding = 'utf_8'
        self.assertEquals(renderer.render(template), u"déf")
开发者ID:chuanzhang,项目名称:pystache,代码行数:17,代码来源:test_renderer.py

示例3: test__literal__handles_unicode

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import string_encoding [as 别名]
    def test__literal__handles_unicode(self):
        """
        Test that literal doesn't try to "double decode" unicode.

        """
        renderer = Renderer()
        renderer.string_encoding = 'ascii'

        engine = renderer._make_render_engine()
        literal = engine.literal

        self.assertEqual(literal("foo"), "foo")
开发者ID:Abixer,项目名称:croomcroom,代码行数:14,代码来源:test_renderer.py

示例4: test__literal__handles_unicode

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import string_encoding [as 别名]
    def test__literal__handles_unicode(self):
        """
        Test that interpolate(..., 'literal') doesn't try to "double decode" unicode.

        """
        renderer = Renderer()
        renderer.string_encoding = 'ascii'

        engine = renderer._make_render_engine()
        interpolate = engine.interpolate

        self.assertEqual(interpolate("foo", 'literal', None), "foo")
开发者ID:GaloisInc,项目名称:echronos,代码行数:14,代码来源:test_renderer.py

示例5: test_unicode__decode_errors

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import string_encoding [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')
开发者ID:chuanzhang,项目名称:pystache,代码行数:17,代码来源:test_renderer.py

示例6: test__resolve_partial__returns_subclass

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import string_encoding [as 别名]
    def test__resolve_partial__returns_subclass(self):
        """Check that resolve_partial returns str (preserving any subclass)."""
        class MyUnicode(str):
            pass

        renderer = Renderer()
        renderer.string_encoding = 'ascii'
        renderer.partials = {'str': 'foo', 'subclass': MyUnicode('abc')}

        engine = renderer._make_render_engine()

        actual = engine.resolve_partial('str', None)
        self.assertEqual(actual, "foo")
        self.assertEqual(type(actual), str)

        # Check that unicode subclasses are not preserved.
        actual = engine.resolve_partial('subclass', None)
        self.assertEqual(actual, "abc")
        self.assertEqual(type(actual), MyUnicode)
开发者ID:GaloisInc,项目名称:echronos,代码行数:21,代码来源:test_renderer.py

示例7: test__literal__returns_unicode

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import string_encoding [as 别名]
    def test__literal__returns_unicode(self):
        """
        Test that literal returns unicode (and not a subclass).

        """
        renderer = Renderer()
        renderer.string_encoding = 'ascii'

        engine = renderer._make_render_engine()
        literal = engine.literal

        self.assertEqual(type(literal("foo")), str)

        class MyUnicode(str):
            pass

        s = MyUnicode("abc")

        self.assertEqual(type(s), MyUnicode)
        self.assertTrue(isinstance(s, str))
        self.assertEqual(type(literal(s)), str)
开发者ID:Abixer,项目名称:croomcroom,代码行数:23,代码来源:test_renderer.py

示例8: test__literal__returns_unicode

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import string_encoding [as 别名]
    def test__literal__returns_unicode(self):
        """
        Test that interpolate(..., 'literal') returns unicode (and not a subclass).

        """
        renderer = Renderer()
        renderer.string_encoding = 'ascii'

        engine = renderer._make_render_engine()
        interpolate = engine.interpolate

        self.assertEqual(type(interpolate("foo", 'literal', None)), str)

        class MyUnicode(str):
            pass

        s = MyUnicode("abc")

        self.assertEqual(type(s), MyUnicode)
        self.assertTrue(isinstance(s, str))
        self.assertEqual(type(interpolate(s, 'literal', None)), str)
开发者ID:GaloisInc,项目名称:echronos,代码行数:23,代码来源:test_renderer.py

示例9: test__escape__returns_unicode

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import string_encoding [as 别名]
    def test__escape__returns_unicode(self):
        """
        Test that literal returns unicode (and not a subclass).

        """
        renderer = Renderer()
        renderer.string_encoding = 'ascii'

        engine = renderer._make_render_engine()
        escape = engine.escape

        self.assertEqual(type(escape("foo")), str)

        # Check that literal doesn't preserve unicode subclasses.
        class MyUnicode(str):
            pass

        s = MyUnicode("abc")

        self.assertEqual(type(s), MyUnicode)
        self.assertTrue(isinstance(s, str))
        self.assertEqual(type(escape(s)), str)
开发者ID:Abixer,项目名称:croomcroom,代码行数:24,代码来源:test_renderer.py

示例10: test__load_partial__returns_unicode

# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import string_encoding [as 别名]
    def test__load_partial__returns_unicode(self):
        """
        Check that load_partial returns unicode (and not a subclass).

        """
        class MyUnicode(str):
            pass

        renderer = Renderer()
        renderer.string_encoding = 'ascii'
        renderer.partials = {'str': 'foo', 'subclass': MyUnicode('abc')}

        engine = renderer._make_render_engine()

        actual = engine.load_partial('str')
        self.assertEqual(actual, "foo")
        self.assertEqual(type(actual), str)

        # Check that unicode subclasses are not preserved.
        actual = engine.load_partial('subclass')
        self.assertEqual(actual, "abc")
        self.assertEqual(type(actual), str)
开发者ID:phihag,项目名称:py3stache,代码行数:24,代码来源:test_renderer.py


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