Ë
    j¦zi%D  ã                  ó2  — d Z ddlmZ dZdgZddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZ ddlmZmZ dd	lmZmZm Z m!Z! dd
l"m#Z# erddl$m%Z% ddlm&Z& ddl'm(Z(m)Z)m*Z* dZ+e	ee,e,f   e,e,gdf   Z- G d„ dee«      Z. G d„ de «      Z/y)zCUse the HTMLParser library to parse HTML files that aren't too bad.é    )ÚannotationsÚMITÚHTMLParserTreeBuilder)Ú
HTMLParser)ÚAnyÚCallableÚcastÚDictÚIterableÚListÚOptionalÚTYPE_CHECKINGÚTupleÚTypeÚUnion)ÚAttributeDictÚCDataÚCommentÚDeclarationÚDoctypeÚProcessingInstruction)ÚEntitySubstitutionÚUnicodeDammit)ÚDetectsXMLParsedAsHTMLÚHTMLÚHTMLTreeBuilderÚSTRICT©ÚParserRejectedMarkup)ÚBeautifulSoup)ÚNavigableString)Ú	_EncodingÚ
_EncodingsÚ
_RawMarkupzhtml.parserNc                  óÞ   — e Zd ZU dZded<   dZded<   	 edœ	 	 	 	 	 	 	 dd„Zd
ed	<   ded<   ded<   dd„Z	 	 	 	 	 	 dd„Z	 d	 	 	 	 	 	 	 dd„Z	ddd„Z
d d„Zd!d„Zd!d„Zd d„Zd"d„Zd d„Zd d„Zy)#ÚBeautifulSoupHTMLParserÚreplaceÚstrÚREPLACEÚignoreÚIGNORE©Úon_duplicate_attributeÚsoupr    r-   ú&Union[str, _DuplicateAttributeHandler]c               ó¶   — || _         || _        |j                  j                  | _        t	        j
                  | g|¢­i |¤Ž g | _        | j                  «        y ©N)r.   r-   ÚbuilderÚattribute_dict_classr   Ú__init__Úalready_closed_empty_elementÚ_initialize_xml_detector)Úselfr.   r-   ÚargsÚkwargss        úN/home/htdocs/ttos/venv/lib/python3.12/site-packages/bs4/builder/_htmlparser.pyr4   z BeautifulSoupHTMLParser.__init__T   sS   € ð ˆŒ	Ø&<ˆÔ#Ø$(§L¡L×$EÑ$EˆÔ!Ü×Ñ˜DÐ2 4Ò2¨6Ò2ð -/ˆÔ)à×%Ñ%Õ'ó    z	List[str]r5   c                ó   — t        |«      ‚r1   r   )r7   Úmessages     r:   ÚerrorzBeautifulSoupHTMLParser.erroro   s   € ô # 7Ó+Ð+r;   c                óN   — | j                  ||d¬«       | j                  |«       y)z…Handle an incoming empty-element tag.

        html.parser only calls this method when the markup looks like
        <tag/>.
        F)Úhandle_empty_elementN)Úhandle_starttagÚhandle_endtag)r7   ÚtagÚattrss      r:   Úhandle_startendtagz*BeautifulSoupHTMLParser.handle_startendtag   s'   € ð 	×Ñ˜S %¸eÐÔDØ×Ñ˜3Õr;   c                óV  — | j                  «       }|D ]_  \  }}|€d}||v rM| j                  }|| j                  k(  rŒ*|d| j                  fv r|||<   Œ@t	        t
        |«      } ||||«       Œ[|||<   Œa | j                  j                  j                  r| j                  «       \  }}	ndx}}	| j                  j                  |dd|||	¬«      }
|
�<|
j                  r0|r.| j                  |d¬«       | j                  j                  |«       | j                  €| j!                  |«       yy)zÓHandle an opening tag, e.g. '<tag>'

        :param handle_empty_element: True if this tag is known to be
            an empty-element tag (i.e. there is not expected to be any
            closing tag).
        NÚ )Ú
sourcelineÚ	sourceposF)Úcheck_already_closed)r3   r-   r+   r)   r	   Ú_DuplicateAttributeHandlerr.   r2   Ústore_line_numbersÚgetposrA   Úis_empty_elementrB   r5   ÚappendÚ_root_tag_nameÚ_root_tag_encountered)r7   rC   rD   r@   Ú	attr_dictÚkeyÚvalueÚon_duperH   rI   ÚtagObjs              r:   rA   z'BeautifulSoupHTMLParser.handle_starttagŽ   sC  € ð $(×#<Ñ#<Ó#>ˆ	Øò 	'‰JˆC�ð ˆ}Ø�Ø�iÑð ×5Ñ5�Ø˜dŸk™kÒ)ØØ  t§|¡|Ð 4Ñ4Ø%*�I˜c’Nä"Ô#=¸wÓG�GÙ˜I s¨EÕ2à!&�	˜#’ð%	'ð, �9‰9×Ñ×/Ò/Ø$(§K¡K£MÑ!ˆJ™	à%)Ð)ˆJ˜Ø—‘×*Ñ*Ø��t˜Y°:Èð +ó 
ˆð Ð &×"9Ò"9Ñ>Rð ×Ñ˜s¸ÐÔ?ð ×-Ñ-×4Ñ4°SÔ9à×ÑÐ&Ø×&Ñ& sÕ+ð 'r;   c                ó’   — |r*|| j                   v r| j                   j                  |«       y| j                  j                  |«       y)zìHandle a closing tag, e.g. '</tag>'

        :param tag: A tag name.
        :param check_already_closed: True if this tag is expected to
           be the closing portion of an empty-element tag,
           e.g. '<tag></tag>'.
        N)r5   Úremover.   rB   )r7   rC   rJ   s      r:   rB   z%BeautifulSoupHTMLParser.handle_endtagÌ   s<   € ñ   C¨4×+LÑ+LÑ$Lð
 ×-Ñ-×4Ñ4°SÕ9à�I‰I×#Ñ# CÕ(r;   c                ó:   — | j                   j                  |«       y)z4Handle some textual data that shows up between tags.N)r.   Úhandle_data©r7   Údatas     r:   rZ   z#BeautifulSoupHTMLParser.handle_dataÞ   s   € à�	‰	×Ñ˜dÕ#r;   c                óF  — |j                  d«      rt        |j                  d«      d«      }n8|j                  d«      rt        |j                  d«      d«      }nt        |«      }t        j                  |«      \  }}|rd| j
                  _        | j                  |«       y)z×Handle a numeric character reference by converting it to the
        corresponding Unicode character and treating it as textual
        data.

        :param name: Character number, possibly in hexadecimal.
        Úxé   ÚXTN)Ú
startswithÚintÚlstripr   Únumeric_character_referencer.   Úcontains_replacement_charactersrZ   )r7   ÚnameÚ	real_namer\   Úreplacement_addeds        r:   Úhandle_charrefz&BeautifulSoupHTMLParser.handle_charrefâ   s‚   € ð �?‰?˜3ÔÜ˜DŸK™K¨Ó,¨bÓ1‰IØ�_‰_˜SÔ!Ü˜DŸK™K¨Ó,¨bÓ1‰Iä˜D›	ˆIä"/×"KÑ"KÈIÓ"VÑˆÐÙØ8<ˆD�I‰IÔ5Ø×Ñ˜Õr;   c                óx   — t         j                  j                  |«      }|�|}nd|z  }| j                  |«       y)zÈHandle a named entity reference by converting it to the
        corresponding Unicode character(s) and treating it as textual
        data.

        :param name: Name of the entity reference.
        Nz&%s)r   ÚHTML_ENTITY_TO_CHARACTERÚgetrZ   )r7   rf   Ú	characterr\   s       r:   Úhandle_entityrefz(BeautifulSoupHTMLParser.handle_entityrefú   s>   € ô '×?Ñ?×CÑCÀDÓIˆ	ØÐ Ø‰Dð ˜4‘<ˆDØ×Ñ˜Õr;   c                ó¬   — | j                   j                  «        | j                   j                  |«       | j                   j                  t        «       y)zOHandle an HTML comment.

        :param data: The text of the comment.
        N)r.   ÚendDatarZ   r   r[   s     r:   Úhandle_commentz&BeautifulSoupHTMLParser.handle_comment  s8   € ð
 	�	‰	×ÑÔØ�	‰	×Ñ˜dÔ#Ø�	‰	×Ñœ'Õ"r;   c                óÈ   — | j                   j                  «        |t        d«      d }| j                   j                  |«       | j                   j                  t        «       y)zYHandle a DOCTYPE declaration.

        :param data: The text of the declaration.
        zDOCTYPE N)r.   rp   ÚlenrZ   r   )r7   Údecls     r:   Úhandle_declz#BeautifulSoupHTMLParser.handle_decl  sI   € ð
 	�	‰	×ÑÔØ”C˜
“OÐ%Ð&ˆØ�	‰	×Ñ˜dÔ#Ø�	‰	×Ñœ'Õ"r;   c                ó  — |j                  «       j                  d«      rt        }|t        d«      d }nt        }| j
                  j                  «        | j
                  j                  |«       | j
                  j                  |«       y)z{Handle a declaration of unknown type -- probably a CDATA block.

        :param data: The text of the declaration.
        zCDATA[N)Úupperra   r   rs   r   r.   rp   rZ   )r7   r\   Úclss      r:   Úunknown_declz$BeautifulSoupHTMLParser.unknown_decl   sf   € ð �:‰:‹<×"Ñ" 8Ô,ÜˆCØœ˜H›˜Ð(‰DäˆCØ�	‰	×ÑÔØ�	‰	×Ñ˜dÔ#Ø�	‰	×Ñ˜#Õr;   c                óÎ   — | j                   j                  «        | j                   j                  |«       | j                  |«       | j                   j                  t        «       y)z\Handle a processing instruction.

        :param data: The text of the instruction.
        N)r.   rp   rZ   Ú_document_might_be_xmlr   r[   s     r:   Ú	handle_piz!BeautifulSoupHTMLParser.handle_pi/  sG   € ð
 	�	‰	×ÑÔØ�	‰	×Ñ˜dÔ#Ø×#Ñ# DÔ)Ø�	‰	×ÑÔ/Õ0r;   N)r.   r    r8   r   r-   r/   r9   r   )r=   r(   ÚreturnÚNone)rC   r(   rD   úList[Tuple[str, Optional[str]]]r}   r~   )T)rC   r(   rD   r   r@   Úboolr}   r~   )rC   r(   rJ   r€   r}   r~   )r\   r(   r}   r~   )rf   r(   r}   r~   )rt   r(   r}   r~   )Ú__name__Ú
__module__Ú__qualname__r)   Ú__annotations__r+   r4   r>   rE   rA   rB   rZ   ri   rn   rq   ru   ry   r|   © r;   r:   r&   r&   =   sâ   … ð €GˆSÓð €FˆCÓðð$ JQñ	(àð(ð ð(ð !Gð	(ð
 ó(ð. CÓBØ"+Ó+Ø
Óó,ð  Øð Ø>ð à	ó ð& &*ð	<,àð<,ð /ð<,ð #ð	<,ð
 
ó<,ô|)ó$$óó0ó&#ó#óô1r;   r&   c                  óº   ‡ — e Zd ZU dZdZded<   dZded<   eZded<   ee	e
gZd	ed
<   ded<   dZded<   	 	 d	 	 	 	 	 dˆ fd„Z	 	 	 d	 	 	 	 	 	 	 	 	 dd„Zefdd„Zˆ xZS )r   z—A Beautiful soup `bs4.builder.TreeBuilder` that uses the
    :py:class:`html.parser.HTMLParser` parser, found in the Python
    standard library.

    Fr€   Úis_xmlTÚ	picklabler(   ÚNAMEzIterable[str]Úfeaturesz$Tuple[Iterable[Any], Dict[str, Any]]Úparser_argsÚTRACKS_LINE_NUMBERSc                óÚ   •— t        «       }dD ]  }||v sŒ|j                  |«      }|||<   Œ t        t        | �  di |¤Ž |xs g }|xs i }|j                  |«       d|d<   ||f| _        y)a‚  Constructor.

        :param parser_args: Positional arguments to pass into
            the BeautifulSoupHTMLParser constructor, once it's
            invoked.
        :param parser_kwargs: Keyword arguments to pass into
            the BeautifulSoupHTMLParser constructor, once it's
            invoked.
        :param kwargs: Keyword arguments for the superclass constructor.
        r,   FÚconvert_charrefsNr…   )ÚdictÚpopÚsuperr   r4   Úupdater‹   )r7   r‹   Úparser_kwargsr9   Úextra_parser_kwargsÚargrT   Ú	__class__s          €r:   r4   zHTMLParserTreeBuilder.__init__K  s‹   ø€ ô$ #›fÐØ.ò 	1ˆCØ�fŠ}ØŸ
™
 3›�Ø+0Ð# CÒ(ð	1ô 	Ô# TÑ3Ñ=°fÒ=Ø!Ò' RˆØ%Ò+¨ˆØ×ÑÐ0Ô1Ø,1ˆÐ(Ñ)Ø'¨Ð7ˆÕr;   c              #  ó@  K  — t        |t        «      r	|dddf–— yg }|r|j                  |«       g }|r|j                  |«       t        |||d|¬«      }|j                  €t        d«      ‚|j                  |j                  |j                  |j                  f–— y­w)a2  Run any preliminary steps necessary to make incoming markup
        acceptable to the parser.

        :param markup: Some markup -- probably a bytestring.
        :param user_specified_encoding: The user asked to try this encoding.
        :param document_declared_encoding: The markup itself claims to be
            in this encoding.
        :param exclude_encodings: The user asked _not_ to try any of
            these encodings.

        :yield: A series of 4-tuples: (markup, encoding, declared encoding,
             has undergone character replacement)

            Each 4-tuple represents a strategy for parsing the document.
            This TreeBuilder uses Unicode, Dammit to convert the markup
            into Unicode, so the ``markup`` element of the tuple will
            always be a string.
        NFT)Úknown_definite_encodingsÚuser_encodingsÚis_htmlÚexclude_encodingszPCould not convert input to Unicode, and html.parser will not accept bytestrings.)	Ú
isinstancer(   rO   r   Úunicode_markupr   Úoriginal_encodingÚdeclared_html_encodingre   )r7   ÚmarkupÚuser_specified_encodingÚdocument_declared_encodingr›   r˜   r™   Údammits           r:   Úprepare_markupz$HTMLParserTreeBuilder.prepare_markupi  sÂ   è ø€ ô2 �fœcÔ"à˜4  uÐ-Ò-Øð 57Ð Ù"ð
 %×+Ñ+Ð,CÔDà*,ˆÙ%ð ×!Ñ!Ð"<Ô=äØØ%=Ø)ØØ/ô
ˆð × Ñ Ð(ô 'Øbóð ð
 ×%Ñ%Ø×(Ñ(Ø×-Ñ-Ø×6Ñ6ð	ó ùs   ‚BBc                ó  — | j                   \  }}t        |t        «      sJ ‚| j                  €J ‚ || j                  g|¢­i |¤Ž}	 |j	                  |«       |j                  «        g |_        y# t        $ r}t        |«      ‚d}~ww xY w)z®
        :param markup: The markup to feed into the parser.
        :param _parser_class: An HTMLParser subclass to use. This is only intended for use in unit tests.
        N)	r‹   rœ   r(   r.   ÚfeedÚcloseÚAssertionErrorr   r5   )r7   r    Ú_parser_classr8   r9   ÚparserÚes          r:   r¦   zHTMLParserTreeBuilder.feed±  s’   € ð
 ×'Ñ'‰ˆˆfô ˜&¤#Ô&Ð&Ð&ð
 �y‰yÐ$Ð$Ð$Ù˜tŸy™yÐ:¨4Ò:°6Ñ:ˆð	*Ø�K‰K˜ÔØ�L‰LŒNð /1ˆÕ+øô ò 	*ô ' qÓ)Ð)ûð		*ús   Á!A0 Á0	B	Á9BÂB	)NN)r‹   zOptional[Iterable[Any]]r“   zOptional[Dict[str, Any]]r9   r   )NNN)
r    r$   r¡   úOptional[_Encoding]r¢   r¬   r›   zOptional[_Encodings]r}   zDIterable[Tuple[str, Optional[_Encoding], Optional[_Encoding], bool]])r    r$   r©   ztype[BeautifulSoupHTMLParser]r}   r~   )r�   r‚   rƒ   Ú__doc__r‡   r„   rˆ   Ú
HTMLPARSERr‰   r   r   rŠ   rŒ   r4   r¤   r&   r¦   Ú__classcell__)r–   s   @r:   r   r   :  sÏ   ø… ñð €FˆDÓØ€IˆtÓØ€Dˆ#ÓØ# T¨6Ð2€HˆmÓ2Ø5Ó5ð !%Ð˜Ó$ð 04Ø26ð8à,ð8ð 0ð8ð õ	8ðB 8<Ø:>Ø26ðFàðFð "5ðFð %8ð	Fð
 0ðFð 
NóFðP Ul÷ 1ð 1r;   )0r­   Ú
__future__r   Ú__license__Ú__all__Úhtml.parserr   Útypingr   r   r	   r
   r   r   r   r   r   r   r   Úbs4.elementr   r   r   r   r   r   Ú
bs4.dammitr   r   Úbs4.builderr   r   r   r   Úbs4.exceptionsr   Úbs4r    r!   Úbs4._typingr"   r#   r$   r®   r(   rK   r&   r   r…   r;   r:   ú<module>r»      s®   ðá IÝ "ð €ð ð€õ #÷÷ ÷ ñ ÷÷ ÷ 9÷ó õ 0áÝ!Ý+÷ñ ð €
à% t¨C°¨H¡~°s¸CÐ&@À$Ð&FÑGÐ ôz1˜jÐ*@ô z1ôzT1˜Oõ T1r;   