本文整理汇总了Python中mako.compat.StringIO方法的典型用法代码示例。如果您正苦于以下问题:Python compat.StringIO方法的具体用法?Python compat.StringIO怎么用?Python compat.StringIO使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mako.compat
的用法示例。
在下文中一共展示了compat.StringIO方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _render
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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()
示例2: test_generate_normal
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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
"""
)
示例3: test_generate_adjusted
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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
"""
)
示例4: test_backslash_line
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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"
"""
)
示例5: test_generate_adjusted
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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
"""
示例6: test_multi_line
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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)
"""
示例7: test_false_unindentor
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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()
示例8: _render
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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()
示例9: _render
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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()
示例10: test_generate_combo
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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
""",
)
示例11: test_multi_line
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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)
"""
)
示例12: test_generate_normal
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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
"""
示例13: test_generate_combo
# 需要导入模块: from mako import compat [as 别名]
# 或者: from mako.compat import StringIO [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
""")