Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions sopel/tools/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
unichr = chr
unicode = str

try:
import html as HTMLLib
except ImportError:
HTMLLib = None

__all__ = [
'USER_AGENT',
'DEFAULT_HEADERS',
Expand Down Expand Up @@ -121,6 +126,16 @@ def decode(html):
:param str html: the HTML page or snippet to process
:return str: ``html`` with all entity references replaced
"""
if HTMLLib is not None:
# Python's stdlib has our back in 3.4+
# TODO: This should be the only implementation in Sopel 8
try:
return HTMLLib.unescape(html)
except AttributeError:
# Must be py3.3; fall through to our half-assed version.
pass

# Not on py3.4+ yet? Then you get to deal with the jankiness.
return r_entity.sub(entity, html)


Expand Down