o ,]W?@sXdZddlZedjZedjZedZedZedZ[Gdd d e Z dS) aShared support for scanning document type declarations in HTML and XHTML. Backported for python-future from Python 3.3. Reason: ParserBase is an old-style class in the Python 2.7 source of markupbase.py, which I suspect might be the cause of sporadic unit-test failures on travis-ci.org with test_htmlparser.py. The test failures look like this: ====================================================================== ERROR: test_attr_entity_replacement (future.tests.test_htmlparser.AttributesStrictTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 661, in test_attr_entity_replacement [("starttag", "a", [("b", "&><"'")])]) File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 93, in _run_check collector = self.get_collector() File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 617, in get_collector return EventCollector(strict=True) File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 27, in __init__ html.parser.HTMLParser.__init__(self, *args, **kw) File "/home/travis/build/edschofield/python-future/future/backports/html/parser.py", line 135, in __init__ self.reset() File "/home/travis/build/edschofield/python-future/future/backports/html/parser.py", line 143, in reset _markupbase.ParserBase.reset(self) TypeError: unbound method reset() must be called with ParserBase instance as first argument (got EventCollector instance instead) This module is used as a foundation for the html.parser module. It has no documented public API and should not be used directly. Nz[a-zA-Z][-_.a-zA-Z0-9]*\s*z(\'[^\']*\'|"[^"]*")\s*z--\s*>z ]\s*]\s*>z]\s*>c@seZdZdZddZddZddZdd Zd d Zd Z d dZ d#ddZ d#ddZ ddZ ddZddZddZddZddZd d!Zd"S)$ ParserBaseziParser base class which provides some common support methods used by the SGML/HTML and XHTML parsers.cCs|jtur tddS)Nz)_markupbase.ParserBase must be subclassed) __class__r RuntimeErrorselfr>/usr/lib/python3/dist-packages/future/backports/_markupbase.py__init__6s zParserBase.__init__cCstd)Nz.subclasses of ParserBase must override error())NotImplementedError)rmessagerrrerror;szParserBase.errorcCsd|_d|_dS)Nrlinenooffsetrrrrreset?s zParserBase.resetcCs |j|jfS)z&Return current line number and offset.rrrrrgetposCs zParserBase.getposcCsd||kr|S|j}|d||}|r(|j||_|d||}||d|_|S|j|||_|S)N r )rawdatacountrrindexr)rijrnlinesposrrr updateposKs zParserBase.updateposc Cs|j}|d}|||dksJd|||ddkr!|dS|||ddvr-dSt|}|||ddkr@||S||d krK||S|||\}}|d krY|S|d kr`d |_||kr||}|dkr||d|}|d kr|||dS|||dS|d vrt||}|sdS| }nG|dvr|||\} }n:||jvr|d}n0|d kr|d kr| |d|}n|t gdvr| d|n| dn | d|||d kr|S||ksddS)N)-rz--[rdoctyperz"'4abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)attlistlinktypelinkelementz&unsupported '[' char in %s declarationz"unexpected '[' char in declarationz!unexpected %r char in declaration) rlen parse_commentparse_marked_section _scan_name_decl_otherchars handle_decl unknown_decl_declstringlit_matchend_parse_doctype_subsetsetr ) rrrrndecltypecdatamnamerrrparse_declaration[s`            (zParserBase.parse_declarationr cCs|j}|||ddksJd||d|\}}|dkr!|S|tgdvr2t||d}n|tgdvrCt||d}n |d||d||sTdS|rf|d}|||d|| dS) NzdS|dkrvd||dvrS|d|d}ndS|||drm|d}|||ds_||dsudSn|||\}}|||d}|sdS|dvrt||}|r|}ndS|||d}|sdS|d kr||dd krdS||d|\}}|dkr|S|||d}|sdS|dkr|dSq") Nr rr!rr()'"#)rr,r[rWr0r1)rrrXrr9rr6r8rrr_parse_doctype_attlists`   z!ParserBase._parse_doctype_attlistcCs|||\}}|dkr|S|j} |||d}|sdS|dkr&|dS|dvr8t||}|s3dS|}n|||\}}|dkrF|Sq)Nrr r!rr_)r,rr0r1)rrrXr9rrr6r8rrr_parse_doctype_notationXs&  z"ParserBase._parse_doctype_notationcCs|j}|||ddkr*|d} |||d}|sdS|r'|d}nnqn|}|||\}}|dkr:|S |j||d}|sHdS|dvrZt||}|rX|}ndS|dkrb|dS|||\}}|dkrp|Sq;)Nr rSr!rr_r)rrWr,r0r1)rrrXrrr6r9r8rrr_parse_doctype_entityos>   z ParserBase._parse_doctype_entitycCs|j}t|}||kr dSt||}|r.|}|}|t||kr&dS||fS||||d|||ddS)N)Nr!zexpected name token at %r) rr)_declname_matchgroupstriplowerr1rr )rrrXrr4r8rYr9rrrr,s   zParserBase._scan_namecCsdS)Nr)rr7rrrr/szParserBase.unknown_declN)r )__name__ __module__ __qualname____doc__r r rrrr-r:r+r*r2r\rarbrcr,r/rrrrr2s$  R C 9$ r) rlrecompilerJrer0rMrDrFobjectrrrrrs"