annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/html/parser.py @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
rev   line source
jpayne@68 1 """A parser for HTML and XHTML."""
jpayne@68 2
jpayne@68 3 # This file is based on sgmllib.py, but the API is slightly different.
jpayne@68 4
jpayne@68 5 # XXX There should be a way to distinguish between PCDATA (parsed
jpayne@68 6 # character data -- the normal case), RCDATA (replaceable character
jpayne@68 7 # data -- only char and entity references and end tags are special)
jpayne@68 8 # and CDATA (character data -- only end tags are special).
jpayne@68 9
jpayne@68 10
jpayne@68 11 import re
jpayne@68 12 import warnings
jpayne@68 13 import _markupbase
jpayne@68 14
jpayne@68 15 from html import unescape
jpayne@68 16
jpayne@68 17
jpayne@68 18 __all__ = ['HTMLParser']
jpayne@68 19
jpayne@68 20 # Regular expressions used for parsing
jpayne@68 21
jpayne@68 22 interesting_normal = re.compile('[&<]')
jpayne@68 23 incomplete = re.compile('&[a-zA-Z#]')
jpayne@68 24
jpayne@68 25 entityref = re.compile('&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]')
jpayne@68 26 charref = re.compile('&#(?:[0-9]+|[xX][0-9a-fA-F]+)[^0-9a-fA-F]')
jpayne@68 27
jpayne@68 28 starttagopen = re.compile('<[a-zA-Z]')
jpayne@68 29 piclose = re.compile('>')
jpayne@68 30 commentclose = re.compile(r'--\s*>')
jpayne@68 31 # Note:
jpayne@68 32 # 1) if you change tagfind/attrfind remember to update locatestarttagend too;
jpayne@68 33 # 2) if you change tagfind/attrfind and/or locatestarttagend the parser will
jpayne@68 34 # explode, so don't do it.
jpayne@68 35 # see http://www.w3.org/TR/html5/tokenization.html#tag-open-state
jpayne@68 36 # and http://www.w3.org/TR/html5/tokenization.html#tag-name-state
jpayne@68 37 tagfind_tolerant = re.compile(r'([a-zA-Z][^\t\n\r\f />\x00]*)(?:\s|/(?!>))*')
jpayne@68 38 attrfind_tolerant = re.compile(
jpayne@68 39 r'((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*'
jpayne@68 40 r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*')
jpayne@68 41 locatestarttagend_tolerant = re.compile(r"""
jpayne@68 42 <[a-zA-Z][^\t\n\r\f />\x00]* # tag name
jpayne@68 43 (?:[\s/]* # optional whitespace before attribute name
jpayne@68 44 (?:(?<=['"\s/])[^\s/>][^\s/=>]* # attribute name
jpayne@68 45 (?:\s*=+\s* # value indicator
jpayne@68 46 (?:'[^']*' # LITA-enclosed value
jpayne@68 47 |"[^"]*" # LIT-enclosed value
jpayne@68 48 |(?!['"])[^>\s]* # bare value
jpayne@68 49 )
jpayne@68 50 (?:\s*,)* # possibly followed by a comma
jpayne@68 51 )?(?:\s|/(?!>))*
jpayne@68 52 )*
jpayne@68 53 )?
jpayne@68 54 \s* # trailing whitespace
jpayne@68 55 """, re.VERBOSE)
jpayne@68 56 endendtag = re.compile('>')
jpayne@68 57 # the HTML 5 spec, section 8.1.2.2, doesn't allow spaces between
jpayne@68 58 # </ and the tag name, so maybe this should be fixed
jpayne@68 59 endtagfind = re.compile(r'</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
jpayne@68 60
jpayne@68 61
jpayne@68 62
jpayne@68 63 class HTMLParser(_markupbase.ParserBase):
jpayne@68 64 """Find tags and other markup and call handler functions.
jpayne@68 65
jpayne@68 66 Usage:
jpayne@68 67 p = HTMLParser()
jpayne@68 68 p.feed(data)
jpayne@68 69 ...
jpayne@68 70 p.close()
jpayne@68 71
jpayne@68 72 Start tags are handled by calling self.handle_starttag() or
jpayne@68 73 self.handle_startendtag(); end tags by self.handle_endtag(). The
jpayne@68 74 data between tags is passed from the parser to the derived class
jpayne@68 75 by calling self.handle_data() with the data as argument (the data
jpayne@68 76 may be split up in arbitrary chunks). If convert_charrefs is
jpayne@68 77 True the character references are converted automatically to the
jpayne@68 78 corresponding Unicode character (and self.handle_data() is no
jpayne@68 79 longer split in chunks), otherwise they are passed by calling
jpayne@68 80 self.handle_entityref() or self.handle_charref() with the string
jpayne@68 81 containing respectively the named or numeric reference as the
jpayne@68 82 argument.
jpayne@68 83 """
jpayne@68 84
jpayne@68 85 CDATA_CONTENT_ELEMENTS = ("script", "style")
jpayne@68 86
jpayne@68 87 def __init__(self, *, convert_charrefs=True):
jpayne@68 88 """Initialize and reset this instance.
jpayne@68 89
jpayne@68 90 If convert_charrefs is True (the default), all character references
jpayne@68 91 are automatically converted to the corresponding Unicode characters.
jpayne@68 92 """
jpayne@68 93 self.convert_charrefs = convert_charrefs
jpayne@68 94 self.reset()
jpayne@68 95
jpayne@68 96 def reset(self):
jpayne@68 97 """Reset this instance. Loses all unprocessed data."""
jpayne@68 98 self.rawdata = ''
jpayne@68 99 self.lasttag = '???'
jpayne@68 100 self.interesting = interesting_normal
jpayne@68 101 self.cdata_elem = None
jpayne@68 102 _markupbase.ParserBase.reset(self)
jpayne@68 103
jpayne@68 104 def feed(self, data):
jpayne@68 105 r"""Feed data to the parser.
jpayne@68 106
jpayne@68 107 Call this as often as you want, with as little or as much text
jpayne@68 108 as you want (may include '\n').
jpayne@68 109 """
jpayne@68 110 self.rawdata = self.rawdata + data
jpayne@68 111 self.goahead(0)
jpayne@68 112
jpayne@68 113 def close(self):
jpayne@68 114 """Handle any buffered data."""
jpayne@68 115 self.goahead(1)
jpayne@68 116
jpayne@68 117 __starttag_text = None
jpayne@68 118
jpayne@68 119 def get_starttag_text(self):
jpayne@68 120 """Return full source of start tag: '<...>'."""
jpayne@68 121 return self.__starttag_text
jpayne@68 122
jpayne@68 123 def set_cdata_mode(self, elem):
jpayne@68 124 self.cdata_elem = elem.lower()
jpayne@68 125 self.interesting = re.compile(r'</\s*%s\s*>' % self.cdata_elem, re.I)
jpayne@68 126
jpayne@68 127 def clear_cdata_mode(self):
jpayne@68 128 self.interesting = interesting_normal
jpayne@68 129 self.cdata_elem = None
jpayne@68 130
jpayne@68 131 # Internal -- handle data as far as reasonable. May leave state
jpayne@68 132 # and data to be processed by a subsequent call. If 'end' is
jpayne@68 133 # true, force handling all data as if followed by EOF marker.
jpayne@68 134 def goahead(self, end):
jpayne@68 135 rawdata = self.rawdata
jpayne@68 136 i = 0
jpayne@68 137 n = len(rawdata)
jpayne@68 138 while i < n:
jpayne@68 139 if self.convert_charrefs and not self.cdata_elem:
jpayne@68 140 j = rawdata.find('<', i)
jpayne@68 141 if j < 0:
jpayne@68 142 # if we can't find the next <, either we are at the end
jpayne@68 143 # or there's more text incoming. If the latter is True,
jpayne@68 144 # we can't pass the text to handle_data in case we have
jpayne@68 145 # a charref cut in half at end. Try to determine if
jpayne@68 146 # this is the case before proceeding by looking for an
jpayne@68 147 # & near the end and see if it's followed by a space or ;.
jpayne@68 148 amppos = rawdata.rfind('&', max(i, n-34))
jpayne@68 149 if (amppos >= 0 and
jpayne@68 150 not re.compile(r'[\s;]').search(rawdata, amppos)):
jpayne@68 151 break # wait till we get all the text
jpayne@68 152 j = n
jpayne@68 153 else:
jpayne@68 154 match = self.interesting.search(rawdata, i) # < or &
jpayne@68 155 if match:
jpayne@68 156 j = match.start()
jpayne@68 157 else:
jpayne@68 158 if self.cdata_elem:
jpayne@68 159 break
jpayne@68 160 j = n
jpayne@68 161 if i < j:
jpayne@68 162 if self.convert_charrefs and not self.cdata_elem:
jpayne@68 163 self.handle_data(unescape(rawdata[i:j]))
jpayne@68 164 else:
jpayne@68 165 self.handle_data(rawdata[i:j])
jpayne@68 166 i = self.updatepos(i, j)
jpayne@68 167 if i == n: break
jpayne@68 168 startswith = rawdata.startswith
jpayne@68 169 if startswith('<', i):
jpayne@68 170 if starttagopen.match(rawdata, i): # < + letter
jpayne@68 171 k = self.parse_starttag(i)
jpayne@68 172 elif startswith("</", i):
jpayne@68 173 k = self.parse_endtag(i)
jpayne@68 174 elif startswith("<!--", i):
jpayne@68 175 k = self.parse_comment(i)
jpayne@68 176 elif startswith("<?", i):
jpayne@68 177 k = self.parse_pi(i)
jpayne@68 178 elif startswith("<!", i):
jpayne@68 179 k = self.parse_html_declaration(i)
jpayne@68 180 elif (i + 1) < n:
jpayne@68 181 self.handle_data("<")
jpayne@68 182 k = i + 1
jpayne@68 183 else:
jpayne@68 184 break
jpayne@68 185 if k < 0:
jpayne@68 186 if not end:
jpayne@68 187 break
jpayne@68 188 k = rawdata.find('>', i + 1)
jpayne@68 189 if k < 0:
jpayne@68 190 k = rawdata.find('<', i + 1)
jpayne@68 191 if k < 0:
jpayne@68 192 k = i + 1
jpayne@68 193 else:
jpayne@68 194 k += 1
jpayne@68 195 if self.convert_charrefs and not self.cdata_elem:
jpayne@68 196 self.handle_data(unescape(rawdata[i:k]))
jpayne@68 197 else:
jpayne@68 198 self.handle_data(rawdata[i:k])
jpayne@68 199 i = self.updatepos(i, k)
jpayne@68 200 elif startswith("&#", i):
jpayne@68 201 match = charref.match(rawdata, i)
jpayne@68 202 if match:
jpayne@68 203 name = match.group()[2:-1]
jpayne@68 204 self.handle_charref(name)
jpayne@68 205 k = match.end()
jpayne@68 206 if not startswith(';', k-1):
jpayne@68 207 k = k - 1
jpayne@68 208 i = self.updatepos(i, k)
jpayne@68 209 continue
jpayne@68 210 else:
jpayne@68 211 if ";" in rawdata[i:]: # bail by consuming &#
jpayne@68 212 self.handle_data(rawdata[i:i+2])
jpayne@68 213 i = self.updatepos(i, i+2)
jpayne@68 214 break
jpayne@68 215 elif startswith('&', i):
jpayne@68 216 match = entityref.match(rawdata, i)
jpayne@68 217 if match:
jpayne@68 218 name = match.group(1)
jpayne@68 219 self.handle_entityref(name)
jpayne@68 220 k = match.end()
jpayne@68 221 if not startswith(';', k-1):
jpayne@68 222 k = k - 1
jpayne@68 223 i = self.updatepos(i, k)
jpayne@68 224 continue
jpayne@68 225 match = incomplete.match(rawdata, i)
jpayne@68 226 if match:
jpayne@68 227 # match.group() will contain at least 2 chars
jpayne@68 228 if end and match.group() == rawdata[i:]:
jpayne@68 229 k = match.end()
jpayne@68 230 if k <= i:
jpayne@68 231 k = n
jpayne@68 232 i = self.updatepos(i, i + 1)
jpayne@68 233 # incomplete
jpayne@68 234 break
jpayne@68 235 elif (i + 1) < n:
jpayne@68 236 # not the end of the buffer, and can't be confused
jpayne@68 237 # with some other construct
jpayne@68 238 self.handle_data("&")
jpayne@68 239 i = self.updatepos(i, i + 1)
jpayne@68 240 else:
jpayne@68 241 break
jpayne@68 242 else:
jpayne@68 243 assert 0, "interesting.search() lied"
jpayne@68 244 # end while
jpayne@68 245 if end and i < n and not self.cdata_elem:
jpayne@68 246 if self.convert_charrefs and not self.cdata_elem:
jpayne@68 247 self.handle_data(unescape(rawdata[i:n]))
jpayne@68 248 else:
jpayne@68 249 self.handle_data(rawdata[i:n])
jpayne@68 250 i = self.updatepos(i, n)
jpayne@68 251 self.rawdata = rawdata[i:]
jpayne@68 252
jpayne@68 253 # Internal -- parse html declarations, return length or -1 if not terminated
jpayne@68 254 # See w3.org/TR/html5/tokenization.html#markup-declaration-open-state
jpayne@68 255 # See also parse_declaration in _markupbase
jpayne@68 256 def parse_html_declaration(self, i):
jpayne@68 257 rawdata = self.rawdata
jpayne@68 258 assert rawdata[i:i+2] == '<!', ('unexpected call to '
jpayne@68 259 'parse_html_declaration()')
jpayne@68 260 if rawdata[i:i+4] == '<!--':
jpayne@68 261 # this case is actually already handled in goahead()
jpayne@68 262 return self.parse_comment(i)
jpayne@68 263 elif rawdata[i:i+3] == '<![':
jpayne@68 264 return self.parse_marked_section(i)
jpayne@68 265 elif rawdata[i:i+9].lower() == '<!doctype':
jpayne@68 266 # find the closing >
jpayne@68 267 gtpos = rawdata.find('>', i+9)
jpayne@68 268 if gtpos == -1:
jpayne@68 269 return -1
jpayne@68 270 self.handle_decl(rawdata[i+2:gtpos])
jpayne@68 271 return gtpos+1
jpayne@68 272 else:
jpayne@68 273 return self.parse_bogus_comment(i)
jpayne@68 274
jpayne@68 275 # Internal -- parse bogus comment, return length or -1 if not terminated
jpayne@68 276 # see http://www.w3.org/TR/html5/tokenization.html#bogus-comment-state
jpayne@68 277 def parse_bogus_comment(self, i, report=1):
jpayne@68 278 rawdata = self.rawdata
jpayne@68 279 assert rawdata[i:i+2] in ('<!', '</'), ('unexpected call to '
jpayne@68 280 'parse_comment()')
jpayne@68 281 pos = rawdata.find('>', i+2)
jpayne@68 282 if pos == -1:
jpayne@68 283 return -1
jpayne@68 284 if report:
jpayne@68 285 self.handle_comment(rawdata[i+2:pos])
jpayne@68 286 return pos + 1
jpayne@68 287
jpayne@68 288 # Internal -- parse processing instr, return end or -1 if not terminated
jpayne@68 289 def parse_pi(self, i):
jpayne@68 290 rawdata = self.rawdata
jpayne@68 291 assert rawdata[i:i+2] == '<?', 'unexpected call to parse_pi()'
jpayne@68 292 match = piclose.search(rawdata, i+2) # >
jpayne@68 293 if not match:
jpayne@68 294 return -1
jpayne@68 295 j = match.start()
jpayne@68 296 self.handle_pi(rawdata[i+2: j])
jpayne@68 297 j = match.end()
jpayne@68 298 return j
jpayne@68 299
jpayne@68 300 # Internal -- handle starttag, return end or -1 if not terminated
jpayne@68 301 def parse_starttag(self, i):
jpayne@68 302 self.__starttag_text = None
jpayne@68 303 endpos = self.check_for_whole_start_tag(i)
jpayne@68 304 if endpos < 0:
jpayne@68 305 return endpos
jpayne@68 306 rawdata = self.rawdata
jpayne@68 307 self.__starttag_text = rawdata[i:endpos]
jpayne@68 308
jpayne@68 309 # Now parse the data between i+1 and j into a tag and attrs
jpayne@68 310 attrs = []
jpayne@68 311 match = tagfind_tolerant.match(rawdata, i+1)
jpayne@68 312 assert match, 'unexpected call to parse_starttag()'
jpayne@68 313 k = match.end()
jpayne@68 314 self.lasttag = tag = match.group(1).lower()
jpayne@68 315 while k < endpos:
jpayne@68 316 m = attrfind_tolerant.match(rawdata, k)
jpayne@68 317 if not m:
jpayne@68 318 break
jpayne@68 319 attrname, rest, attrvalue = m.group(1, 2, 3)
jpayne@68 320 if not rest:
jpayne@68 321 attrvalue = None
jpayne@68 322 elif attrvalue[:1] == '\'' == attrvalue[-1:] or \
jpayne@68 323 attrvalue[:1] == '"' == attrvalue[-1:]:
jpayne@68 324 attrvalue = attrvalue[1:-1]
jpayne@68 325 if attrvalue:
jpayne@68 326 attrvalue = unescape(attrvalue)
jpayne@68 327 attrs.append((attrname.lower(), attrvalue))
jpayne@68 328 k = m.end()
jpayne@68 329
jpayne@68 330 end = rawdata[k:endpos].strip()
jpayne@68 331 if end not in (">", "/>"):
jpayne@68 332 lineno, offset = self.getpos()
jpayne@68 333 if "\n" in self.__starttag_text:
jpayne@68 334 lineno = lineno + self.__starttag_text.count("\n")
jpayne@68 335 offset = len(self.__starttag_text) \
jpayne@68 336 - self.__starttag_text.rfind("\n")
jpayne@68 337 else:
jpayne@68 338 offset = offset + len(self.__starttag_text)
jpayne@68 339 self.handle_data(rawdata[i:endpos])
jpayne@68 340 return endpos
jpayne@68 341 if end.endswith('/>'):
jpayne@68 342 # XHTML-style empty tag: <span attr="value" />
jpayne@68 343 self.handle_startendtag(tag, attrs)
jpayne@68 344 else:
jpayne@68 345 self.handle_starttag(tag, attrs)
jpayne@68 346 if tag in self.CDATA_CONTENT_ELEMENTS:
jpayne@68 347 self.set_cdata_mode(tag)
jpayne@68 348 return endpos
jpayne@68 349
jpayne@68 350 # Internal -- check to see if we have a complete starttag; return end
jpayne@68 351 # or -1 if incomplete.
jpayne@68 352 def check_for_whole_start_tag(self, i):
jpayne@68 353 rawdata = self.rawdata
jpayne@68 354 m = locatestarttagend_tolerant.match(rawdata, i)
jpayne@68 355 if m:
jpayne@68 356 j = m.end()
jpayne@68 357 next = rawdata[j:j+1]
jpayne@68 358 if next == ">":
jpayne@68 359 return j + 1
jpayne@68 360 if next == "/":
jpayne@68 361 if rawdata.startswith("/>", j):
jpayne@68 362 return j + 2
jpayne@68 363 if rawdata.startswith("/", j):
jpayne@68 364 # buffer boundary
jpayne@68 365 return -1
jpayne@68 366 # else bogus input
jpayne@68 367 if j > i:
jpayne@68 368 return j
jpayne@68 369 else:
jpayne@68 370 return i + 1
jpayne@68 371 if next == "":
jpayne@68 372 # end of input
jpayne@68 373 return -1
jpayne@68 374 if next in ("abcdefghijklmnopqrstuvwxyz=/"
jpayne@68 375 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
jpayne@68 376 # end of input in or before attribute value, or we have the
jpayne@68 377 # '/' from a '/>' ending
jpayne@68 378 return -1
jpayne@68 379 if j > i:
jpayne@68 380 return j
jpayne@68 381 else:
jpayne@68 382 return i + 1
jpayne@68 383 raise AssertionError("we should not get here!")
jpayne@68 384
jpayne@68 385 # Internal -- parse endtag, return end or -1 if incomplete
jpayne@68 386 def parse_endtag(self, i):
jpayne@68 387 rawdata = self.rawdata
jpayne@68 388 assert rawdata[i:i+2] == "</", "unexpected call to parse_endtag"
jpayne@68 389 match = endendtag.search(rawdata, i+1) # >
jpayne@68 390 if not match:
jpayne@68 391 return -1
jpayne@68 392 gtpos = match.end()
jpayne@68 393 match = endtagfind.match(rawdata, i) # </ + tag + >
jpayne@68 394 if not match:
jpayne@68 395 if self.cdata_elem is not None:
jpayne@68 396 self.handle_data(rawdata[i:gtpos])
jpayne@68 397 return gtpos
jpayne@68 398 # find the name: w3.org/TR/html5/tokenization.html#tag-name-state
jpayne@68 399 namematch = tagfind_tolerant.match(rawdata, i+2)
jpayne@68 400 if not namematch:
jpayne@68 401 # w3.org/TR/html5/tokenization.html#end-tag-open-state
jpayne@68 402 if rawdata[i:i+3] == '</>':
jpayne@68 403 return i+3
jpayne@68 404 else:
jpayne@68 405 return self.parse_bogus_comment(i)
jpayne@68 406 tagname = namematch.group(1).lower()
jpayne@68 407 # consume and ignore other stuff between the name and the >
jpayne@68 408 # Note: this is not 100% correct, since we might have things like
jpayne@68 409 # </tag attr=">">, but looking for > after tha name should cover
jpayne@68 410 # most of the cases and is much simpler
jpayne@68 411 gtpos = rawdata.find('>', namematch.end())
jpayne@68 412 self.handle_endtag(tagname)
jpayne@68 413 return gtpos+1
jpayne@68 414
jpayne@68 415 elem = match.group(1).lower() # script or style
jpayne@68 416 if self.cdata_elem is not None:
jpayne@68 417 if elem != self.cdata_elem:
jpayne@68 418 self.handle_data(rawdata[i:gtpos])
jpayne@68 419 return gtpos
jpayne@68 420
jpayne@68 421 self.handle_endtag(elem)
jpayne@68 422 self.clear_cdata_mode()
jpayne@68 423 return gtpos
jpayne@68 424
jpayne@68 425 # Overridable -- finish processing of start+end tag: <tag.../>
jpayne@68 426 def handle_startendtag(self, tag, attrs):
jpayne@68 427 self.handle_starttag(tag, attrs)
jpayne@68 428 self.handle_endtag(tag)
jpayne@68 429
jpayne@68 430 # Overridable -- handle start tag
jpayne@68 431 def handle_starttag(self, tag, attrs):
jpayne@68 432 pass
jpayne@68 433
jpayne@68 434 # Overridable -- handle end tag
jpayne@68 435 def handle_endtag(self, tag):
jpayne@68 436 pass
jpayne@68 437
jpayne@68 438 # Overridable -- handle character reference
jpayne@68 439 def handle_charref(self, name):
jpayne@68 440 pass
jpayne@68 441
jpayne@68 442 # Overridable -- handle entity reference
jpayne@68 443 def handle_entityref(self, name):
jpayne@68 444 pass
jpayne@68 445
jpayne@68 446 # Overridable -- handle data
jpayne@68 447 def handle_data(self, data):
jpayne@68 448 pass
jpayne@68 449
jpayne@68 450 # Overridable -- handle comment
jpayne@68 451 def handle_comment(self, data):
jpayne@68 452 pass
jpayne@68 453
jpayne@68 454 # Overridable -- handle declaration
jpayne@68 455 def handle_decl(self, decl):
jpayne@68 456 pass
jpayne@68 457
jpayne@68 458 # Overridable -- handle processing instruction
jpayne@68 459 def handle_pi(self, data):
jpayne@68 460 pass
jpayne@68 461
jpayne@68 462 def unknown_decl(self, data):
jpayne@68 463 pass
jpayne@68 464
jpayne@68 465 # Internal -- helper to remove special character quoting
jpayne@68 466 def unescape(self, s):
jpayne@68 467 warnings.warn('The unescape method is deprecated and will be removed '
jpayne@68 468 'in 3.5, use html.unescape() instead.',
jpayne@68 469 DeprecationWarning, stacklevel=2)
jpayne@68 470 return unescape(s)