Skip to content

Commit 602f028

Browse files
committed
web: use html.unescape() when available (Python 3.4+)
1 parent e655564 commit 602f028

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

sopel/tools/web.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
unichr = chr
3535
unicode = str
3636

37+
try:
38+
import html as HTMLLib
39+
except ImportError:
40+
HTMLLib = None
41+
3742
__all__ = [
3843
'USER_AGENT',
3944
'DEFAULT_HEADERS',
@@ -121,6 +126,12 @@ def decode(html):
121126
:param str html: the HTML page or snippet to process
122127
:return str: ``html`` with all entity references replaced
123128
"""
129+
if HTMLLib is not None:
130+
# Python's stdlib has our back in 3.4+
131+
# TODO: This should be the only implementation in Sopel 8
132+
return HTMLLib.unescape(html)
133+
134+
# Not on py3.4+ yet? Then you get to deal with the jankiness.
124135
return r_entity.sub(entity, html)
125136

126137

0 commit comments

Comments
 (0)