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


Python html.htmlfile函数代码示例

本文整理汇总了Python中translate.storage.html.htmlfile函数的典型用法代码示例。如果您正苦于以下问题:Python htmlfile函数的具体用法?Python htmlfile怎么用?Python htmlfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了htmlfile函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_escaping_script_and_pre

 def test_escaping_script_and_pre(self):
     """<script> and <pre> can contain < and > and these should not be
     interpretted as tags"""
     h = html.htmlfile()
     store = h.parsestring("<p>We are here</p><script>Some </tag>like data<script></p>")
     print store.units[0].source
     assert len(store.units) == 1
开发者ID:AshishNamdev,项目名称:verbatim,代码行数:7,代码来源:test_html.py

示例2: mergestore

 def mergestore(self, inputstore, templatetext, includefuzzy):
     """converts a file to .po format"""
     self.inputstore = inputstore
     self.inputstore.makeindex()
     self.includefuzzy = includefuzzy
     output_store = html.htmlfile(inputfile=templatetext, callback=self.lookup)
     return output_store.filesrc
开发者ID:andynicholson,项目名称:translate,代码行数:7,代码来源:po2html.py

示例3: test_extraction_attr_title

    def test_extraction_attr_title(self):
        """Check that we can extract title attribute"""
        h = html.htmlfile()

        # Example form http://www.w3schools.com/tags/att_global_title.asp
        store = h.parsestring("""
            <p><abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>
            <p title="Free Web tutorials">W3Schools.com</p>""")
        print(store.units[0].source)
        assert len(store.units) == 4
        assert store.units[0].source == "World Health Organization"
        # FIXME this is not ideal we need to either drop title= as we've
        # extracted it already or not extract it earlier
        assert store.units[1].source == '<abbr title="World Health Organization">WHO</abbr> was founded in 1948.'
        assert store.units[2].source == "Free Web tutorials"
        assert store.units[3].source == "W3Schools.com"

        # Example from http://www.netmechanic.com/news/vol6/html_no1.htm
        store = h.parsestring("""
            <table width="100" border="2" title="Henry Jacobs Camp summer 2003 schedule">
        """)
        assert len(store.units) == 1
        assert store.units[0].source == "Henry Jacobs Camp summer 2003 schedule"
        # FIXME this doesn't extract as I'd have expected
        #store = h.parsestring("""
        #    <a href="page1.html" title="HS Jacobs - a UAHC camp in Utica, MS">Henry S. Jacobs Camp</a>
        #""")
        #assert len(store.units) == 2
        #assert store.units[0].source == "HS Jacobs - a UAHC camp in Utica, MS"
        #assert store.units[1].source == "Henry S. Jacobs Camp"
        store = h.parsestring("""
            <form name="application" title="Henry Jacobs camper application" method="  " action="  ">
        """)
        assert len(store.units) == 1
        assert store.units[0].source == "Henry Jacobs camper application"
开发者ID:XLeonardo,项目名称:translate-1,代码行数:35,代码来源:test_html.py

示例4: test_extraction_attr_alt

 def test_extraction_attr_alt(self):
     """Check that we can extract title attribute"""
     h = html.htmlfile()
     # Example from http://www.netmechanic.com/news/vol6/html_no1.htm
     store = h.parsestring("""
         <img src="cafeteria.jpg" height="200" width="200" alt="UAHC campers enjoy a meal in the camp cafeteria">
     """)
     assert len(store.units) == 1
     assert store.units[0].source == "UAHC campers enjoy a meal in the camp cafeteria"
开发者ID:XLeonardo,项目名称:translate-1,代码行数:9,代码来源:test_html.py

示例5: convertfile

 def convertfile(self, inputfile, filename, includeuntagged=False,
                 duplicatestyle="msgctxt", keepcomments=False):
     """converts a html file to .po format"""
     thetargetfile = po.pofile()
     htmlparser = html.htmlfile(includeuntaggeddata=includeuntagged,
                                inputfile=inputfile)
     for htmlunit in htmlparser.units:
         thepo = thetargetfile.addsourceunit(htmlunit.source)
         thepo.addlocations(htmlunit.getlocations())
         if keepcomments:
             thepo.addnote(htmlunit.getnotes(), "developer")
     thetargetfile.removeduplicates(duplicatestyle)
     return thetargetfile
开发者ID:asyschikov,项目名称:translate,代码行数:13,代码来源:html2po.py

示例6: test_extraction_tag_figcaption

 def test_extraction_tag_figcaption(self):
     """Check that we can extract figcaption"""
     h = html.htmlfile()
     # Example form http://www.w3schools.com/tags/tag_figcaption.asp
     store = h.parsestring("""
            <figure>
                <img src="img_pulpit.jpg" alt="The Pulpit Rock" width="304" height="228">
                <figcaption>Fig1. - A view of the pulpit rock in Norway.</figcaption>
            </figure>""")
     print(store.units[0].source)
     assert len(store.units) == 2
     assert store.units[0].source == "The Pulpit Rock"
     assert store.units[1].source == "Fig1. - A view of the pulpit rock in Norway."
开发者ID:XLeonardo,项目名称:translate-1,代码行数:13,代码来源:test_html.py

示例7: test_extraction_tag_caption_td_th

 def test_extraction_tag_caption_td_th(self):
     """Check that we can extract table related translatable: th, td and caption"""
     h = html.htmlfile()
     # Example form http://www.w3schools.com/tags/tag_caption.asp
     store = h.parsestring("""
         <table>
             <caption>Monthly savings</caption>
             <tr>
                 <th>Month</th>
                 <th>Savings</th>
             </tr>
             <tr>
                 <td>January</td>
                 <td>$100</td>
             </tr>
         </table>""")
     print(store.units[0].source)
     assert len(store.units) == 5
     assert store.units[0].source == "Monthly savings"
     assert store.units[1].source == "Month"
     assert store.units[2].source == "Savings"
     assert store.units[3].source == "January"
     assert store.units[4].source == "$100"
开发者ID:XLeonardo,项目名称:translate-1,代码行数:23,代码来源:test_html.py

示例8: test_self_closing_tags

 def test_self_closing_tags(self):
     h = html.htmlfile()
     store = h.parsestring("<h3>Some text <img><br><img></h3>")
     assert len(store.units) == 1
开发者ID:AshishNamdev,项目名称:verbatim,代码行数:4,代码来源:test_html.py

示例9: test_pi_escaping

def test_pi_escaping():
    h = html.htmlfile()
    assert h.pi_escape('<a href="<?=($a < $b ? $foo : ($b > c ? $bar : $cat))?>">') == '<a href="<?=($a %lt; $b ? $foo : ($b %gt; c ? $bar : $cat))?>">'
开发者ID:AshishNamdev,项目名称:verbatim,代码行数:3,代码来源:test_html.py

示例10: test_strip_html_with_pi

def test_strip_html_with_pi():
    h = html.htmlfile()
    assert html.strip_html(h.pi_escape('<a href="<?$var?>">Something</a>')) == "Something"
    assert html.strip_html(h.pi_escape('<a href="<?=($a < $b ? $foo : ($b > c ? $bar : $cat))?>">Something</a>')) == "Something"
开发者ID:AshishNamdev,项目名称:verbatim,代码行数:4,代码来源:test_html.py

示例11: test_guess_encoding

def test_guess_encoding():
    """Read an encoding header to guess the encoding correctly"""
    h = html.htmlfile()
    assert h.guess_encoding('''<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8">''') == "UTF-8"
    assert h.guess_encoding('''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><!-- base href="http://home.online.no/~rut-aane/linux.html" --><link rel="shortcut icon" href="http://home.online.no/~rut-aane/peng16x16a.gif"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta name="Description" content="Linux newbie stuff and a little about Watching TV under Linux"><meta name="MSSmartTagsPreventParsing" content="TRUE"><meta name="GENERATOR" content="Mozilla/4.7 [en] (X11; I; Linux 2.2.5-15 i586) [Netscape]"><title>Some Linux for beginners</title><style type="text/css">''') == "iso-8859-1"
开发者ID:AshishNamdev,项目名称:verbatim,代码行数:5,代码来源:test_html.py


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