コード例 #1
0
ファイル: html.py プロジェクト: chronossc/bag
def _substitute_entity(match):
    ent = match.group(3)
    if match.group(1) == "#":        # decode by number
        if match.group(2) == '':     # number is decimal
            return chr(int(ent))
        elif match.group(2) == 'x':  # number is hex
            return chr(int('0x' + ent, 16))
    else:
        cp = name2codepoint.get(ent)  # decode by name
        if cp:
            return chr(cp)
        else:
            return match.group()
コード例 #2
0
ファイル: html.py プロジェクト: cicide/GeoGallery
def _substitute_entity(match):
    ent = match.group(3)
    if match.group(1) == "#":  # decode by number
        if match.group(2) == '':  # number is decimal
            return chr(int(ent))
        elif match.group(2) == 'x':  # number is hex
            return chr(int('0x' + ent, 16))
    else:
        cp = name2codepoint.get(ent)  # decode by name
        if cp:
            return chr(cp)
        else:
            return match.group()
コード例 #3
0
ファイル: test_xml.py プロジェクト: ollyc/kajiki
 def test_html_entities(self):
     source = "<div>Spam&nbsp;Spam &lt; Spam &gt; Spam</div>"
     output = '<div>Spam Spam &lt; Spam &gt; Spam</div>'
     assert chr(32) in output  # normal space
     assert chr(160) in output  # non breaking space
     perform(source, output)
コード例 #4
0
 def test_html_entities(self):
     source = "<div>Spam&nbsp;Spam &lt; Spam &gt; Spam</div>"
     output = '<div>Spam Spam &lt; Spam &gt; Spam</div>'
     assert chr(32) in output  # normal space
     assert chr(160) in output  # non breaking space
     perform(source, output)