B ÍAÒ[:Mã@sdZddlmZmZmZmZddlTddlmZddl Z ddl Z e   d¡Z e   d¡Z e   d¡Ze   d ¡Ze   d ¡Ze   d ¡Ze   d ¡Ze   d ¡Ze   d¡Ze   d¡Ze   d¡Ze   de j¡Ze   de j¡Ze   d ¡Ze   d¡ZGdd„deƒZGdd„dejƒZdS)zLA parser for HTML and XHTML. Backported for python-future from Python 3.3. é)Úabsolute_importÚdivisionÚprint_functionÚunicode_literals)Ú*)Ú _markupbaseNz[&<]z &[a-zA-Z#]z%&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]z)&#(?:[0-9]+|[xX][0-9a-fA-F]+)[^0-9a-fA-F]z <[a-zA-Z]ú>z--\s*>z(([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*z[a-zA-Z][^ />]*zJ\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?z]((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*aê <[a-zA-Z][-.a-zA-Z0-9:_]* # tag name (?:\s+ # whitespace before attribute name (?:[a-zA-Z_][-.:a-zA-Z0-9_]* # attribute name (?:\s*=\s* # value indicator (?:'[^']*' # LITA-enclosed value |\"[^\"]*\" # LIT-enclosed value |[^'\">\s]+ # bare value ) )? ) )* \s* # trailing whitespace aF <[a-zA-Z][-.a-zA-Z0-9:_]* # tag name (?:[\s/]* # optional whitespace before attribute name (?:(?<=['"\s/])[^\s/>][^\s/=>]* # attribute name (?:\s*=+\s* # value indicator (?:'[^']*' # LITA-enclosed value |"[^"]*" # LIT-enclosed value |(?!['"])[^>\s]* # bare value ) (?:\s*,)* # possibly followed by a comma )?(?:\s|/(?!>))* )* )? \s* # trailing whitespace z#c@s"eZdZdZddd„Zdd„ZdS) ÚHTMLParseErrorz&Exception raised for all parse errors.©NNcCs&|st‚||_|d|_|d|_dS)Nré)ÚAssertionErrorÚmsgÚlinenoÚoffset)Úselfr Úposition©rúM/opt/alt/python37/lib/python3.7/site-packages/future/backports/html/parser.pyÚ__init__Us zHTMLParseError.__init__cCs>|j}|jdk r|d|j}|jdk r:|d|jd}|S)Nz , at line %dz , column %dr )r rr)rÚresultrrrÚ__str__[s   zHTMLParseError.__str__N)r )Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrr Rs r c@sìeZdZdZdZd:dd„Zdd„Zdd „Zd d „Zd d „Z dZ dd„Z dd„Z dd„Z dd„Zdd„Zd;dd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Zd6d7„Zd8d9„ZdS)<Ú HTMLParseraÇFind tags and other markup and call handler functions. Usage: p = HTMLParser() p.feed(data) ... p.close() Start tags are handled by calling self.handle_starttag() or self.handle_startendtag(); end tags by self.handle_endtag(). The data between tags is passed from the parser to the derived class by calling self.handle_data() with the data as argument (the data may be split up in arbitrary chunks). Entity references are passed by calling self.handle_entityref() with the entity reference as the argument. Numeric character references are passed to self.handle_charref() with the string containing the reference as the argument. )ÚscriptÚstyleFcCs&|rtjdtdd||_| ¡dS)zßInitialize and reset this instance. If strict is set to False (the default) the parser will parse invalid markup, otherwise it will raise an error. Note that the strict mode is deprecated. zThe strict mode is deprecated.é)Ú stacklevelN)ÚwarningsÚwarnÚDeprecationWarningÚstrictÚreset)rr#rrrrzs  zHTMLParser.__init__cCs(d|_d|_t|_d|_tj |¡dS)z1Reset this instance. Loses all unprocessed data.Úz???N)ÚrawdataÚlasttagÚinteresting_normalÚ interestingÚ cdata_elemrÚ ParserBaser$)rrrrr$‡s zHTMLParser.resetcCs|j||_| d¡dS)z‘Feed data to the parser. Call this as often as you want, with as little or as much text as you want (may include '\n'). rN)r&Úgoahead)rÚdatarrrÚfeeds zHTMLParser.feedcCs| d¡dS)zHandle any buffered data.r N)r,)rrrrÚclose˜szHTMLParser.closecCst|| ¡ƒ‚dS)N)r Úgetpos)rÚmessagerrrÚerrorœszHTMLParser.errorNcCs|jS)z)Return full source of start tag: '<...>'.)Ú_HTMLParser__starttag_text)rrrrÚget_starttag_text¡szHTMLParser.get_starttag_textcCs$| ¡|_t d|jtj¡|_dS)Nz )Úlowerr*ÚreÚcompileÚIr))rÚelemrrrÚset_cdata_mode¥s zHTMLParser.set_cdata_modecCst|_d|_dS)N)r(r)r*)rrrrÚclear_cdata_mode©szHTMLParser.clear_cdata_modec Cs¤|j}d}t|ƒ}xF||krZ|j ||¡}|r<| ¡}n |jrDP|}||krb| |||…¡| ||¡}||krxP|j}|d|ƒr¾t   ||¡r¢|  |¡}n’|d|ƒr¸|  |¡}n||d|ƒrÎ|  |¡}nf|d|ƒrä| |¡}nP|d|ƒr|jr| |¡}n | |¡}n$|d|kr2| d¡|d}nP|dkr°|sFP|jrX| d¡| d |d¡}|dkr–| d|d¡}|dkrž|d}n|d7}| |||…¡| ||¡}q|d |ƒrZt  ||¡}|r&| ¡d d …} | | ¡| ¡}|d |dƒs|d}| ||¡}qn2d ||d…krV| |dd …¡| |d ¡}Pq|d|ƒrLt  ||¡}|rº| d¡} | | ¡| ¡}|d |dƒs¬|d}| ||¡}qt  ||¡}|r|r| ¡||d…kr|jrü| d¡n||kr |}| ||d¡}Pn,|d|krH| d¡| ||d¡}nPqdstdƒ‚qW|r’||kr’|js’| |||…¡| ||¡}||d…|_dS)NrúdS|rX| ||d|…¡|dS)Nr)zÚ z junk characters in start tag: %réz/>)r3Úcheck_for_whole_start_tagr&ÚtagfindrGr rQrOr5r'r#ÚattrfindÚattrfind_tolerantÚunescapeÚappendÚstripr0Úcountr@Úrfindr2rCÚendswithÚhandle_startendtagÚhandle_starttagÚCDATA_CONTENT_ELEMENTSr:)rrUÚendposr&ÚattrsrGrXÚtagÚmÚattrnameÚrestZ attrvaluerQrrrrrrHEs\    (,          zHTMLParser.parse_starttagcCs|j}|jrt ||¡}n t ||¡}|rú| ¡}|||d…}|dkrR|dS|dkr²| d|¡rn|dS| d|¡r~dS|jrž| ||d¡| d¡||krª|S|dS|dkr¾dS|d krÊdS|jræ| ||¡| d ¡||krò|S|dSt d ƒ‚dS) Nr rú/z/>rr=zmalformed empty start tagr%z6abcdefghijklmnopqrstuvwxyz=/ABCDEFGHIJKLMNOPQRSTUVWXYZzmalformed start tagzwe should not get here!) r&r#ÚlocatestarttagendrGÚlocatestarttagend_tolerantrQrErDr2r )rrUr&ryrWÚnextrrrri~s>      z$HTMLParser.check_for_whole_start_tagcCsN|j}|||d…dks"tdƒ‚t ||d¡}|s:dS| ¡}t ||¡}|sø|jdk rr| |||…¡|S|j r|  d|||…f¡t  ||d¡}|sÊ|||d…dkrÀ|dS|  |¡S|  ¡ ¡}| d | ¡¡}| |¡|dS|  d¡ ¡}|jdk r4||jkr4| |||…¡|S| | ¡¡| ¡|S) Nrzr)r&r Ú endendtagrArQÚ endtagfindrGr*rCr#r2Útagfind_tolerantr^rOr5rMÚ handle_endtagr;)rrUr&rGr_Z namematchZtagnamer9rrrrI©s<       zHTMLParser.parse_endtagcCs| ||¡| |¡dS)N)rtrƒ)rrxrwrrrrsÓs zHTMLParser.handle_startendtagcCsdS)Nr)rrxrwrrrrtØszHTMLParser.handle_starttagcCsdS)Nr)rrxrrrrƒÜszHTMLParser.handle_endtagcCsdS)Nr)rrYrrrrPàszHTMLParser.handle_charrefcCsdS)Nr)rrYrrrrSäszHTMLParser.handle_entityrefcCsdS)Nr)rr-rrrrCèszHTMLParser.handle_datacCsdS)Nr)rr-rrrr`ìszHTMLParser.handle_commentcCsdS)Nr)rZdeclrrrr]ðszHTMLParser.handle_declcCsdS)Nr)rr-rrrrdôszHTMLParser.handle_picCs|jr| d|f¡dS)Nzunknown declaration: %r)r#r2)rr-rrrÚ unknown_decl÷szHTMLParser.unknown_declcCs"d|kr |Sdd„}t d||¡S)Nr?cSsü| ¡d}yX|ddkrb|dd…}|ddkrLt|dd… d¡dƒ}nt| d¡ƒ}t|ƒSWntk r|d|SXddlm}||krš||S| d¡r¬d |SxJtd t |ƒƒD]0}|d|…|kr¼||d|…||d…Sq¼Wd |SdS) Nrú#r )ÚxÚXr>éz&#)Úhtml5r?r) ÚgroupsÚintÚrstripÚchrÚ ValueErrorZfuture.backports.html.entitiesr‰rrÚranger@)ÚsÚcr‰r†rrrÚreplaceEntitiesÿs&         z,HTMLParser.unescape..replaceEntitiesz&&(#?[xX]?(?:[0-9a-fA-F]+;|\w{1,32};?)))r6Úsub)rrr’rrrrmüs zHTMLParser.unescape)F)r ) rrrrrurr$r.r/r2r3r4r:r;r,rLr^rKrHrirIrsrtrƒrPrSrCr`r]rdr„rmrrrrrds:  h  9+*r) rÚ __future__rrrrZfuture.builtinsZfuture.backportsrr6r r7r(rTrRrNrFrcZ commentcloserjr‚rkrlÚVERBOSEr}r~r€rÚ Exceptionr r+rrrrrÚs4