environment.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:QA4LOV 作者: gatemezing 项目源码 文件源码
def call_filter(self, name, value, args=None, kwargs=None,
                    context=None, eval_ctx=None):
        """Invokes a filter on a value the same way the compiler does it.

        .. versionadded:: 2.7
        """
        func = self.filters.get(name)
        if func is None:
            raise TemplateRuntimeError('no filter named %r' % name)
        args = [value] + list(args or ())
        if getattr(func, 'contextfilter', False):
            if context is None:
                raise TemplateRuntimeError('Attempted to invoke context '
                                           'filter without context')
            args.insert(0, context)
        elif getattr(func, 'evalcontextfilter', False):
            if eval_ctx is None:
                if context is not None:
                    eval_ctx = context.eval_ctx
                else:
                    eval_ctx = EvalContext(self)
            args.insert(0, eval_ctx)
        elif getattr(func, 'environmentfilter', False):
            args.insert(0, self)
        return func(*args, **(kwargs or {}))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号