File tree 1 file changed +9
-9
lines changed
1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 9
9
from html import escape as html_escape
10
10
11
11
12
- class HTMLParseError (Exception ):
12
+ class HTMLParseError (ValueError ):
13
13
pass
14
14
15
15
@@ -42,11 +42,6 @@ def handle_data(self, d):
42
42
if not self .strip_tag_contents_mode :
43
43
self .fed .append (d )
44
44
45
- if (3 ,) <= sys .version_info < (3 , 10 ):
46
-
47
- def error (self , message ):
48
- raise HTMLParseError (message )
49
-
50
45
def handle_entityref (self , d ):
51
46
try :
52
47
val = chr (name2codepoint [d ])
@@ -69,12 +64,17 @@ def strip_tags(html: str) -> str:
69
64
"""
70
65
s = HTMLTagStripper ()
71
66
67
+ # `HTMLParser.feed()` raises `AssertionError` if fed invalid HTML.
68
+ # See the source at https://github.com/python/cpython/blob/main/Lib/html/parser.py
69
+ # and https://github.com/python/cpython/blob/main/Lib/_markupbase.py#L30.
70
+ # We want to catch this exception and raise a more informative exception to
71
+ # tell it apart from general `AssertionError`s that normally mean a programmer error.
72
+ # Those are later caught in `Message.calculate_html_snippet` so it can recover from
73
+ # invalid HTML.
72
74
try :
73
75
s .feed (html )
74
76
except AssertionError as e :
75
- if e .args [0 ].startswith ("unknown status keyword" ):
76
- raise HTMLParseError (* e .args ) from e
77
- raise
77
+ raise HTMLParseError (* e .args ) from e
78
78
79
79
return s .get_data ()
80
80
You can’t perform that action at this time.
0 commit comments