本文整理汇总了Python中genshi.core.Stream类的典型用法代码示例。如果您正苦于以下问题:Python Stream类的具体用法?Python Stream怎么用?Python Stream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Stream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_doctype_in_stream
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)
示例2: test_doctype_in_stream_no_sysid
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_serializer_doctype
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)
示例4: helper
def helper(field_stream):
s = Stream(field_stream)
f = s.select('//strong/text()').textOf()
if field != f: #if we are the field just skip it
#identity stream filter
for kind, data, pos in s:
yield kind, data, pos
示例5: test_xml_decl_dropped
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)
示例6: test_with_xml_decl
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
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
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
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: extract_javascript_script
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.select('//script[@type="text/javascript"]').render(out=out)
out.seek(0)
return extract_javascript(out, keywords, comment_tags, options)
示例11: helper
def helper(field_stream):
try:
s = Stream(field_stream)
self.log.debug('ChangeLog Pre')
# without None as the second value we get str instead of unicode
# and that causes things to break sometimes
f = s.select('//strong/text()').textOf(strip_markup=True).lower()
# self.log.debug(u'ChangeLog Pre 2 : %s: %r', type(f), f)
self.log.debug('ChangeLog Filter: field:%s, label:%s, we are looking at:%r, skip?%s',
field, check, f, check == f )
if check != f: #if we are the field just skip it
#identity stream filter
for kind, data, pos in s:
yield kind, data, pos
except Exception, e:
self.log.exception('ChangeLog: Stream Filter Exception');
raise e
示例12: setUp
def setUp(self):
env = EnvironmentStub(enable=[Chrome, PatchRenderer])
req = Mock(base_path='', chrome={'static_hash': None}, args={},
session={}, abs_href=Href('/'), href=Href('/'), locale='',
perm=MockPerm(), authname=None, tz=None)
self.context = web_context(req)
self.patch = Mimeview(env).renderers[0]
patch_html = open(os.path.join(os.path.split(__file__)[0],
'patch.html'))
self.patch_html = Stream(list(HTMLParser(patch_html, encoding='utf-8')))
示例13: setUp
def setUp(self):
env = EnvironmentStub(enable=[Chrome, PatchRenderer])
req = Mock(base_path='', chrome={}, args={}, session={},
abs_href=Href('/'), href=Href('/'),
perm=MockPerm(), authname=None, tz=None)
self.context = Context.from_request(req)
self.patch = Mimeview(env).renderers[0]
patch_html = open(os.path.join(os.path.split(__file__)[0],
'patch.html'))
self.patch_html = Stream(list(HTMLParser(patch_html)))
示例14: setUp
def setUp(self):
self.env = EnvironmentStub(enable=[Chrome, PygmentsRenderer])
self.pygments = Mimeview(self.env).renderers[0]
self.req = Mock(base_path='', chrome={}, args={},
abs_href=Href('/'), href=Href('/'),
session={}, perm=None, authname=None, tz=None)
self.context = web_context(self.req)
pygments_html = open(os.path.join(os.path.split(__file__)[0],
'pygments.html'))
self.pygments_html = Stream(list(HTMLParser(pygments_html, encoding='utf-8')))
示例15: test_multiple_bound_namespaces
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)