本文整理汇总了Python中genshi.core.Stream.render方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.render方法的具体用法?Python Stream.render怎么用?Python Stream.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类genshi.core.Stream
的用法示例。
在下文中一共展示了Stream.render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: extract_javascript_script
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def extract_javascript_script(fileobj, keywords, comment_tags, options):
"""Extract messages from Javascript embedding in <script> tags.
Select <script type="javascript/text"> tags and delegate to
`extract_javascript`.
"""
from genshi.core import Stream
from genshi.input import XMLParser
out = StringIO()
stream = Stream(XMLParser(fileobj))
stream = stream.select('//script[@type="text/javascript"]')
stream.render(out=out, encoding='utf-8')
out.seek(0)
return extract_javascript(out, keywords, comment_tags, options)
示例2: test_doctype_in_stream_no_sysid
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_doctype_in_stream_no_sysid(self):
stream = Stream([(Stream.DOCTYPE,
('html', '-//W3C//DTD HTML 4.01//EN', None),
(None, -1, -1))])
output = stream.render(XMLSerializer, encoding=None)
self.assertEqual('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">\n',
output)
示例3: test_doctype_in_stream
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_doctype_in_stream(self):
stream = Stream([(Stream.DOCTYPE, DocType.HTML_STRICT, (None, -1, -1))])
output = stream.render(XMLSerializer, encoding=None)
self.assertEqual('<!DOCTYPE html PUBLIC '
'"-//W3C//DTD HTML 4.01//EN" '
'"http://www.w3.org/TR/html4/strict.dtd">\n',
output)
示例4: test_xml_decl_dropped
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_xml_decl_dropped(self):
stream = Stream([(Stream.XML_DECL, ('1.0', None, -1), (None, -1, -1))])
output = stream.render(XHTMLSerializer, doctype='xhtml', encoding=None)
self.assertEqual('<!DOCTYPE html PUBLIC '
'"-//W3C//DTD XHTML 1.0 Strict//EN" '
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n',
output)
示例5: test_serializer_doctype
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_serializer_doctype(self):
stream = Stream([])
output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT)
self.assertEqual('<!DOCTYPE html PUBLIC '
'"-//W3C//DTD HTML 4.01//EN" '
'"http://www.w3.org/TR/html4/strict.dtd">\n',
output)
示例6: test_with_xml_decl
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_with_xml_decl(self):
stream = Stream([(Stream.XML_DECL, ('1.0', None, -1), (None, -1, -1))])
output = stream.render(XMLSerializer, doctype='xhtml')
self.assertEqual('<?xml version="1.0"?>\n'
'<!DOCTYPE html PUBLIC '
'"-//W3C//DTD XHTML 1.0 Strict//EN" '
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n',
output)
示例7: test_doctype_one_and_only
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_doctype_one_and_only(self):
stream = Stream([
(Stream.DOCTYPE, ('html', None, None), (None, -1, -1))
])
output = stream.render(XMLSerializer, doctype=DocType.HTML_STRICT)
self.assertEqual('<!DOCTYPE html PUBLIC '
'"-//W3C//DTD HTML 4.01//EN" '
'"http://www.w3.org/TR/html4/strict.dtd">\n',
output)
示例8: test_doctype_in_stream_no_pubid
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_doctype_in_stream_no_pubid(self):
stream = Stream([
(Stream.DOCTYPE,
('html', None, 'http://www.w3.org/TR/html4/strict.dtd'),
(None, -1, -1))
])
output = stream.render(XMLSerializer, encoding=None)
self.assertEqual('<!DOCTYPE html SYSTEM '
'"http://www.w3.org/TR/html4/strict.dtd">\n',
output)
示例9: test_cache_markup
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_cache_markup(self):
loc = (None, -1, -1)
stream = Stream([(Stream.START, (QName('foo'), Attrs()), loc),
(Stream.TEXT, u'…', loc),
(Stream.END, QName('foo'), loc),
(Stream.START, (QName('bar'), Attrs()), loc),
(Stream.TEXT, Markup('…'), loc),
(Stream.END, QName('bar'), loc)])
output = stream.render(XMLSerializer, encoding=None,
strip_whitespace=False)
self.assertEqual('<foo>&hellip;</foo><bar>…</bar>', output)
示例10: test_multiple_bound_namespaces
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_multiple_bound_namespaces(self):
stream = Stream([
(Stream.START, (QName('div'), Attrs()), (None, -1, -1)),
(Stream.TEXT, '\n ', (None, -1, -1)),
(Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)),
(Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)),
(Stream.END, QName('http://example.org/}p'), (None, -1, -1)),
(Stream.END_NS, 'x', (None, -1, -1)),
(Stream.TEXT, '\n ', (None, -1, -1)),
(Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)),
(Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)),
(Stream.END, QName('http://example.org/}p'), (None, -1, -1)),
(Stream.END_NS, 'x', (None, -1, -1)),
(Stream.TEXT, '\n ', (None, -1, -1)),
(Stream.END, QName('div'), (None, -1, -1)),
])
output = stream.render(XMLSerializer, encoding=None)
self.assertEqual("""<div>
<x:p xmlns:x="http://example.org/"/>
<x:p xmlns:x="http://example.org/"/>
</div>""", output)
示例11: test_nested_default_namespaces
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_nested_default_namespaces(self):
stream = Stream([
(Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)),
(Stream.START, (QName('http://example.org/}div'), Attrs()), (None, -1, -1)),
(Stream.TEXT, '\n ', (None, -1, -1)),
(Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)),
(Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)),
(Stream.END, QName('http://example.org/}p'), (None, -1, -1)),
(Stream.END_NS, '', (None, -1, -1)),
(Stream.TEXT, '\n ', (None, -1, -1)),
(Stream.START_NS, ('', 'http://example.org/'), (None, -1, -1)),
(Stream.START, (QName('http://example.org/}p'), Attrs()), (None, -1, -1)),
(Stream.END, QName('http://example.org/}p'), (None, -1, -1)),
(Stream.END_NS, '', (None, -1, -1)),
(Stream.TEXT, '\n ', (None, -1, -1)),
(Stream.END, QName('http://example.org/}div'), (None, -1, -1)),
(Stream.END_NS, '', (None, -1, -1))
])
output = stream.render(XMLSerializer, encoding=None)
self.assertEqual("""<div xmlns="http://example.org/">
<p/>
<p/>
</div>""", output)
示例12: test_nested_bound_namespaces
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_nested_bound_namespaces(self):
stream = Stream([
(Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)),
(Stream.START, (QName('div'), Attrs()), (None, -1, -1)),
(Stream.TEXT, '\n ', (None, -1, -1)),
(Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)),
(Stream.START, (QName('p'), Attrs()), (None, -1, -1)),
(Stream.END, QName('p'), (None, -1, -1)),
(Stream.END_NS, 'x', (None, -1, -1)),
(Stream.TEXT, '\n ', (None, -1, -1)),
(Stream.START_NS, ('x', 'http://example.org/'), (None, -1, -1)),
(Stream.START, (QName('p'), Attrs()), (None, -1, -1)),
(Stream.END, QName('p'), (None, -1, -1)),
(Stream.END_NS, 'x', (None, -1, -1)),
(Stream.TEXT, '\n ', (None, -1, -1)),
(Stream.END, QName('div'), (None, -1, -1)),
(Stream.END_NS, 'x', (None, -1, -1))
])
output = stream.render(XHTMLSerializer)
self.assertEqual("""<div xmlns:x="http://example.org/">
<p></p>
<p></p>
</div>""", output)
示例13: test_processing_instruction
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_processing_instruction(self):
stream = Stream([(Stream.PI, ('python', 'x = 2'), (None, -1, -1))])
output = stream.render(XMLSerializer, encoding=None)
self.assertEqual('<?python x = 2?>', output)
示例14: test_comment
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_comment(self):
stream = Stream([(Stream.COMMENT, 'foo bar', (None, -1, -1))])
output = stream.render(XMLSerializer, encoding=None)
self.assertEqual('<!--foo bar-->', output)
示例15: test_doctype_in_stream_no_pubid_or_sysid
# 需要导入模块: from genshi.core import Stream [as 别名]
# 或者: from genshi.core.Stream import render [as 别名]
def test_doctype_in_stream_no_pubid_or_sysid(self):
stream = Stream([(Stream.DOCTYPE, ('html', None, None),
(None, -1, -1))])
output = stream.render(XMLSerializer, encoding=None)
self.assertEqual('<!DOCTYPE html>\n', output)