(self, i)
| 424 | |
| 425 | # Internal -- handle starttag, return end or -1 if not terminated |
| 426 | def parse_starttag(self, i): |
| 427 | # See the HTML5 specs section "13.2.5.8 Tag name state" |
| 428 | # https://html.spec.whatwg.org/multipage/parsing.html#tag-name-state |
| 429 | self.__starttag_text = None |
| 430 | endpos = self.check_for_whole_start_tag(i) |
| 431 | if endpos < 0: |
| 432 | return endpos |
| 433 | rawdata = self.rawdata |
| 434 | self.__starttag_text = rawdata[i:endpos] |
| 435 | |
| 436 | # Now parse the data between i+1 and j into a tag and attrs |
| 437 | attrs = [] |
| 438 | match = tagfind_tolerant.match(rawdata, i+1) |
| 439 | assert match, 'unexpected call to parse_starttag()' |
| 440 | k = match.end() |
| 441 | self.lasttag = tag = match.group(1).lower() |
| 442 | while k < endpos: |
| 443 | m = attrfind_tolerant.match(rawdata, k) |
| 444 | if not m: |
| 445 | break |
| 446 | attrname, rest, attrvalue = m.group(1, 2, 3) |
| 447 | if not rest: |
| 448 | attrvalue = None |
| 449 | elif attrvalue[:1] == '\'' == attrvalue[-1:] or \ |
| 450 | attrvalue[:1] == '"' == attrvalue[-1:]: |
| 451 | attrvalue = attrvalue[1:-1] |
| 452 | if attrvalue: |
| 453 | attrvalue = _unescape_attrvalue(attrvalue) |
| 454 | attrs.append((attrname.lower(), attrvalue)) |
| 455 | k = m.end() |
| 456 | |
| 457 | end = rawdata[k:endpos].strip() |
| 458 | if end not in (">", "/>"): |
| 459 | self.handle_data(rawdata[i:endpos]) |
| 460 | return endpos |
| 461 | if end.endswith('/>'): |
| 462 | # XHTML-style empty tag: <span attr="value" /> |
| 463 | self.handle_startendtag(tag, attrs) |
| 464 | else: |
| 465 | self.handle_starttag(tag, attrs) |
| 466 | if (tag in self.CDATA_CONTENT_ELEMENTS or |
| 467 | (self.scripting and tag == "noscript") or |
| 468 | tag == "plaintext"): |
| 469 | self.set_cdata_mode(tag, escapable=False) |
| 470 | elif tag in self.RCDATA_CONTENT_ELEMENTS: |
| 471 | self.set_cdata_mode(tag, escapable=True) |
| 472 | return endpos |
| 473 | |
| 474 | # Internal -- check to see if we have a complete starttag; return end |
| 475 | # or -1 if incomplete. |
no test coverage detected