33applications, APIs, or websites in your plugins.
44
55.. versionadded:: 7.0
6-
7- .. note::
8- Some parts of this module will remain accessible through ``sopel.web`` as
9- well until its final removal in Sopel 8. This is for backward
10- compatibility only; please update old code as soon as possible.
116"""
127# Copyright © 2008, Sean B. Palmer, inamidst.com
138# Copyright © 2009, Michael Yanovich <[email protected] > 1813
1914from __future__ import generator_stop
2015
16+ import html
2117from html .entities import name2codepoint
2218import re
2319import urllib
2420from urllib .parse import urlparse , urlunparse
2521
26- from sopel import __version__
22+ from sopel import __version__ , tools
2723
2824
2925__all__ = [
8581
8682
8783r_entity = re .compile (r'&([^;\s]+);' )
88- """Regular expression to match HTML entities."""
84+ """Regular expression to match HTML entities.
85+
86+ .. deprecated:: 8.0
87+
88+ Will be removed in Sopel 9, along with :func:`entity`.
89+ """
8990
9091
92+ @tools .deprecated (
93+ version = '8.0' ,
94+ removed_in = '9.0' ,
95+ reason = "No longer needed now that Python 3.4+ has `html.unescape()`" ,
96+ )
9197def entity (match ):
9298 """Convert an entity reference to the appropriate character.
9399
@@ -96,6 +102,12 @@ def entity(match):
96102 :return str: the Unicode character corresponding to the given ``match``
97103 string, or a fallback representation if the reference cannot be
98104 resolved to a character
105+
106+ .. deprecated:: 8.0
107+
108+ Will be removed in Sopel 9. Use :func:`decode` directly or migrate to
109+ Python's standard-library equivalent, :func:`html.unescape`.
110+
99111 """
100112 value = match .group (1 ).lower ()
101113 if value .startswith ('#x' ):
@@ -107,13 +119,20 @@ def entity(match):
107119 return '[' + value + ']'
108120
109121
110- def decode (html ):
122+ def decode (text ):
111123 """Decode HTML entities into Unicode text.
112124
113- :param str html: the HTML page or snippet to process
114- :return str: ``html`` with all entity references replaced
125+ :param str text: the HTML page or snippet to process
126+ :return str: ``text`` with all entity references replaced
127+
128+ .. versionchanged:: 8.0
129+
130+ Renamed ``html`` parameter to ``text``. (Python gained a standard
131+ library module named :mod:`html` in version 3.4.)
132+
115133 """
116- return r_entity .sub (entity , html )
134+ # TODO deprecated?
135+ return html .unescape (text )
117136
118137
119138def quote (string , safe = '/' ):
0 commit comments