diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index 867163fc2b..c71af8e0f4 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -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: diff --git a/src/calibre/utils/cleantext.py b/src/calibre/utils/cleantext.py index 9e04d5d4d6..f8ba151de3 100644 --- a/src/calibre/utils/cleantext.py +++ b/src/calibre/utils/cleantext.py @@ -2,8 +2,9 @@ __license__ = 'GPL 3' __copyright__ = '2010, sengian ' __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: diff --git a/src/polyglot/html_entities.py b/src/polyglot/html_entities.py new file mode 100644 index 0000000000..2e20eee7f4 --- /dev/null +++ b/src/polyglot/html_entities.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python2 +# vim:fileencoding=utf-8 +# License: GPL v3 Copyright: 2019, Eli Schwartz + +from polyglot.builtins import is_py3 + +if is_py3: + from html.entities import name2codepoint +else: + from htmlentitydefs import name2codepoint