當前位置: 首頁>>代碼示例>>Python>>正文


Python util.FastEncodingBuffer方法代碼示例

本文整理匯總了Python中mako.util.FastEncodingBuffer方法的典型用法代碼示例。如果您正苦於以下問題:Python util.FastEncodingBuffer方法的具體用法?Python util.FastEncodingBuffer怎麽用?Python util.FastEncodingBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mako.util的用法示例。


在下文中一共展示了util.FastEncodingBuffer方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _render_error

# 需要導入模塊: from mako import util [as 別名]
# 或者: from mako.util import FastEncodingBuffer [as 別名]
def _render_error(template, context, error):
    if template.error_handler:
        result = template.error_handler(context, error)
        if not result:
            compat.reraise(*sys.exc_info())
    else:
        error_template = exceptions.html_error_template()
        if context._outputting_as_unicode:
            context._buffer_stack[:] = [
                util.FastEncodingBuffer(as_unicode=True)
            ]
        else:
            context._buffer_stack[:] = [
                util.FastEncodingBuffer(
                    error_template.output_encoding,
                    error_template.encoding_errors,
                )
            ]

        context._set_with_template(error_template)
        error_template.render_context(context, error=error) 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:23,代碼來源:runtime.py

示例2: _render

# 需要導入模塊: from mako import util [as 別名]
# 或者: from mako.util import FastEncodingBuffer [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

示例3: _render_error

# 需要導入模塊: from mako import util [as 別名]
# 或者: from mako.util import FastEncodingBuffer [as 別名]
def _render_error(template, context, error):
    if template.error_handler:
        result = template.error_handler(context, error)
        if not result:
            compat.reraise(*sys.exc_info())
    else:
        error_template = exceptions.html_error_template()
        if context._outputting_as_unicode:
            context._buffer_stack[:] = [
                util.FastEncodingBuffer(as_unicode=True)]
        else:
            context._buffer_stack[:] = [util.FastEncodingBuffer(
                error_template.output_encoding,
                error_template.encoding_errors)]

        context._set_with_template(error_template)
        error_template.render_context(context, error=error) 
開發者ID:jpush,項目名稱:jbox,代碼行數:19,代碼來源:runtime.py

示例4: test_dont_accept_relative_outside_of_root

# 需要導入模塊: from mako import util [as 別名]
# 或者: from mako.util import FastEncodingBuffer [as 別名]
def test_dont_accept_relative_outside_of_root(self):
        """test the mechanics of an include where
        the include goes outside of the path"""
        tl = lookup.TemplateLookup(directories=[os.path.join(template_base, "subdir")])
        index = tl.get_template("index.html")

        ctx = runtime.Context(FastEncodingBuffer())
        ctx._with_template=index

        assert_raises_message(
            exceptions.TemplateLookupException,
           "Template uri \"../index.html\" is invalid - it "
            "cannot be relative outside of the root path",
            runtime._lookup_template, ctx, "../index.html", index.uri
        )

        assert_raises_message(
            exceptions.TemplateLookupException,
           "Template uri \"../othersubdir/foo.html\" is invalid - it "
            "cannot be relative outside of the root path",
            runtime._lookup_template, ctx, "../othersubdir/foo.html", index.uri
        )

        # this is OK since the .. cancels out
        t = runtime._lookup_template(ctx, "foo/../index.html", index.uri) 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:27,代碼來源:test_lookup.py

示例5: _render

# 需要導入模塊: from mako import util [as 別名]
# 或者: from mako.util import FastEncodingBuffer [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:fboender,項目名稱:ansible-cmdb,代碼行數:22,代碼來源:runtime.py

示例6: _render_error

# 需要導入模塊: from mako import util [as 別名]
# 或者: from mako.util import FastEncodingBuffer [as 別名]
def _render_error(template, context, error):
    if template.error_handler:
        result = template.error_handler(context, error)
        if not result:
            compat.reraise(*sys.exc_info())
    else:
        error_template = exceptions.html_error_template()
        if context._outputting_as_unicode:
            context._buffer_stack[:] = [
                                    util.FastEncodingBuffer(as_unicode=True)]
        else:
            context._buffer_stack[:] = [util.FastEncodingBuffer(
                                            error_template.output_encoding,
                                            error_template.encoding_errors)]

        context._set_with_template(error_template)
        error_template.render_context(context, error=error) 
開發者ID:fboender,項目名稱:ansible-cmdb,代碼行數:19,代碼來源:runtime.py

示例7: _push_writer

# 需要導入模塊: from mako import util [as 別名]
# 或者: from mako.util import FastEncodingBuffer [as 別名]
def _push_writer(self):
        """push a capturing buffer onto this Context and return
        the new writer function."""

        buf = util.FastEncodingBuffer()
        self._buffer_stack.append(buf)
        return buf.write 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:9,代碼來源:runtime.py

示例8: _render

# 需要導入模塊: from mako import util [as 別名]
# 或者: from mako.util import FastEncodingBuffer [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

示例9: compile

# 需要導入模塊: from mako import util [as 別名]
# 或者: from mako.util import FastEncodingBuffer [as 別名]
def compile(node,
            uri,
            filename=None,
            default_filters=None,
            buffer_filters=None,
            imports=None,
            future_imports=None,
            source_encoding=None,
            generate_magic_comment=True,
            disable_unicode=False,
            strict_undefined=False,
            enable_loop=True,
            reserved_names=frozenset()):
    """Generate module source code given a parsetree node,
      uri, and optional source filename"""

    # if on Py2K, push the "source_encoding" string to be
    # a bytestring itself, as we will be embedding it into
    # the generated source and we don't want to coerce the
    # result into a unicode object, in "disable_unicode" mode
    if not compat.py3k and isinstance(source_encoding, compat.text_type):
        source_encoding = source_encoding.encode(source_encoding)

    buf = util.FastEncodingBuffer()

    printer = PythonPrinter(buf)
    _GenerateRenderMethod(printer,
                          _CompileContext(uri,
                                          filename,
                                          default_filters,
                                          buffer_filters,
                                          imports,
                                          future_imports,
                                          source_encoding,
                                          generate_magic_comment,
                                          disable_unicode,
                                          strict_undefined,
                                          enable_loop,
                                          reserved_names),
                          node)
    return buf.getvalue() 
開發者ID:jpush,項目名稱:jbox,代碼行數:43,代碼來源:codegen.py

示例10: test_fast_buffer_write

# 需要導入模塊: from mako import util [as 別名]
# 或者: from mako.util import FastEncodingBuffer [as 別名]
def test_fast_buffer_write(self):
        buf = util.FastEncodingBuffer()
        buf.write("string a ")
        buf.write("string b")
        eq_(buf.getvalue(), "string a string b") 
開發者ID:sqlalchemy,項目名稱:mako,代碼行數:7,代碼來源:test_util.py

示例11: test_fast_buffer_encoded

# 需要導入模塊: from mako import util [as 別名]
# 或者: from mako.util import FastEncodingBuffer [as 別名]
def test_fast_buffer_encoded(self):
        s = u("drôl m’a rée « S’il")
        buf = util.FastEncodingBuffer(encoding="utf-8")
        buf.write(s[0:10])
        buf.write(s[10:])
        eq_(buf.getvalue(), s.encode("utf-8")) 
開發者ID:sqlalchemy,項目名稱:mako,代碼行數:8,代碼來源:test_util.py


注:本文中的mako.util.FastEncodingBuffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。