当前位置: 首页>>代码示例>>Python>>正文


Python HTML.filter方法代码示例

本文整理汇总了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)
开发者ID:alon,项目名称:polinax,代码行数:13,代码来源:i18n.py

示例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'))
开发者ID:homecontrol,项目名称:server,代码行数:43,代码来源:bootstrap.py


注:本文中的genshi.input.HTML.filter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。