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


Python template.callable_方法代码示例

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


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

示例1: capture

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def capture(context, callable_, *args, **kwargs):
    """Execute the given template def, capturing the output into
    a buffer.

    See the example in :ref:`namespaces_python_modules`.

    """

    if not callable(callable_):
        raise exceptions.RuntimeException(
            "capture() function expects a callable as "
            "its argument (i.e. capture(func, *args, **kwargs))"
        )
    context._push_buffer()
    try:
        callable_(*args, **kwargs)
    finally:
        buf = context._pop_buffer()
    return buf.getvalue() 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:runtime.py

示例2: _exec_template

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def _exec_template(callable_, context, args=None, kwargs=None):
    """execute a rendering callable given the callable, a
    Context, and optional explicit arguments

    the contextual Template will be located if it exists, and
    the error handling options specified on that Template will
    be interpreted here.
    """
    template = context._with_template
    if template is not None and (
        template.format_exceptions or template.error_handler
    ):
        try:
            callable_(context, *args, **kwargs)
        except Exception:
            _render_error(template, context, compat.exception_as())
        except:
            e = sys.exc_info()[0]
            _render_error(template, context, e)
    else:
        callable_(context, *args, **kwargs) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:23,代码来源:runtime.py

示例3: _include_file

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def _include_file(context, uri, calling_uri, **kwargs):
    """locate the template from the given uri and include it in
    the current output."""

    template = _lookup_template(context, uri, calling_uri)
    (callable_, ctx) = _populate_self_namespace(
        context._clean_inheritance_tokens(), template
    )
    kwargs = _kwargs_for_include(callable_, context._data, **kwargs)
    if template.include_error_handler:
        try:
            callable_(ctx, **kwargs)
        except Exception:
            result = template.include_error_handler(ctx, compat.exception_as())
            if not result:
                compat.reraise(*sys.exc_info())
    else:
        callable_(ctx, **kwargs) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:20,代码来源:runtime.py

示例4: capture

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def capture(context, callable_, *args, **kwargs):
    """Execute the given template def, capturing the output into
    a buffer.

    See the example in :ref:`namespaces_python_modules`.

    """

    if not compat.callable(callable_):
        raise exceptions.RuntimeException(
            "capture() function expects a callable as "
            "its argument (i.e. capture(func, *args, **kwargs))"
        )
    context._push_buffer()
    try:
        callable_(*args, **kwargs)
    finally:
        buf = context._pop_buffer()
    return buf.getvalue() 
开发者ID:jpush,项目名称:jbox,代码行数:21,代码来源:runtime.py

示例5: _render

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def _render(template, callable_, args, data, as_unicode=False):
    """create a Context and return the string
    output of the given template and template callable."""

    if as_unicode:
        buf = util.FastEncodingBuffer(as_unicode=True)
    elif template.bytestring_passthrough:
        buf = compat.StringIO()
    else:
        buf = util.FastEncodingBuffer(
            as_unicode=as_unicode,
            encoding=template.output_encoding,
            errors=template.encoding_errors)
    context = Context(buf, **data)
    context._outputting_as_unicode = as_unicode
    context._set_with_template(template)

    _render_context(template, callable_, context, *args,
                    **_kwargs_for_callable(callable_, data))
    return context._pop_buffer().getvalue() 
开发者ID:jpush,项目名称:jbox,代码行数:22,代码来源:runtime.py

示例6: _exec_template

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def _exec_template(callable_, context, args=None, kwargs=None):
    """execute a rendering callable given the callable, a
    Context, and optional explicit arguments

    the contextual Template will be located if it exists, and
    the error handling options specified on that Template will
    be interpreted here.
    """
    template = context._with_template
    if template is not None and \
            (template.format_exceptions or template.error_handler):
        try:
            callable_(context, *args, **kwargs)
        except Exception:
            _render_error(template, context, compat.exception_as())
        except:
            e = sys.exc_info()[0]
            _render_error(template, context, e)
    else:
        callable_(context, *args, **kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:22,代码来源:runtime.py

示例7: _get_star

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def _get_star(self):
        if self.callables:
            for key in self.callables:
                yield (key, self.callables[key])

        def get(key):
            callable_ = self.template._get_def_callable(key)
            return functools.partial(callable_, self.context)

        for k in self.template.module._exports:
            yield (k, get(k)) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:13,代码来源:runtime.py

示例8: __getattr__

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def __getattr__(self, key):
        if key in self.callables:
            val = self.callables[key]
        elif self.template.has_def(key):
            callable_ = self.template._get_def_callable(key)
            val = functools.partial(callable_, self.context)
        elif self.inherits:
            val = getattr(self.inherits, key)

        else:
            raise AttributeError(
                "Namespace '%s' has no member '%s'" % (self.name, key)
            )
        setattr(self, key, val)
        return val 
开发者ID:remg427,项目名称:misp42splunk,代码行数:17,代码来源:runtime.py

示例9: _inherit_from

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def _inherit_from(context, uri, calling_uri):
    """called by the _inherit method in template modules to set
    up the inheritance chain at the start of a template's
    execution."""

    if uri is None:
        return None
    template = _lookup_template(context, uri, calling_uri)
    self_ns = context["self"]
    ih = self_ns
    while ih.inherits is not None:
        ih = ih.inherits
    lclcontext = context._locals({"next": ih})
    ih.inherits = TemplateNamespace(
        "self:%s" % template.uri,
        lclcontext,
        template=template,
        populate_self=False,
    )
    context._data["parent"] = lclcontext._data["local"] = ih.inherits
    callable_ = getattr(template.module, "_mako_inherit", None)
    if callable_ is not None:
        ret = callable_(template, lclcontext)
        if ret:
            return ret

    gen_ns = getattr(template.module, "_mako_generate_namespaces", None)
    if gen_ns is not None:
        gen_ns(context)
    return (template.callable_, lclcontext) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:32,代码来源:runtime.py

示例10: _populate_self_namespace

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def _populate_self_namespace(context, template, self_ns=None):
    if self_ns is None:
        self_ns = TemplateNamespace(
            "self:%s" % template.uri,
            context,
            template=template,
            populate_self=False,
        )
    context._data["self"] = context._data["local"] = self_ns
    if hasattr(template.module, "_mako_inherit"):
        ret = template.module._mako_inherit(template, context)
        if ret:
            return ret
    return (template.callable_, context) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:16,代码来源:runtime.py

示例11: _render

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def _render(template, callable_, args, data, as_unicode=False):
    """create a Context and return the string
    output of the given template and template callable."""

    if as_unicode:
        buf = util.FastEncodingBuffer(as_unicode=True)
    elif template.bytestring_passthrough:
        buf = compat.StringIO()
    else:
        buf = util.FastEncodingBuffer(
            as_unicode=as_unicode,
            encoding=template.output_encoding,
            errors=template.encoding_errors,
        )
    context = Context(buf, **data)
    context._outputting_as_unicode = as_unicode
    context._set_with_template(template)

    _render_context(
        template,
        callable_,
        context,
        *args,
        **_kwargs_for_callable(callable_, data)
    )
    return context._pop_buffer().getvalue() 
开发者ID:remg427,项目名称:misp42splunk,代码行数:28,代码来源:runtime.py

示例12: _kwargs_for_callable

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def _kwargs_for_callable(callable_, data):
    argspec = compat.inspect_getargspec(callable_)
    # for normal pages, **pageargs is usually present
    if argspec[2]:
        return data

    # for rendering defs from the top level, figure out the args
    namedargs = argspec[0] + [v for v in argspec[1:3] if v is not None]
    kwargs = {}
    for arg in namedargs:
        if arg != "context" and arg in data and arg not in kwargs:
            kwargs[arg] = data[arg]
    return kwargs 
开发者ID:remg427,项目名称:misp42splunk,代码行数:15,代码来源:runtime.py

示例13: _kwargs_for_include

# 需要导入模块: from mako import template [as 别名]
# 或者: from mako.template import callable_ [as 别名]
def _kwargs_for_include(callable_, data, **kwargs):
    argspec = compat.inspect_getargspec(callable_)
    namedargs = argspec[0] + [v for v in argspec[1:3] if v is not None]
    for arg in namedargs:
        if arg != "context" and arg in data and arg not in kwargs:
            kwargs[arg] = data[arg]
    return kwargs 
开发者ID:remg427,项目名称:misp42splunk,代码行数:9,代码来源:runtime.py


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