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


Python exceptions.TemplateAssertionError方法代码示例

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


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

示例1: test_templates

# 需要导入模块: from jinja2 import exceptions [as 别名]
# 或者: from jinja2.exceptions import TemplateAssertionError [as 别名]
def test_templates(self):
        """
        Just to check templates syntax

        :return: None
        """

        from jinja2 import Environment, exceptions
        jinja_env = Environment(extensions=['jinja2.ext.i18n'])
        templates = os.listdir('bot/templates')
        for template in templates:
            print('Testing template:{}'.format(template))
            with open(os.path.join('bot/templates', template)) as f:
                template_text = unicode(f.read())
            try:
                jinja_env.from_string(template_text).render()
            except exceptions.TemplateAssertionError:
                pass
            except exceptions.UndefinedError:
                pass 
开发者ID:Xevib,项目名称:osmbot,代码行数:22,代码来源:test.py

示例2: fail

# 需要导入模块: from jinja2 import exceptions [as 别名]
# 或者: from jinja2.exceptions import TemplateAssertionError [as 别名]
def fail(self, msg, lineno):
        """Fail with a :exc:`TemplateAssertionError`."""
        raise TemplateAssertionError(msg, lineno, self.name, self.filename) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:compiler.py

示例3: parse_from

# 需要导入模块: from jinja2 import exceptions [as 别名]
# 或者: from jinja2.exceptions import TemplateAssertionError [as 别名]
def parse_from(self):
        node = nodes.FromImport(lineno=next(self.stream).lineno)
        node.template = self.parse_expression()
        self.stream.expect('name:import')
        node.names = []

        def parse_context():
            if self.stream.current.value in ('with', 'without') and \
               self.stream.look().test('name:context'):
                node.with_context = next(self.stream).value == 'with'
                self.stream.skip()
                return True
            return False

        while 1:
            if node.names:
                self.stream.expect('comma')
            if self.stream.current.type == 'name':
                if parse_context():
                    break
                target = self.parse_assign_target(name_only=True)
                if target.name.startswith('_'):
                    self.fail('names starting with an underline can not '
                              'be imported', target.lineno,
                              exc=TemplateAssertionError)
                if self.stream.skip_if('name:as'):
                    alias = self.parse_assign_target(name_only=True)
                    node.names.append((target.name, alias.name))
                else:
                    node.names.append(target.name)
                if parse_context() or self.stream.current.type != 'comma':
                    break
            else:
                self.stream.expect('name')
        if not hasattr(node, 'with_context'):
            node.with_context = False
        return node 
开发者ID:remg427,项目名称:misp42splunk,代码行数:39,代码来源:parser.py

示例4: parse_from

# 需要导入模块: from jinja2 import exceptions [as 别名]
# 或者: from jinja2.exceptions import TemplateAssertionError [as 别名]
def parse_from(self):
        node = nodes.FromImport(lineno=next(self.stream).lineno)
        node.template = self.parse_expression()
        self.stream.expect('name:import')
        node.names = []

        def parse_context():
            if self.stream.current.value in ('with', 'without') and \
               self.stream.look().test('name:context'):
                node.with_context = next(self.stream).value == 'with'
                self.stream.skip()
                return True
            return False

        while 1:
            if node.names:
                self.stream.expect('comma')
            if self.stream.current.type == 'name':
                if parse_context():
                    break
                target = self.parse_assign_target(name_only=True)
                if target.name.startswith('_'):
                    self.fail('names starting with an underline can not '
                              'be imported', target.lineno,
                              exc=TemplateAssertionError)
                if self.stream.skip_if('name:as'):
                    alias = self.parse_assign_target(name_only=True)
                    node.names.append((target.name, alias.name))
                else:
                    node.names.append(target.name)
                if parse_context() or self.stream.current.type != 'comma':
                    break
            else:
                break
        if not hasattr(node, 'with_context'):
            node.with_context = False
            self.stream.skip_if('comma')
        return node 
开发者ID:jpush,项目名称:jbox,代码行数:40,代码来源:parser.py

示例5: test_complex_plural

# 需要导入模块: from jinja2 import exceptions [as 别名]
# 或者: from jinja2.exceptions import TemplateAssertionError [as 别名]
def test_complex_plural(self):
        tmpl = i18n_env.from_string('{% trans foo=42, count=2 %}{{ count }} item{% '
                                    'pluralize count %}{{ count }} items{% endtrans %}')
        assert tmpl.render() == '2 items'
        self.assert_raises(TemplateAssertionError, i18n_env.from_string,
                           '{% trans foo %}...{% pluralize bar %}...{% endtrans %}') 
开发者ID:chalasr,项目名称:Flask-P2P,代码行数:8,代码来源:ext.py


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