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


Python TemplateSpec.template_encoding方法代碼示例

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


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

示例1: test_load__template__with_template_encoding

# 需要導入模塊: from pystache import TemplateSpec [as 別名]
# 或者: from pystache.TemplateSpec import template_encoding [as 別名]
    def test_load__template__with_template_encoding(self):
        """
        Test the template attribute: with template encoding attribute.

        """
        custom = TemplateSpec()
        custom.template_encoding = 'ascii'
        custom.template = 'é'.encode('utf-8')

        spec_loader = self._make_specloader()

        self.assertRaises(UnicodeDecodeError, self._assert_template, spec_loader, custom, 'é')

        custom.template_encoding = 'utf-8'
        self._assert_template(spec_loader, custom, 'é')
開發者ID:GaloisInc,項目名稱:echronos,代碼行數:17,代碼來源:test_specloader.py

示例2: test_load__template__correct_loader

# 需要導入模塊: from pystache import TemplateSpec [as 別名]
# 或者: from pystache.TemplateSpec import template_encoding [as 別名]
    def test_load__template__correct_loader(self):
        """
        Test that reader.unicode() is called correctly.

        This test tests that the correct reader is called with the correct
        arguments.  This is a catch-all test to supplement the other
        test cases.  It tests SpecLoader.load() independent of reader.unicode()
        being implemented correctly (and tested).

        """
        class MockLoader(Loader):

            def __init__(self):
                self.s = None
                self.encoding = None

            # Overrides the existing method.
            def unicode(self, s, encoding=None):
                self.s = s
                self.encoding = encoding
                return u"foo"

        loader = MockLoader()
        custom_loader = SpecLoader()
        custom_loader.loader = loader

        view = TemplateSpec()
        view.template = "template-foo"
        view.template_encoding = "encoding-foo"

        # Check that our unicode() above was called.
        self._assert_template(custom_loader, view, u'foo')
        self.assertEqual(loader.s, "template-foo")
        self.assertEqual(loader.encoding, "encoding-foo")
開發者ID:tobiasandtobias,項目名稱:pystache,代碼行數:36,代碼來源:test_specloader.py

示例3: test_load__template__with_template_encoding

# 需要導入模塊: from pystache import TemplateSpec [as 別名]
# 或者: from pystache.TemplateSpec import template_encoding [as 別名]
    def test_load__template__with_template_encoding(self):
        """
        Test the template attribute: with template encoding attribute.

        """
        custom = TemplateSpec()
        custom.template = u'é'.encode('utf-8')

        self.assertRaises(UnicodeDecodeError, self._assert_template, SpecLoader(), custom, u'é')

        custom.template_encoding = 'utf-8'
        self._assert_template(SpecLoader(), custom, u'é')
開發者ID:clach04,項目名稱:pystache,代碼行數:14,代碼來源:test_template_spec.py


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