aboutsummaryrefslogtreecommitdiff
path: root/gnu/packages/patches/python-sgmllib3k-assertions.patch
blob: 872f1c62c90952559dfa1e3a1768fc8783c1b2a7 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
Restores compatibility with Python >=3.9,
which removed the custom .error() method in
https://github.com/python/cpython/commit/e34bbfd61f405eef89e8aa50672b0b25022de320

Despite the big diff, only a try…except clause is added.

--- source/sgmllib.py	2023-03-18 08:57:58.726240606 +0100
+++ source/sgmllib.py	2023-03-18 09:02:01.667568916 +0100
@@ -101,113 +101,116 @@
         """Handle the remaining data."""
         self.goahead(1)
 
-    def error(self, message):
-        raise SGMLParseError(message)
-
     # Internal -- handle data as far as reasonable.  May leave state
     # and data to be processed by a subsequent call.  If 'end' is
     # true, force handling all data as if followed by EOF marker.
     def goahead(self, end):
-        rawdata = self.rawdata
-        i = 0
-        n = len(rawdata)
-        while i < n:
-            if self.nomoretags:
-                self.handle_data(rawdata[i:n])
-                i = n
-                break
-            match = interesting.search(rawdata, i)
-            if match: j = match.start()
-            else: j = n
-            if i < j:
-                self.handle_data(rawdata[i:j])
-            i = j
-            if i == n: break
-            if rawdata[i] == '<':
-                if starttagopen.match(rawdata, i):
+        try:
+            rawdata = self.rawdata
+            i = 0
+            n = len(rawdata)
+            while i < n:
+                if self.nomoretags:
+                    self.handle_data(rawdata[i:n])
+                    i = n
+                    break
+                match = interesting.search(rawdata, i)
+                if match: j = match.start()
+                else: j = n
+                if i < j:
+                    self.handle_data(rawdata[i:j])
+                i = j
+                if i == n: break
+                if rawdata[i] == '<':
+                    if starttagopen.match(rawdata, i):
+                        if self.literal:
+                            self.handle_data(rawdata[i])
+                            i = i+1
+                            continue
+                        k = self.parse_starttag(i)
+                        if k < 0: break
+                        i = k
+                        continue
+                    if rawdata.startswith("</", i):
+                        k = self.parse_endtag(i)
+                        if k < 0: break
+                        i = k
+                        self.literal = 0
+                        continue
+                    if self.literal:
+                        if n > (i + 1):
+                            self.handle_data("<")
+                            i = i+1
+                        else:
+                            # incomplete
+                            break
+                        continue
+                    if rawdata.startswith("<!--", i):
+                            # Strictly speaking, a comment is --.*--
+                            # within a declaration tag <!...>.
+                            # This should be removed,
+                            # and comments handled only in parse_declaration.
+                        k = self.parse_comment(i)
+                        if k < 0: break
+                        i = k
+                        continue
+                    if rawdata.startswith("<?", i):
+                        k = self.parse_pi(i)
+                        if k < 0: break
+                        i = i+k
+                        continue
+                    if rawdata.startswith("<!", i):
+                        # This is some sort of declaration; in "HTML as
+                        # deployed," this should only be the document type
+                        # declaration ("<!DOCTYPE html...>").
+                        k = self.parse_declaration(i)
+                        if k < 0: break
+                        i = k
+                        continue
+                elif rawdata[i] == '&':
                     if self.literal:
                         self.handle_data(rawdata[i])
                         i = i+1
                         continue
-                    k = self.parse_starttag(i)
-                    if k < 0: break
-                    i = k
-                    continue
-                if rawdata.startswith("</", i):
-                    k = self.parse_endtag(i)
-                    if k < 0: break
-                    i = k
-                    self.literal = 0
-                    continue
-                if self.literal:
-                    if n > (i + 1):
-                        self.handle_data("<")
-                        i = i+1
-                    else:
-                        # incomplete
-                        break
-                    continue
-                if rawdata.startswith("<!--", i):
-                        # Strictly speaking, a comment is --.*--
-                        # within a declaration tag <!...>.
-                        # This should be removed,
-                        # and comments handled only in parse_declaration.
-                    k = self.parse_comment(i)
-                    if k < 0: break
-                    i = k
-                    continue
-                if rawdata.startswith("<?", i):
-                    k = self.parse_pi(i)
-                    if k < 0: break
-                    i = i+k
-                    continue
-                if rawdata.startswith("<!", i):
-                    # This is some sort of declaration; in "HTML as
-                    # deployed," this should only be the document type
-                    # declaration ("<!DOCTYPE html...>").
-                    k = self.parse_declaration(i)
-                    if k < 0: break
-                    i = k
-                    continue
-            elif rawdata[i] == '&':
-                if self.literal:
+                    match = charref.match(rawdata, i)
+                    if match:
+                        name = match.group(1)
+                        self.handle_charref(name)
+                        i = match.end(0)
+                        if rawdata[i-1] != ';': i = i-1
+                        continue
+                    match = entityref.match(rawdata, i)
+                    if match:
+                        name = match.group(1)
+                        self.handle_entityref(name)
+                        i = match.end(0)
+                        if rawdata[i-1] != ';': i = i-1
+                        continue
+                else:
+                    self.error('neither < nor & ??')
+                # We get here only if incomplete matches but
+                # nothing else
+                match = incomplete.match(rawdata, i)
+                if not match:
                     self.handle_data(rawdata[i])
                     i = i+1
                     continue
-                match = charref.match(rawdata, i)
-                if match:
-                    name = match.group(1)
-                    self.handle_charref(name)
-                    i = match.end(0)
-                    if rawdata[i-1] != ';': i = i-1
-                    continue
-                match = entityref.match(rawdata, i)
-                if match:
-                    name = match.group(1)
-                    self.handle_entityref(name)
-                    i = match.end(0)
-                    if rawdata[i-1] != ';': i = i-1
-                    continue
-            else:
-                self.error('neither < nor & ??')
-            # We get here only if incomplete matches but
-            # nothing else
-            match = incomplete.match(rawdata, i)
-            if not match:
-                self.handle_data(rawdata[i])
-                i = i+1
-                continue
-            j = match.end(0)
-            if j == n:
-                break # Really incomplete
-            self.handle_data(rawdata[i:j])
-            i = j
-        # end while
-        if end and i < n:
-            self.handle_data(rawdata[i:n])
-            i = n
-        self.rawdata = rawdata[i:]
-        # XXX if end: check for empty stack
+                j = match.end(0)
+                if j == n:
+                    break # Really incomplete
+                self.handle_data(rawdata[i:j])
+                i = j
+            # end while
+            if end and i < n:
+                self.handle_data(rawdata[i:n])
+                i = n
+            self.rawdata = rawdata[i:]
+            # XXX if end: check for empty stack
+        except AssertionError as e:
+            # The .error() method, which threw the custom SGMLParseError was removed
+            # by https://github.com/python/cpython/issues/76025. So we have to catch
+            # _markupbase’s AssertionError and translate it into the old one.
+            raise SGMLParseError (e.args[0]) from e
 
     # Extensions for the DOCTYPE scanner:
     _decl_otherchars = '='