PATH:
usr
/
lib64
/
python3.6
"""Shared support for scanning document type declarations in HTML and XHTML. This module is used as a foundation for the html.parser module. It has no documented public API and should not be used directly. """ import re _declname_match = re.compile(r'[a-zA-Z][-_.a-zA-Z0-9]*\s*').match _declstringlit_match = re.compile(r'(\'[^\']*\'|"[^"]*")\s*').match _commentclose = re.compile(r'--\s*>') _markedsectionclose = re.compile(r']\s*]\s*>') # An analysis of the MS-Word extensions is available at # http://www.planetpublish.com/xmlarena/xap/Thursday/WordtoXML.pdf _msmarkedsectionclose = re.compile(r']\s*>') del re class ParserBase: """Parser base class which provides some common support methods used by the SGML/HTML and XHTML parsers.""" def __init__(self): if self.__class__ is ParserBase: raise RuntimeError( "_markupbase.ParserBase must be subclassed") def error(self, message): raise NotImplementedError( "subclasses of ParserBase must override error()") def reset(self): self.lineno = 1 self.offset = 0 def getpos(self): """Return current line number and offset.""" return self.lineno, self.offset # Internal -- update line number and offset. This should be # called for each piece of data exactly once, in order -- in other # words the concatenation of all the input strings to this # function should be exactly the entire input. def updatepos(self, i, j): if i >= j: return j rawdata = self.rawdata nlines = rawdata.count("\n", i, j) if nlines: self.lineno = self.lineno + nlines pos = rawdata.rindex("\n", i, j) # Should not fail self.offset = j-(pos+1) else: self.offset = self.offset + j-i return j _decl_otherchars = '' # Internal -- parse declaration (for use by subclasses). def parse_declaration(self, i): # This is some sort of declaration; in "HTML as # deployed," this should only be the document type # declaration ("<!DOCTYPE html...>"). # ISO 8879:1986, however, has more complex # declaration syntax for elements in <!...>, including: # --comment-- # [marked section] # name in the following list: ENTITY, DOCTYPE, ELEMENT, # ATTLIST, NOTATION, SHORTREF, USEMAP, # LINKTYPE, LINK, IDLINK, USELINK, SYSTEM rawdata = self.rawdata j = i + 2 assert rawdata[i:j] == "<!", "unexpected call to parse_declaration" if rawdata[j:j+1] == ">": # the empty comment <!> return j + 1 if rawdata[j:j+1] in ("-", ""): # Start of comment followed by buffer boundary, # or just a buffer boundary. return -1 # A simple, practical version could look like: ((name|stringlit) S*) + '>' n = len(rawdata) if rawdata[j:j+2] == '--': #comment # Locate --.*-- as the body of the comment return self.parse_comment(i) elif rawdata[j] == '[': #marked section # Locate [statusWord [...arbitrary SGML...]] as the body of the marked section # Where statusWord is one of TEMP, CDATA, IGNORE, INCLUDE, RCDATA # Note that this is extended by Microsoft Office "Save as Web" function # to include [if...] and [endif]. return self.parse_marked_section(i) else: #all other declaration elements decltype, j = self._scan_name(j, i) if j < 0: return j if decltype == "doctype": self._decl_otherchars = '' while j < n: c = rawdata[j] if c == ">": # end of declaration syntax data = rawdata[i+2:j] if decltype == "doctype": self.handle_decl(data) else: # According to the HTML5 specs sections "8.2.4.44 Bogus # comment state" and "8.2.4.45 Markup declaration open # state", a comment token should be emitted. # Calling unknown_decl provides more flexibility though. self.unknown_decl(data) return j + 1 if c in "\"'": m = _declstringlit_match(rawdata, j) if not m: return -1 # incomplete j = m.end() elif c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ": name, j = self._scan_name(j, i) elif c in self._decl_otherchars: j = j + 1 elif c == "[": # this could be handled in a separate doctype parser if decltype == "doctype": j = self._parse_doctype_subset(j + 1, i) elif decltype in {"attlist", "linktype", "link", "element"}: # must tolerate []'d groups in a content model in an element declaration # also in data attribute specifications of attlist declaration # also link type declaration subsets in linktype declarations # also link attribute specification lists in link declarations self.error("unsupported '[' char in %s declaration" % decltype) else: self.error("unexpected '[' char in declaration") else: self.error( "unexpected %r char in declaration" % rawdata[j]) if j < 0: return j return -1 # incomplete # Internal -- parse a marked section # Override this to handle MS-word extension syntax <![if word]>content<![endif]> def parse_marked_section(self, i, report=1): rawdata= self.rawdata assert rawdata[i:i+3] == '<![', "unexpected call to parse_marked_section()" sectName, j = self._scan_name( i+3, i ) if j < 0: return j if sectName in {"temp", "cdata", "ignore", "include", "rcdata"}: # look for standard ]]> ending match= _markedsectionclose.search(rawdata, i+3) elif sectName in {"if", "else", "endif"}: # look for MS Office ]> ending match= _msmarkedsectionclose.search(rawdata, i+3) else: self.error('unknown status keyword %r in marked section' % rawdata[i+3:j]) if not match: return -1 if report: j = match.start(0) self.unknown_decl(rawdata[i+3: j]) return match.end(0) # Internal -- parse comment, return length or -1 if not terminated def parse_comment(self, i, report=1): rawdata = self.rawdata if rawdata[i:i+4] != '<!--': self.error('unexpected call to parse_comment()') match = _commentclose.search(rawdata, i+4) if not match: return -1 if report: j = match.start(0) self.handle_comment(rawdata[i+4: j]) return match.end(0) # Internal -- scan past the internal subset in a <!DOCTYPE declaration, # returning the index just past any whitespace following the trailing ']'. def _parse_doctype_subset(self, i, declstartpos): rawdata = self.rawdata n = len(rawdata) j = i while j < n: c = rawdata[j] if c == "<": s = rawdata[j:j+2] if s == "<": # end of buffer; incomplete return -1 if s != "<!": self.updatepos(declstartpos, j + 1) self.error("unexpected char in internal subset (in %r)" % s) if (j + 2) == n: # end of buffer; incomplete return -1 if (j + 4) > n: # end of buffer; incomplete return -1 if rawdata[j:j+4] == "<!--": j = self.parse_comment(j, report=0) if j < 0: return j continue name, j = self._scan_name(j + 2, declstartpos) if j == -1: return -1 if name not in {"attlist", "element", "entity", "notation"}: self.updatepos(declstartpos, j + 2) self.error( "unknown declaration %r in internal subset" % name) # handle the individual names meth = getattr(self, "_parse_doctype_" + name) j = meth(j, declstartpos) if j < 0: return j elif c == "%": # parameter entity reference if (j + 1) == n: # end of buffer; incomplete return -1 s, j = self._scan_name(j + 1, declstartpos) if j < 0: return j if rawdata[j] == ";": j = j + 1 elif c == "]": j = j + 1 while j < n and rawdata[j].isspace(): j = j + 1 if j < n: if rawdata[j] == ">": return j self.updatepos(declstartpos, j) self.error("unexpected char after internal subset") else: return -1 elif c.isspace(): j = j + 1 else: self.updatepos(declstartpos, j) self.error("unexpected char %r in internal subset" % c) # end of buffer reached return -1 # Internal -- scan past <!ELEMENT declarations def _parse_doctype_element(self, i, declstartpos): name, j = self._scan_name(i, declstartpos) if j == -1: return -1 # style content model; just skip until '>' rawdata = self.rawdata if '>' in rawdata[j:]: return rawdata.find(">", j) + 1 return -1 # Internal -- scan past <!ATTLIST declarations def _parse_doctype_attlist(self, i, declstartpos): rawdata = self.rawdata name, j = self._scan_name(i, declstartpos) c = rawdata[j:j+1] if c == "": return -1 if c == ">": return j + 1 while 1: # scan a series of attribute descriptions; simplified: # name type [value] [#constraint] name, j = self._scan_name(j, declstartpos) if j < 0: return j c = rawdata[j:j+1] if c == "": return -1 if c == "(": # an enumerated type; look for ')' if ")" in rawdata[j:]: j = rawdata.find(")", j) + 1 else: return -1 while rawdata[j:j+1].isspace(): j = j + 1 if not rawdata[j:]: # end of buffer, incomplete return -1 else: name, j = self._scan_name(j, declstartpos) c = rawdata[j:j+1] if not c: return -1 if c in "'\"": m = _declstringlit_match(rawdata, j) if m: j = m.end() else: return -1 c = rawdata[j:j+1] if not c: return -1 if c == "#": if rawdata[j:] == "#": # end of buffer return -1 name, j = self._scan_name(j + 1, declstartpos) if j < 0: return j c = rawdata[j:j+1] if not c: return -1 if c == '>': # all done return j + 1 # Internal -- scan past <!NOTATION declarations def _parse_doctype_notation(self, i, declstartpos): name, j = self._scan_name(i, declstartpos) if j < 0: return j rawdata = self.rawdata while 1: c = rawdata[j:j+1] if not c: # end of buffer; incomplete return -1 if c == '>': return j + 1 if c in "'\"": m = _declstringlit_match(rawdata, j) if not m: return -1 j = m.end() else: name, j = self._scan_name(j, declstartpos) if j < 0: return j # Internal -- scan past <!ENTITY declarations def _parse_doctype_entity(self, i, declstartpos): rawdata = self.rawdata if rawdata[i:i+1] == "%": j = i + 1 while 1: c = rawdata[j:j+1] if not c: return -1 if c.isspace(): j = j + 1 else: break else: j = i name, j = self._scan_name(j, declstartpos) if j < 0: return j while 1: c = self.rawdata[j:j+1] if not c: return -1 if c in "'\"": m = _declstringlit_match(rawdata, j) if m: j = m.end() else: return -1 # incomplete elif c == ">": return j + 1 else: name, j = self._scan_name(j, declstartpos) if j < 0: return j # Internal -- scan a name token and the new position and the token, or # return -1 if we've reached the end of the buffer. def _scan_name(self, i, declstartpos): rawdata = self.rawdata n = len(rawdata) if i == n: return None, -1 m = _declname_match(rawdata, i) if m: s = m.group() name = s.strip() if (i + len(s)) == n: return None, -1 # end of buffer return name.lower(), m.end() else: self.updatepos(declstartpos, i) self.error("expected name token at %r" % rawdata[declstartpos:declstartpos+20]) # To be overridden -- handlers for unknown objects def unknown_decl(self, data): pass
[+]
..
[-] __phello__.foo.py
[edit]
[-] zipfile.py
[edit]
[-] _dummy_thread.py
[edit]
[-] signal.py
[edit]
[-] tabnanny.py
[edit]
[-] cmd.py
[edit]
[-] cProfile.py
[edit]
[-] tempfile.py
[edit]
[-] argparse.py
[edit]
[-] platform.py
[edit]
[-] binhex.py
[edit]
[-] antigravity.py
[edit]
[+]
curses
[-] _compat_pickle.py
[edit]
[-] statistics.py
[edit]
[-] inspect.py
[edit]
[-] ipaddress.py
[edit]
[-] sunau.py
[edit]
[-] imghdr.py
[edit]
[-] random.py
[edit]
[-] macpath.py
[edit]
[-] hmac.py
[edit]
[-] base64.py
[edit]
[-] cgitb.py
[edit]
[-] stringprep.py
[edit]
[-] ast.py
[edit]
[-] textwrap.py
[edit]
[-] enum.py
[edit]
[-] _compression.py
[edit]
[-] dis.py
[edit]
[+]
venv
[-] chunk.py
[edit]
[-] this.py
[edit]
[-] py_compile.py
[edit]
[-] fnmatch.py
[edit]
[+]
xml
[-] opcode.py
[edit]
[+]
site-packages
[-] sre_compile.py
[edit]
[-] _pyio.py
[edit]
[-] pty.py
[edit]
[-] datetime.py
[edit]
[-] macurl2path.py
[edit]
[+]
lib2to3
[+]
wsgiref
[-] heapq.py
[edit]
[-] keyword.py
[edit]
[-] codecs.py
[edit]
[+]
ensurepip
[-] pickletools.py
[edit]
[-] compileall.py
[edit]
[-] nturl2path.py
[edit]
[-] warnings.py
[edit]
[-] shutil.py
[edit]
[-] socket.py
[edit]
[-] pdb.py
[edit]
[-] zipapp.py
[edit]
[-] formatter.py
[edit]
[-] _sitebuiltins.py
[edit]
[-] _markupbase.py
[edit]
[-] types.py
[edit]
[-] runpy.py
[edit]
[-] uu.py
[edit]
[-] typing.py
[edit]
[-] pathlib.py
[edit]
[-] _threading_local.py
[edit]
[-] mailcap.py
[edit]
[-] bisect.py
[edit]
[-] linecache.py
[edit]
[-] colorsys.py
[edit]
[-] glob.py
[edit]
[-] sndhdr.py
[edit]
[-] ssl.py
[edit]
[-] _strptime.py
[edit]
[-] _sysconfigdata_m_linux_x86_64-linux-gnu.py
[edit]
[-] imp.py
[edit]
[-] contextlib.py
[edit]
[-] copyreg.py
[edit]
[-] filecmp.py
[edit]
[+]
logging
[-] operator.py
[edit]
[-] token.py
[edit]
[-] gzip.py
[edit]
[-] string.py
[edit]
[-] genericpath.py
[edit]
[-] _osx_support.py
[edit]
[-] stat.py
[edit]
[-] lzma.py
[edit]
[-] __future__.py
[edit]
[+]
distutils
[-] dummy_threading.py
[edit]
[+]
asyncio
[-] webbrowser.py
[edit]
[-] symtable.py
[edit]
[+]
lib-dynload
[-] getopt.py
[edit]
[-] wave.py
[edit]
[-] codeop.py
[edit]
[-] _sysconfigdata_dm_linux_x86_64-linux-gnu.py
[edit]
[-] abc.py
[edit]
[+]
config-3.6m-x86_64-linux-gnu
[+]
pydoc_data
[-] telnetlib.py
[edit]
[+]
unittest
[-] fileinput.py
[edit]
[-] ftplib.py
[edit]
[+]
ctypes
[-] _bootlocale.py
[edit]
[-] pipes.py
[edit]
[-] aifc.py
[edit]
[-] pprint.py
[edit]
[-] queue.py
[edit]
[-] difflib.py
[edit]
[+]
__pycache__
[-] uuid.py
[edit]
[-] reprlib.py
[edit]
[-] threading.py
[edit]
[+]
http
[-] sre_parse.py
[edit]
[-] subprocess.py
[edit]
[+]
importlib
[-] selectors.py
[edit]
[-] getpass.py
[edit]
[-] trace.py
[edit]
[-] struct.py
[edit]
[-] tracemalloc.py
[edit]
[-] plistlib.py
[edit]
[-] asynchat.py
[edit]
[-] fractions.py
[edit]
[-] shlex.py
[edit]
[-] bdb.py
[edit]
[-] locale.py
[edit]
[-] calendar.py
[edit]
[-] poplib.py
[edit]
[-] posixpath.py
[edit]
[-] imaplib.py
[edit]
[+]
concurrent
[-] pickle.py
[edit]
[-] timeit.py
[edit]
[+]
json
[-] traceback.py
[edit]
[+]
multiprocessing
[-] shelve.py
[edit]
[-] csv.py
[edit]
[-] tarfile.py
[edit]
[-] numbers.py
[edit]
[-] optparse.py
[edit]
[-] cgi.py
[edit]
[-] pstats.py
[edit]
[-] crypt.py
[edit]
[+]
collections
[-] site.py
[edit]
[-] pkgutil.py
[edit]
[-] re.py
[edit]
[-] pyclbr.py
[edit]
[-] socketserver.py
[edit]
[-] _pydecimal.py
[edit]
[-] pydoc.py
[edit]
[-] sre_constants.py
[edit]
[-] xdrlib.py
[edit]
[-] nntplib.py
[edit]
[-] mimetypes.py
[edit]
[+]
email
[-] quopri.py
[edit]
[-] doctest.py
[edit]
[-] profile.py
[edit]
[-] sched.py
[edit]
[-] hashlib.py
[edit]
[+]
urllib
[-] secrets.py
[edit]
[-] functools.py
[edit]
[-] smtplib.py
[edit]
[-] copy.py
[edit]
[+]
dbm
[-] tty.py
[edit]
[-] os.py
[edit]
[-] _collections_abc.py
[edit]
[-] configparser.py
[edit]
[-] _weakrefset.py
[edit]
[-] netrc.py
[edit]
[-] code.py
[edit]
[-] asyncore.py
[edit]
[-] tokenize.py
[edit]
[+]
encodings
[-] io.py
[edit]
[-] smtpd.py
[edit]
[-] sysconfig.py
[edit]
[-] decimal.py
[edit]
[+]
sqlite3
[-] rlcompleter.py
[edit]
[-] ntpath.py
[edit]
[+]
test
[-] weakref.py
[edit]
[-] symbol.py
[edit]
[-] modulefinder.py
[edit]
[+]
xmlrpc
[-] bz2.py
[edit]
[-] gettext.py
[edit]
[-] mailbox.py
[edit]
[+]
html