(self, i)
| 58 | |
| 59 | # Internal -- parse declaration (for use by subclasses). |
| 60 | def parse_declaration(self, i): |
| 61 | # This is some sort of declaration; in "HTML as |
| 62 | # deployed," this should only be the document type |
| 63 | # declaration ("<!DOCTYPE html...>"). |
| 64 | # ISO 8879:1986, however, has more complex |
| 65 | # declaration syntax for elements in <!...>, including: |
| 66 | # --comment-- |
| 67 | # [marked section] |
| 68 | # name in the following list: ENTITY, DOCTYPE, ELEMENT, |
| 69 | # ATTLIST, NOTATION, SHORTREF, USEMAP, |
| 70 | # LINKTYPE, LINK, IDLINK, USELINK, SYSTEM |
| 71 | rawdata = self.rawdata |
| 72 | j = i + 2 |
| 73 | assert rawdata[i:j] == "<!", "unexpected call to parse_declaration" |
| 74 | if rawdata[j:j+1] == ">": |
| 75 | # the empty comment <!> |
| 76 | return j + 1 |
| 77 | if rawdata[j:j+1] in ("-", ""): |
| 78 | # Start of comment followed by buffer boundary, |
| 79 | # or just a buffer boundary. |
| 80 | return -1 |
| 81 | # A simple, practical version could look like: ((name|stringlit) S*) + '>' |
| 82 | n = len(rawdata) |
| 83 | if rawdata[j:j+2] == '--': #comment |
| 84 | # Locate --.*-- as the body of the comment |
| 85 | return self.parse_comment(i) |
| 86 | elif rawdata[j] == '[': #marked section |
| 87 | # Locate [statusWord [...arbitrary SGML...]] as the body of the marked section |
| 88 | # Where statusWord is one of TEMP, CDATA, IGNORE, INCLUDE, RCDATA |
| 89 | # Note that this is extended by Microsoft Office "Save as Web" function |
| 90 | # to include [if...] and [endif]. |
| 91 | return self.parse_marked_section(i) |
| 92 | else: #all other declaration elements |
| 93 | decltype, j = self._scan_name(j, i) |
| 94 | if j < 0: |
| 95 | return j |
| 96 | if decltype == "doctype": |
| 97 | self._decl_otherchars = '' |
| 98 | while j < n: |
| 99 | c = rawdata[j] |
| 100 | if c == ">": |
| 101 | # end of declaration syntax |
| 102 | data = rawdata[i+2:j] |
| 103 | if decltype == "doctype": |
| 104 | self.handle_decl(data) |
| 105 | else: |
| 106 | # According to the HTML5 specs sections "8.2.4.44 Bogus |
| 107 | # comment state" and "8.2.4.45 Markup declaration open |
| 108 | # state", a comment token should be emitted. |
| 109 | # Calling unknown_decl provides more flexibility though. |
| 110 | self.unknown_decl(data) |
| 111 | return j + 1 |
| 112 | if c in "\"'": |
| 113 | m = _declstringlit_match(rawdata, j) |
| 114 | if not m: |
| 115 | return -1 # incomplete |
| 116 | j = m.end() |
| 117 | elif c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": |
nothing calls this directly
no test coverage detected