o ÏÓçh!Pã@sÞdZddlZddlZddlmZdgZe d¡Ze d¡Ze d¡Z e d¡Z e d ¡Z e d ¡Z e d ¡Z e d ¡Ze d ¡Ze d¡Ze dej¡Ze dej¡Ze dej¡Ze d ¡Ze d¡ZGdd„dejƒZdS)zA parser for HTML and XHTML.éN)ÚunescapeÚ HTMLParserz[&<]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 z--!?>z-?>z0([a-zA-Z][^\t\n\r\f />]*)(?:[\t\n\r\f ]|/(?!>))*a{ ( (?<=['"\t\n\r\f /])[^\t\n\r\f />][^\t\n\r\f /=>]* # attribute name ) ([\t\n\r\f ]*=[\t\n\r\f ]* # value indicator ('[^']*' # LITA-enclosed value |"[^"]*" # LIT-enclosed value |(?!['"])[^>\t\n\r\f ]* # bare value ) )? (?:[\t\n\r\f ]|/(?!>))* # possibly followed by a space a [a-zA-Z][^\t\n\r\f />]* # tag name [\t\n\r\f /]* # optional whitespace before attribute name (?:(?<=['"\t\n\r\f /])[^\t\n\r\f />][^\t\n\r\f /=>]* # attribute name (?:[\t\n\r\f ]*=[\t\n\r\f ]* # value indicator (?:'[^']*' # LITA-enclosed value |"[^"]*" # LIT-enclosed value |(?!['"])[^>\t\n\r\f ]* # bare value ) )? [\t\n\r\f /]* # possibly followed by a space )* >? aF <[a-zA-Z][^\t\n\r\f />\x00]* # 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 space )?(?:\s|/(?!>))* )* )? \s* # trailing whitespace z#c@sþeZdZdZdZdZddœdd„Zdd „Zd d „Zd d „Z dZ dd„Z ddœdd„Z dd„Z d>dd„Zdd„Zdd„Zd>dd„Zd?d d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Zd6d7„Zd8d9„Zd:d;„Zd'.)Ú_HTMLParser__starttag_textrr r r Úget_starttag_text•szHTMLParser.get_starttag_textF©Ú escapablecCsZ| ¡|_||_|r|jst d|jtjtjB¡|_dSt d|jtjtjB¡|_dS)Nz&|])z])) ÚlowerrrrÚreÚcompileÚ IGNORECASEÚASCIIr)rÚelemr r r r Úset_cdata_mode™s     ÿ   ÿzHTMLParser.set_cdata_modecCst|_d|_d|_dS)NT)rrrrrr r r Úclear_cdata_mode£s zHTMLParser.clear_cdata_modecCs ||_dS)aEnable or disable support of the CDATA sections. If enabled, "<[CDATA[" starts a CDATA section which ends with "]]>". If disabled, "<[CDATA[" starts a bogus comments which ends with ">". This method is not called by default. Its purpose is to be called in custom handle_starttag() and handle_endtag() methods, with value that depends on the adjusted current node. See https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state for details. N)r)rÚflagr r r Ú_set_support_cdata¨s zHTMLParser._set_support_cdatac Cs|j}d}t|ƒ}||krU|jr;|js;| d|¡}|dkr:| dt||dƒ¡}|dkr8t d¡  ||¡s8n|}n|j   ||¡}|rI|  ¡}n|jrNn|}||kro|jrf|j rf|  t|||…ƒ¡n |  |||…¡| ||¡}||kr{nÚ|j}|d|ƒrt ||¡r| |¡} n@|d|ƒr›| |¡} n5|d|ƒr¦| |¡} n*|d|ƒr±| |¡} n|d |ƒr¼| |¡} n|d |ksÄ|rÎ|  d¡|d } nn…| dkr‰|sÙn|t ||¡ràn§|d|ƒr|d |krò|  d¡n•t ||¡rùnŽ| ||d d…¡n‚|d|ƒr0|}d D]} | | |d ¡r"|t| ƒ8}nq| ||d |…¡nW|d|ƒrF|jrF| ||dd…¡nA|||d… ¡dkr_| ||d d…¡n(|d |ƒrq| ||d d…¡n|d|ƒrƒ| ||d d…¡nt dƒ‚|} | || ¡}nÁ|d|ƒràt! ||¡}|rÃ| "¡d d…} | #| ¡| $¡} |d| d ƒs¼| d } | || ¡}q d||d…vrß|  |||d …¡| ||d ¡}nu|d|ƒrQt% ||¡}|r| "d ¡} | &| ¡| $¡} |d| d ƒs | d } | || ¡}q t' ||¡}|r;|r:| "¡||d…kr:| $¡} | |kr2|} | ||d ¡}n|d |krP|  d¡| ||d ¡}nn||ks|r€||kr€|jrq|j rq|  t|||…ƒ¡n |  |||…¡| ||¡}||d…|_dS)Nrú<ú&é"z [\t\n\r\f ;]zrr6r3r5rr/rzÚ reTr)rÚcheck_for_whole_start_tagr Útagfind_tolerantrArQrOr!rÚattrfind_tolerantrÚappendÚstripZgetposÚcountr8r:r>rIÚhandle_startendtagÚhandle_starttagÚCDATA_CONTENT_ELEMENTSr'ÚRCDATA_CONTENT_ELEMENTS)rrUÚendposr ÚattrsrArXÚtagÚmÚattrnameÚrestZ attrvaluerQÚlinenoÚoffsetr r r rBs\  &( ó   ÿ   û   þzHTMLParser.parse_starttagcCs6|j}t ||d¡}| ¡}||ddkrdS|S)Nrrr6)r Ú locatetagendrArQrbr r r rgÄs z$HTMLParser.check_for_whole_start_tagcCs´|j}| d|d¡dkrdSt ||¡s*||d|d…dkr%|dS| |¡St ||d¡}| ¡}||ddkr@dSt ||d¡}| d¡  ¡}|  |¡|  ¡|S)Nrr/rr6r3r) r r9rGrAr\ryrQrhrOr!Ú handle_endtagr()rrUr rArWrsr r r rCÎs    zHTMLParser.parse_endtagcCs| ||¡| |¡dS©N)rnrz©rrsrrr r r rmìs zHTMLParser.handle_startendtagcCódSr{r r|r r r rnñózHTMLParser.handle_starttagcCr}r{r )rrsr r r rzõr~zHTMLParser.handle_endtagcCr}r{r ©rrZr r r rPùr~zHTMLParser.handle_charrefcCr}r{r rr r r rSýr~zHTMLParser.handle_entityrefcCr}r{r rr r r r>r~zHTMLParser.handle_datacCr}r{r rr r r rHr~zHTMLParser.handle_commentcCr}r{r )rZdeclr r r rK r~zHTMLParser.handle_declcCr}r{r rr r r rL r~zHTMLParser.handle_picCr}r{r rr r r rJr~zHTMLParser.unknown_decl)T)r)!Ú__name__Ú __module__Ú __qualname__Ú__doc__rorpr rrrrrr'r(r*rrFrDr\rErBrgrCrmrnrzrPrSr>rHrKrLrJr r r r rZs@     "   7  )rƒr"rZhtmlrÚ__all__r#rrTrRrNr@rGrar]r^rhÚVERBOSEriryZlocatestarttagend_tolerantZ endendtagZ endtagfindrrr r r r Ús6             õ  óò