當前位置: 首頁>>代碼示例>>Python>>正文


Python Renderer.default_encoding方法代碼示例

本文整理匯總了Python中pystache.renderer.Renderer.default_encoding方法的典型用法代碼示例。如果您正苦於以下問題:Python Renderer.default_encoding方法的具體用法?Python Renderer.default_encoding怎麽用?Python Renderer.default_encoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pystache.renderer.Renderer的用法示例。


在下文中一共展示了Renderer.default_encoding方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_unicode__default_encoding

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import default_encoding [as 別名]
    def test_unicode__default_encoding(self):
        """
        Test that the default_encoding attribute is respected.

        """
        renderer = Renderer()
        s = "é"

        renderer.default_encoding = "ascii"
        self.assertRaises(UnicodeDecodeError, renderer.unicode, s)

        renderer.default_encoding = "utf-8"
        self.assertEquals(renderer.unicode(s), u"é")
開發者ID:jakearchibald,項目名稱:pystache,代碼行數:15,代碼來源:test_renderer.py

示例2: test_render__nonascii_template

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import default_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 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")
開發者ID:jakearchibald,項目名稱:pystache,代碼行數:17,代碼來源:test_renderer.py

示例3: test__literal__handles_unicode

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import default_encoding [as 別名]
    def test__literal__handles_unicode(self):
        """
        Test that literal doesn't try to "double decode" unicode.

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

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

        self.assertEquals(literal(u"foo"), "foo")
開發者ID:jakearchibald,項目名稱:pystache,代碼行數:14,代碼來源:test_renderer.py

示例4: test_unicode__decode_errors

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import default_encoding [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')
開發者ID:jakearchibald,項目名稱:pystache,代碼行數:17,代碼來源:test_renderer.py

示例5: test__literal__returns_unicode

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import default_encoding [as 別名]
    def test__literal__returns_unicode(self):
        """
        Test that literal returns unicode (and not a subclass).

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

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

        self.assertEquals(type(literal("foo")), unicode)

        class MyUnicode(unicode):
            pass

        s = MyUnicode("abc")

        self.assertEquals(type(s), MyUnicode)
        self.assertTrue(isinstance(s, unicode))
        self.assertEquals(type(literal(s)), unicode)
開發者ID:jakearchibald,項目名稱:pystache,代碼行數:23,代碼來源:test_renderer.py

示例6: test__escape__returns_unicode

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import default_encoding [as 別名]
    def test__escape__returns_unicode(self):
        """
        Test that literal returns unicode (and not a subclass).

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

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

        self.assertEquals(type(escape("foo")), unicode)

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

        s = MyUnicode("abc")

        self.assertEquals(type(s), MyUnicode)
        self.assertTrue(isinstance(s, unicode))
        self.assertEquals(type(escape(s)), unicode)
開發者ID:jakearchibald,項目名稱:pystache,代碼行數:24,代碼來源:test_renderer.py

示例7: test__load_partial__returns_unicode

# 需要導入模塊: from pystache.renderer import Renderer [as 別名]
# 或者: from pystache.renderer.Renderer import default_encoding [as 別名]
    def test__load_partial__returns_unicode(self):
        """
        Check that load_partial returns unicode (and not a subclass).

        """
        class MyUnicode(unicode):
            pass

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

        engine = renderer._make_render_engine()

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

        # Check that unicode subclasses are not preserved.
        actual = engine.load_partial('subclass')
        self.assertEquals(actual, "abc")
        self.assertEquals(type(actual), unicode)
開發者ID:jakearchibald,項目名稱:pystache,代碼行數:24,代碼來源:test_renderer.py


注:本文中的pystache.renderer.Renderer.default_encoding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。