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


Python utils.Markup方法代码示例

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


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

示例1: format_string

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def format_string(self, s, args, kwargs, format_func=None):
        """If a format call is detected, then this is routed through this
        method so that our safety sandbox can be used for it.
        """
        if isinstance(s, Markup):
            formatter = SandboxedEscapeFormatter(self, s.escape)
        else:
            formatter = SandboxedFormatter(self)

        if format_func is not None and format_func.__name__ == 'format_map':
            if len(args) != 1 or kwargs:
                raise TypeError(
                    'format_map() takes exactly one argument %d given'
                    % (len(args) + (kwargs is not None))
                )

            kwargs = args[0]
            args = None

        kwargs = _MagicFormatMapping(args, kwargs)
        rv = formatter.vformat(s, args, kwargs)
        return type(s)(rv) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:24,代码来源:sandbox.py

示例2: return_buffer_contents

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def return_buffer_contents(self, frame, force_unescaped=False):
        """Return the buffer contents of the frame."""
        if not force_unescaped:
            if frame.eval_ctx.volatile:
                self.writeline('if context.eval_ctx.autoescape:')
                self.indent()
                self.writeline('return Markup(concat(%s))' % frame.buffer)
                self.outdent()
                self.writeline('else:')
                self.indent()
                self.writeline('return concat(%s)' % frame.buffer)
                self.outdent()
                return
            elif frame.eval_ctx.autoescape:
                self.writeline('return Markup(concat(%s))' % frame.buffer)
                return
        self.writeline('return concat(%s)' % frame.buffer) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:19,代码来源:compiler.py

示例3: visit_AssignBlock

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def visit_AssignBlock(self, node, frame):
        self.push_assign_tracking()
        block_frame = frame.inner()
        # This is a special case.  Since a set block always captures we
        # will disable output checks.  This way one can use set blocks
        # toplevel even in extended templates.
        block_frame.require_output_check = False
        block_frame.symbols.analyze_node(node)
        self.enter_frame(block_frame)
        self.buffer(block_frame)
        self.blockvisit(node.body, block_frame)
        self.newline(node)
        self.visit(node.target, frame)
        self.write(' = (Markup if context.eval_ctx.autoescape '
                   'else identity)(')
        if node.filter is not None:
            self.visit_Filter(node.filter, block_frame)
        else:
            self.write('concat(%s)' % block_frame.buffer)
        self.write(')')
        self.pop_assign_tracking(frame)
        self.leave_frame(block_frame)

    # -- Expression Visitors 
开发者ID:remg427,项目名称:misp42splunk,代码行数:26,代码来源:compiler.py

示例4: has_safe_repr

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def has_safe_repr(value):
    """Does the node have a safe representation?"""
    if value is None or value is NotImplemented or value is Ellipsis:
        return True
    if type(value) in (bool, int, float, complex, range_type, Markup) + string_types:
        return True
    if type(value) in (tuple, list, set, frozenset):
        for item in value:
            if not has_safe_repr(item):
                return False
        return True
    elif type(value) is dict:
        for key, value in iteritems(value):
            if not has_safe_repr(key):
                return False
            if not has_safe_repr(value):
                return False
        return True
    return False 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:compiler.py

示例5: has_safe_repr

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def has_safe_repr(value):
    """Does the node have a safe representation?"""
    if value is None or value is NotImplemented or value is Ellipsis:
        return True
    if isinstance(value, (bool, int, float, complex, range_type,
            Markup) + string_types):
        return True
    if isinstance(value, (tuple, list, set, frozenset)):
        for item in value:
            if not has_safe_repr(item):
                return False
        return True
    elif isinstance(value, dict):
        for key, value in iteritems(value):
            if not has_safe_repr(key):
                return False
            if not has_safe_repr(value):
                return False
        return True
    return False 
开发者ID:jpush,项目名称:jbox,代码行数:22,代码来源:compiler.py

示例6: visit_AssignBlock

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def visit_AssignBlock(self, node, frame):
        self.push_assign_tracking()
        block_frame = frame.inner()
        # This is a special case.  Since a set block always captures we
        # will disable output checks.  This way one can use set blocks
        # toplevel even in extended templates.
        block_frame.require_output_check = False
        block_frame.symbols.analyze_node(node)
        self.enter_frame(block_frame)
        self.buffer(block_frame)
        self.blockvisit(node.body, block_frame)
        self.newline(node)
        self.visit(node.target, frame)
        self.write(' = (Markup if context.eval_ctx.autoescape '
                   'else identity)(concat(%s))' % block_frame.buffer)
        self.pop_assign_tracking(frame)
        self.leave_frame(block_frame)

    # -- Expression Visitors 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:21,代码来源:compiler.py

示例7: wrap_block_reference_call

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def wrap_block_reference_call(original_call):
    @internalcode
    async def async_call(self):
        rv = await concat_async(self._stack[self._depth](self._context))
        if self._context.eval_ctx.autoescape:
            rv = Markup(rv)
        return rv

    @internalcode
    def __call__(self):
        if not self._context.environment.is_async:
            return original_call(self)
        return async_call(self)

    return update_wrapper(__call__, original_call) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:17,代码来源:asyncsupport.py

示例8: wrap_macro_invoke

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def wrap_macro_invoke(original_invoke):
    @internalcode
    async def async_invoke(self, arguments, autoescape):
        rv = await self._func(*arguments)
        if autoescape:
            rv = Markup(rv)
        return rv

    @internalcode
    def _invoke(self, arguments, autoescape):
        if not self._environment.is_async:
            return original_invoke(self, arguments, autoescape)
        return async_invoke(self, arguments, autoescape)
    return update_wrapper(_invoke, original_invoke) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:16,代码来源:asyncsupport.py

示例9: _make_new_gettext

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def _make_new_gettext(func):
    @contextfunction
    def gettext(__context, __string, **variables):
        rv = __context.call(func, __string)
        if __context.eval_ctx.autoescape:
            rv = Markup(rv)
        return rv % variables
    return gettext 
开发者ID:remg427,项目名称:misp42splunk,代码行数:10,代码来源:ext.py

示例10: _make_new_ngettext

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def _make_new_ngettext(func):
    @contextfunction
    def ngettext(__context, __singular, __plural, __num, **variables):
        variables.setdefault('num', __num)
        rv = __context.call(func, __singular, __plural, __num)
        if __context.eval_ctx.autoescape:
            rv = Markup(rv)
        return rv % variables
    return ngettext 
开发者ID:remg427,项目名称:misp42splunk,代码行数:11,代码来源:ext.py

示例11: visit_TemplateData

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def visit_TemplateData(self, node, frame):
        try:
            self.write(repr(node.as_const(frame.eval_ctx)))
        except nodes.Impossible:
            self.write('(Markup if context.eval_ctx.autoescape else identity)(%r)'
                       % node.data) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:8,代码来源:compiler.py

示例12: visit_Filter

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def visit_Filter(self, node, frame):
        if self.environment.is_async:
            self.write('await auto_await(')
        self.write(self.filters[node.name] + '(')
        func = self.environment.filters.get(node.name)
        if func is None:
            self.fail('no filter named %r' % node.name, node.lineno)
        if getattr(func, 'contextfilter', False):
            self.write('context, ')
        elif getattr(func, 'evalcontextfilter', False):
            self.write('context.eval_ctx, ')
        elif getattr(func, 'environmentfilter', False):
            self.write('environment, ')

        # if the filter node is None we are inside a filter block
        # and want to write to the current buffer
        if node.node is not None:
            self.visit(node.node, frame)
        elif frame.eval_ctx.volatile:
            self.write('(context.eval_ctx.autoescape and'
                       ' Markup(concat(%s)) or concat(%s))' %
                       (frame.buffer, frame.buffer))
        elif frame.eval_ctx.autoescape:
            self.write('Markup(concat(%s))' % frame.buffer)
        else:
            self.write('concat(%s)' % frame.buffer)
        self.signature(node, frame)
        self.write(')')
        if self.environment.is_async:
            self.write(')') 
开发者ID:remg427,项目名称:misp42splunk,代码行数:32,代码来源:compiler.py

示例13: visit_MarkSafe

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def visit_MarkSafe(self, node, frame):
        self.write('Markup(')
        self.visit(node.expr, frame)
        self.write(')') 
开发者ID:remg427,项目名称:misp42splunk,代码行数:6,代码来源:compiler.py

示例14: as_const

# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import Markup [as 别名]
def as_const(self, eval_ctx=None):
        eval_ctx = get_eval_context(self, eval_ctx)
        if eval_ctx.volatile:
            raise Impossible()
        if eval_ctx.autoescape:
            return Markup(self.data)
        return self.data 
开发者ID:remg427,项目名称:misp42splunk,代码行数:9,代码来源:nodes.py


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