本文整理汇总了Python中genshi.template.markup.MarkupTemplate.generate方法的典型用法代码示例。如果您正苦于以下问题:Python MarkupTemplate.generate方法的具体用法?Python MarkupTemplate.generate怎么用?Python MarkupTemplate.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类genshi.template.markup.MarkupTemplate
的用法示例。
在下文中一共展示了MarkupTemplate.generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_latin1_encoded_explicit_encoding
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_latin1_encoded_explicit_encoding(self):
tmpl = MarkupTemplate(u"""<div xmlns:py="http://genshi.edgewall.org/">
\xf6
</div>""".encode('iso-8859-1'), encoding='iso-8859-1')
self.assertEqual(u"""<div>
\xf6
</div>""", unicode(tmpl.generate()))
示例2: test_directive_element
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_directive_element(self):
tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
<py:if test="myvar">bar</py:if>
</div>""")
self.assertEqual("""<div>
bar
</div>""", str(tmpl.generate(myvar='"foo"')))
示例3: test_template_comment
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_template_comment(self):
tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
<!-- !foo -->
<!--!bar-->
</div>""")
self.assertEqual("""<div>
</div>""", str(tmpl.generate()))
示例4: test_relative_include_without_loader_relative
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_relative_include_without_loader_relative(self):
file1 = open(os.path.join(self.dirname, "tmpl1.html"), "w")
try:
file1.write("""<div>Included</div>""")
finally:
file1.close()
file2 = open(os.path.join(self.dirname, "tmpl2.html"), "w")
try:
file2.write(
"""<html xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="tmpl1.html" />
</html>"""
)
finally:
file2.close()
tmpl = MarkupTemplate(
"""<html xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="tmpl1.html" />
</html>""",
filename=os.path.join(self.dirname, "tmpl2.html"),
)
self.assertEqual(
"""<html>
<div>Included</div>
</html>""",
tmpl.generate().render(encoding=None),
)
示例5: test_exec_import
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_exec_import(self):
tmpl = MarkupTemplate("""<?python from datetime import timedelta ?>
<div xmlns:py="http://genshi.edgewall.org/">
${timedelta(days=2)}
</div>""")
self.assertEqual("""<div>
2 days, 0:00:00
</div>""", str(tmpl.generate()))
示例6: test_latin1_encoded_with_xmldecl
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_latin1_encoded_with_xmldecl(self):
tmpl = MarkupTemplate(u"""<?xml version="1.0" encoding="iso-8859-1" ?>
<div xmlns:py="http://genshi.edgewall.org/">
\xf6
</div>""".encode('iso-8859-1'), encoding='iso-8859-1')
self.assertEqual(u"""<?xml version="1.0" encoding="iso-8859-1"?>\n<div>
\xf6
</div>""", unicode(tmpl.generate()))
示例7: render
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def render(self, namespace, **options):
# import genshi only here because this package is optional
from genshi.template.markup import MarkupTemplate
template = MarkupTemplate(self.text)
stream = template.generate(**namespace)
# enforce conversion to unicode
options['encoding'] = None
rendered_template = stream.render(**options)
return rendered_template
示例8: test_parse_with_same_namespace_nested
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_parse_with_same_namespace_nested(self):
tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
<span xmlns:py="http://genshi.edgewall.org/">
</span>
</div>""")
self.assertEqual("""<div>
<span>
</span>
</div>""", str(tmpl.generate()))
示例9: test_attr_escape_quotes
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_attr_escape_quotes(self):
"""
Verify that outputting context data in attribtes escapes quotes.
"""
tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
<elem class="$myvar"/>
</div>""")
self.assertEqual("""<div>
<elem class=""foo""/>
</div>""", str(tmpl.generate(myvar='"foo"')))
示例10: test_text_noescape_quotes
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_text_noescape_quotes(self):
"""
Verify that outputting context data in text nodes doesn't escape quotes.
"""
tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
$myvar
</div>""")
self.assertEqual("""<div>
"foo"
</div>""", str(tmpl.generate(myvar='"foo"')))
示例11: test_markup_noescape
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_markup_noescape(self):
"""
Verify that outputting context data that is a `Markup` instance is not
escaped.
"""
tmpl = MarkupTemplate("""<div xmlns:py="http://genshi.edgewall.org/">
$myvar
</div>""")
self.assertEqual("""<div>
<b>foo</b>
</div>""", str(tmpl.generate(myvar=Markup('<b>foo</b>'))))
示例12: test_exec_def
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_exec_def(self):
tmpl = MarkupTemplate("""
<?python
def foo():
return 42
?>
<div xmlns:py="http://genshi.edgewall.org/">
${foo()}
</div>""")
self.assertEqual("""<div>
42
</div>""", str(tmpl.generate()))
示例13: test_exec_in_match
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_exec_in_match(self):
xml = ("""<html xmlns:py="http://genshi.edgewall.org/">
<py:match path="body/p">
<?python title="wakka wakka wakka" ?>
${title}
</py:match>
<body><p>moot text</p></body>
</html>""")
tmpl = MarkupTemplate(xml, filename='test.html', allow_exec=True)
self.assertEqual("""<html>
<body>
wakka wakka wakka
</body>
</html>""", tmpl.generate().render(encoding=None))
示例14: test_namespace_on_removed_elem
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_namespace_on_removed_elem(self):
"""
Verify that a namespace declaration on an element that is removed from
the generated stream does not get pushed up to the next non-stripped
element (see ticket #107).
"""
tmpl = MarkupTemplate("""<?xml version="1.0"?>
<Test xmlns:py="http://genshi.edgewall.org/">
<Size py:if="0" xmlns:t="test">Size</Size>
<Item/>
</Test>""")
self.assertEqual("""<?xml version="1.0"?>\n<Test>
<Item/>
</Test>""", str(tmpl.generate()))
示例15: test_relative_include_from_inmemory_template
# 需要导入模块: from genshi.template.markup import MarkupTemplate [as 别名]
# 或者: from genshi.template.markup.MarkupTemplate import generate [as 别名]
def test_relative_include_from_inmemory_template(self):
file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w')
try:
file1.write("""<div>Included</div>""")
finally:
file1.close()
loader = TemplateLoader([self.dirname])
tmpl2 = MarkupTemplate("""<html xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="../tmpl1.html" />
</html>""", filename='subdir/tmpl2.html', loader=loader)
self.assertEqual("""<html>
<div>Included</div>
</html>""", tmpl2.generate().render())