mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
python3: add polyglot wrapper for html.entities/htmlentitydefs
This commit is contained in:
parent
b62022ac7d
commit
d7410fe7b3
@ -614,7 +614,7 @@ def entity_to_unicode(match, exceptions=[], encoding='cp1252',
|
||||
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:
|
||||
|
@ -2,8 +2,9 @@ __license__ = 'GPL 3'
|
||||
__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 unescape(text, rm=False, rchar=u''):
|
||||
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:
|
||||
|
10
src/polyglot/html_entities.py
Normal file
10
src/polyglot/html_entities.py
Normal 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
|
Loading…
x
Reference in New Issue
Block a user