當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。