本文整理汇总了Python中genshi.input.HTML.filter方法的典型用法代码示例。如果您正苦于以下问题:Python HTML.filter方法的具体用法?Python HTML.filter怎么用?Python HTML.filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类genshi.input.HTML
的用法示例。
在下文中一共展示了HTML.filter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_translate_included_attribute_text
# 需要导入模块: from genshi.input import HTML [as 别名]
# 或者: from genshi.input.HTML import filter [as 别名]
def test_translate_included_attribute_text(self):
"""
Verify that translated attributes end up in a proper `Attrs` instance.
"""
html = HTML("""<html>
<span title="Foo"></span>
</html>""")
translator = Translator(lambda s: u"Voh")
stream = list(html.filter(translator))
kind, data, pos = stream[2]
assert isinstance(data[1], Attrs)
示例2: send_html_response
# 需要导入模块: from genshi.input import HTML [as 别名]
# 或者: from genshi.input.HTML import filter [as 别名]
def send_html_response(self, handler, html_file, code=200, html_form_data={}, **kwargs):
""" Generates and sends an HTML response.
This generates headers and an HTML response either from the specified HTML
source or HTML file. Both will be parsed using the Genhsi template engine
and will be extended with the default template.
Args:
handler: References the handler of the current http request.
code: Defines the response code is send within the http headers,
by default, responde code 200 (success) is sent.
html_file: Must reference a HTML document within the current
document root or the plugin directory that will be loaded and
parsed using Genshi.
html_form_data: Pass additional html form data to auto-fill html forms
using genshi.filters.HTMLFormFiller.
**kwargs: Any additional parameter will be forwarded to the Genshi
template.
"""
handler.send_response(code=code)
handler.send_header("Content-type", 'text/html')
handler.end_headers()
# Add additional template parameters
kwargs["plugin"] = self.__module__
template_path = os.path.dirname(__file__) + os.sep + \
"assets" + os.sep + "html" + os.sep + "index.html"
fd = open(template_path)
template = MarkupTemplate(fd, template_path)
fd.close()
filler = HTMLFormFiller(data=html_form_data)
# See http://stackoverflow.com/questions/1555644/can-one-prevent-genshi-from-parsing-html-entities
# because of "us-ascii" encoding.
html = HTML(self.template.load(html_file).generate(**kwargs).render(encoding= 'us-ascii'))
template = template.generate(Context(input=html.filter(filler), **kwargs))
handler.wfile.write(template.render('xhtml', doctype='html', encoding= 'us-ascii'))