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


Python pygen.PythonPrinter方法代碼示例

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


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

示例1: _render_cmd_body

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def _render_cmd_body(op_container, autogen_context):

    buf = StringIO()
    printer = PythonPrinter(buf)

    printer.writeline(
        "### commands auto generated by Alembic - "
        "please adjust! ###"
    )

    if not op_container.ops:
        printer.writeline("pass")
    else:
        for op in op_container.ops:
            lines = render_op(autogen_context, op)

            for line in lines:
                printer.writeline(line)

    printer.writeline("### end Alembic commands ###")

    return buf.getvalue() 
開發者ID:jpush,項目名稱:jbox,代碼行數:24,代碼來源:render.py

示例2: _render_cmd_body

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def _render_cmd_body(op_container, autogen_context):

    buf = StringIO()
    printer = PythonPrinter(buf)

    printer.writeline(
        "# ### commands auto generated by Alembic - please adjust! ###"
    )

    has_lines = False
    for op in op_container.ops:
        lines = render_op(autogen_context, op)
        has_lines = has_lines or lines

        for line in lines:
            printer.writeline(line)

    if not has_lines:
        printer.writeline("pass")

    printer.writeline("# ### end Alembic commands ###")

    return buf.getvalue() 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:25,代碼來源:render.py

示例3: test_generate_normal

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def test_generate_normal(self):
        stream = StringIO()
        printer = PythonPrinter(stream)
        printer.writeline("import lala")
        printer.writeline("for x in foo:")
        printer.writeline("print x")
        printer.writeline(None)
        printer.writeline("print y")
        assert (
            stream.getvalue()
            == """import lala
for x in foo:
    print x
print y
"""
        ) 
開發者ID:sqlalchemy,項目名稱:mako,代碼行數:18,代碼來源:test_pygen.py

示例4: test_generate_adjusted

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def test_generate_adjusted(self):
        block = """
        x = 5 +6
        if x > 7:
            for y in range(1,5):
                print "<td>%s</td>" % y
"""
        stream = StringIO()
        printer = PythonPrinter(stream)
        printer.write_indented_block(block)
        printer.close()
        # print stream.getvalue()
        assert (
            stream.getvalue()
            == """
x = 5 +6
if x > 7:
    for y in range(1,5):
        print "<td>%s</td>" % y

"""
        ) 
開發者ID:sqlalchemy,項目名稱:mako,代碼行數:24,代碼來源:test_pygen.py

示例5: test_backslash_line

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def test_backslash_line(self):
        block = """
            # comment
    if test:
        if (lala + hoho) + \\
(foobar + blat) == 5:
            print "hi"
    print "more indent"
"""
        stream = StringIO()
        printer = PythonPrinter(stream)
        printer.write_indented_block(block)
        printer.close()
        assert (
            stream.getvalue()
            == """
            # comment
if test:
    if (lala + hoho) + \\
(foobar + blat) == 5:
        print "hi"
print "more indent"

"""
        ) 
開發者ID:sqlalchemy,項目名稱:mako,代碼行數:27,代碼來源:test_pygen.py

示例6: test_generate_adjusted

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def test_generate_adjusted(self):
        block = """
        x = 5 +6
        if x > 7:
            for y in range(1,5):
                print "<td>%s</td>" % y
"""
        stream = StringIO()
        printer = PythonPrinter(stream)
        printer.write_indented_block(block)
        printer.close()
        #print stream.getvalue()
        assert stream.getvalue() == \
"""
x = 5 +6
if x > 7:
    for y in range(1,5):
        print "<td>%s</td>" % y

""" 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:22,代碼來源:test_pygen.py

示例7: test_multi_line

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def test_multi_line(self):
        block = \
"""
    if test:
        print ''' this is a block of stuff.
this is more stuff in the block.
and more block.
'''
        do_more_stuff(g)
"""
        stream = StringIO()
        printer = PythonPrinter(stream)
        printer.write_indented_block(block)
        printer.close()
        #print stream.getvalue()
        assert stream.getvalue() == \
"""
if test:
    print ''' this is a block of stuff.
this is more stuff in the block.
and more block.
'''
    do_more_stuff(g)

""" 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:27,代碼來源:test_pygen.py

示例8: test_false_unindentor

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def test_false_unindentor(self):
        stream = StringIO()
        printer = PythonPrinter(stream)
        for line in [
            "try:",
            "elsemyvar = 12",
            "if True:",
            "print 'hi'",
            None,
            "finally:",
            "dosomething",
            None
        ]:
            printer.writeline(line)

        assert stream.getvalue() == \
"""try:
    elsemyvar = 12
    if True:
        print 'hi'
finally:
    dosomething
"""    , stream.getvalue() 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:25,代碼來源:test_pygen.py

示例9: _render_cmd_body

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def _render_cmd_body(op_container, autogen_context):

    buf = StringIO()
    printer = PythonPrinter(buf)

    printer.writeline(
        "# ### commands auto generated by Alembic - please adjust! ###"
    )

    if not op_container.ops:
        printer.writeline("pass")
    else:
        for op in op_container.ops:
            lines = render_op(autogen_context, op)

            for line in lines:
                printer.writeline(line)

    printer.writeline("# ### end Alembic commands ###")

    return buf.getvalue() 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:23,代碼來源:render.py

示例10: compile

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

示例11: test_generate_combo

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def test_generate_combo(self):
        block = """
                x = 5 +6
                if x > 7:
                    for y in range(1,5):
                        print "<td>%s</td>" % y
                    print "hi"
                print "there"
                foo(lala)
"""
        stream = StringIO()
        printer = PythonPrinter(stream)
        printer.writeline("import lala")
        printer.writeline("for x in foo:")
        printer.writeline("print x")
        printer.write_indented_block(block)
        printer.writeline(None)
        printer.writeline("print y")
        printer.close()
        # print "->" + stream.getvalue().replace(' ', '#') + "<-"
        eq_(
            stream.getvalue(),
            """import lala
for x in foo:
    print x

    x = 5 +6
    if x > 7:
        for y in range(1,5):
            print "<td>%s</td>" % y
        print "hi"
    print "there"
    foo(lala)

print y
""",
        ) 
開發者ID:sqlalchemy,項目名稱:mako,代碼行數:39,代碼來源:test_pygen.py

示例12: test_multi_line

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def test_multi_line(self):
        block = """
    if test:
        print ''' this is a block of stuff.
this is more stuff in the block.
and more block.
'''
        do_more_stuff(g)
"""
        stream = StringIO()
        printer = PythonPrinter(stream)
        printer.write_indented_block(block)
        printer.close()
        # print stream.getvalue()
        assert (
            stream.getvalue()
            == """
if test:
    print ''' this is a block of stuff.
this is more stuff in the block.
and more block.
'''
    do_more_stuff(g)

"""
        ) 
開發者ID:sqlalchemy,項目名稱:mako,代碼行數:28,代碼來源:test_pygen.py

示例13: test_generate_normal

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def test_generate_normal(self):
        stream = StringIO()
        printer = PythonPrinter(stream)
        printer.writeline("import lala")
        printer.writeline("for x in foo:")
        printer.writeline("print x")
        printer.writeline(None)
        printer.writeline("print y")
        assert stream.getvalue() == \
"""import lala
for x in foo:
    print x
print y
""" 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:16,代碼來源:test_pygen.py

示例14: test_generate_combo

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def test_generate_combo(self):
        block = \
"""
                x = 5 +6
                if x > 7:
                    for y in range(1,5):
                        print "<td>%s</td>" % y
                    print "hi"
                print "there"
                foo(lala)
"""
        stream = StringIO()
        printer = PythonPrinter(stream)
        printer.writeline("import lala")
        printer.writeline("for x in foo:")
        printer.writeline("print x")
        printer.write_indented_block(block)
        printer.writeline(None)
        printer.writeline("print y")
        printer.close()
        #print "->" + stream.getvalue().replace(' ', '#') + "<-"
        eq_(stream.getvalue(),
"""import lala
for x in foo:
    print x

    x = 5 +6
    if x > 7:
        for y in range(1,5):
            print "<td>%s</td>" % y
        print "hi"
    print "there"
    foo(lala)

print y
""") 
開發者ID:jhpyle,項目名稱:docassemble,代碼行數:38,代碼來源:test_pygen.py

示例15: compile

# 需要導入模塊: from mako import pygen [as 別名]
# 或者: from mako.pygen import PythonPrinter [as 別名]
def compile(  # noqa
    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:remg427,項目名稱:misp42splunk,代碼行數:49,代碼來源:codegen.py


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