python3: add polyglot wrapper for html.entities/htmlentitydefs

This commit is contained in:
Eli Schwartz 2019-03-25 10:27:57 -04:00
parent b62022ac7d
commit d7410fe7b3
No known key found for this signature in database
GPG key ID: CEB167EFB5722BD6
3 changed files with 14 additions and 3 deletions

View file

@ -614,7 +614,7 @@ def check(ch):
return check(html5_entities[ent])
except KeyError:
pass
from htmlentitydefs import name2codepoint
from polyglot.html_entities import name2codepoint
try:
return check(my_unichr(name2codepoint[ent]))
except KeyError:

View file

@ -2,8 +2,9 @@
__copyright__ = '2010, sengian <sengian1@gmail.com>'
__docformat__ = 'restructuredtext en'
import re, htmlentitydefs
import re
from polyglot.builtins import codepoint_to_chr, map, range
from polyglot.html_entities import name2codepoint
from calibre.constants import plugins, preferred_encoding
try:
@ -80,7 +81,7 @@ def fixup(m, rm=rm, rchar=rchar):
else:
# named entity
try:
text = codepoint_to_chr(htmlentitydefs.name2codepoint[text[1:-1]])
text = codepoint_to_chr(name2codepoint[text[1:-1]])
except KeyError:
pass
if rm:

View file

@ -0,0 +1,10 @@
#!/usr/bin/env python2
# vim:fileencoding=utf-8
# License: GPL v3 Copyright: 2019, Eli Schwartz <eschwartz@archlinux.org>
from polyglot.builtins import is_py3
if is_py3:
from html.entities import name2codepoint
else:
from htmlentitydefs import name2codepoint