§
     MºfK:  ã                   ó¶   — d Z dZdgZddlmZ ddlZddlZddl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mZ d	Z G d
„ dee¦  «        Z G d„ de¦  «        ZdS )zCUse the HTMLParser library to parse HTML files that aren't too bad.ÚMITÚHTMLParserTreeBuilderé    )Ú
HTMLParserN)ÚCDataÚCommentÚDeclarationÚDoctypeÚProcessingInstruction)ÚEntitySubstitutionÚUnicodeDammit)ÚDetectsXMLParsedAsHTMLÚParserRejectedMarkupÚHTMLÚHTMLTreeBuilderÚSTRICTzhtml.parserc                   óf   — e Zd ZdZdZdZd„ Zd„ Zd„ Zdd„Z	dd	„Z
d
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚBeautifulSoupHTMLParserz¸A subclass of the Python standard library's HTMLParser class, which
    listens for HTMLParser events and translates them into calls
    to Beautiful Soup's tree construction API.
    ÚignoreÚreplacec                 ó¦   — |                      d| j        ¦  «        | _        t          j        | g|¢R i |¤Ž g | _        |                      ¦   «          dS )a  Constructor.

        :param on_duplicate_attribute: A strategy for what to do if a
            tag includes the same attribute more than once. Accepted
            values are: REPLACE (replace earlier values with later
            ones, the default), IGNORE (keep the earliest value
            encountered), or a callable. A callable must take three
            arguments: the dictionary of attributes already processed,
            the name of the duplicate attribute, and the most recent value
            encountered.           
        Úon_duplicate_attributeN)ÚpopÚREPLACEr   r   Ú__init__Úalready_closed_empty_elementÚ_initialize_xml_detector)ÚselfÚargsÚkwargss      úV/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/bs4/builder/_htmlparser.pyr   z BeautifulSoupHTMLParser.__init__.   sf   € ð '-§j¢jØ$ d¤lñ'
ô '
ˆÔ#õ 	Ô˜DÐ2 4Ð2Ð2Ð2¨6Ð2Ð2Ð2ð -/ˆÔ)à×%Ò%Ñ'Ô'Ð'Ð'Ð'ó    c                 ó    — t          |¦  «        ‚)N)r   )r   Úmessages     r    ÚerrorzBeautifulSoupHTMLParser.errorJ   s   € õ # 7Ñ+Ô+Ð+r!   c                 ó`   — |                       ||d¬¦  «        }|                      |¦  «         dS )zÏHandle an incoming empty-element tag.

        This is only called when the markup looks like <tag/>.

        :param name: Name of the tag.
        :param attrs: Dictionary of the tag's attributes.
        F)Úhandle_empty_elementN)Úhandle_starttagÚhandle_endtag)r   ÚnameÚattrsÚtags       r    Úhandle_startendtagz*BeautifulSoupHTMLParser.handle_startendtagZ   s8   € ð ×"Ò" 4¨ÀUÐ"ÑKÔKˆØ×Ò˜4Ñ Ô Ð Ð Ð r!   Tc                 ó¾  — i }|D ]F\  }}|€d}||v r2| j         }|| j        k    rn$|d| j        fv r|||<   n ||||¦  «         n|||<   d}ŒG|                      ¦   «         \  }	}
| j                             |dd||	|
¬¦  «        }|r:|j        r3|r1|                      |d¬¦  «         | j         	                    |¦  «         | j
        €|                      |¦  «         dS dS )a3  Handle an opening tag, e.g. '<tag>'

        :param name: Name of the tag.
        :param attrs: Dictionary of the tag's attributes.
        :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Ú z"")Ú
sourcelineÚ	sourceposF)Úcheck_already_closed)r   ÚIGNOREr   ÚgetposÚsoupr'   Úis_empty_elementr(   r   ÚappendÚ	_root_tagÚ_root_tag_encountered)r   r)   r*   r&   Ú	attr_dictÚkeyÚvalueÚon_dupeÚ	attrvaluer/   r0   r+   s               r    r'   z'BeautifulSoupHTMLParser.handle_starttagi   sG  € ð ˆ	Øð 	ð 	‰JˆC�ð ˆ}Ø�Ø�iÐÐð Ô5�Ø˜dœkÒ)Ð)ØØ  t¤|Ð 4Ð4Ð4Ø%*�I˜c‘N�Nà�G˜I s¨EÑ2Ô2Ð2Ð2à!&�	˜#‘ØˆIˆIà $§¢¡¤Ñˆ
�IØŒi×'Ò'Ø�$˜˜i°JØð (ñ 
ô 
ˆð ð 	;�3Ô'ð 	;Ð,@ð 	;ð ×Ò˜t¸%ÐÑ@Ô@Ð@ð Ô-×4Ò4°TÑ:Ô:Ð:àŒ>Ð!Ø×&Ò& tÑ,Ô,Ð,Ð,Ð,ð "Ð!r!   c                 óˆ   — |r%|| j         v r| j                              |¦  «         dS | j                             |¦  «         dS )zõHandle a closing tag, e.g. '</tag>'
        
        :param name: 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)r   Úremover4   r(   )r   r)   r1   s      r    r(   z%BeautifulSoupHTMLParser.handle_endtag    sT   € ð  ð 	* D¨DÔ,MÐ$MÐ$Mð
 Ô-×4Ò4°TÑ:Ô:Ð:Ð:Ð:àŒI×#Ò# DÑ)Ô)Ð)Ð)Ð)r!   c                 ó:   — | j                              |¦  «         dS )z4Handle some textual data that shows up between tags.N)r4   Úhandle_data©r   Údatas     r    rA   z#BeautifulSoupHTMLParser.handle_data²   s   € àŒ	×Ò˜dÑ#Ô#Ð#Ð#Ð#r!   c                 óJ  — |                      d¦  «        r$t          |                     d¦  «        d¦  «        }nH|                      d¦  «        r$t          |                     d¦  «        d¦  «        }nt          |¦  «        }d}|dk     rO| j        j        dfD ]@}|sŒ	 t          |g¦  «                             |¦  «        }Œ*# t          $ r
}Y d}~Œ9d}~ww xY w|s/	 t          |¦  «        }n# t          t          f$ r
}Y d}~nd}~ww xY w|pd}|                      |¦  «         dS )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é   ÚXNé   zwindows-1252u   ï¿½)Ú
startswithÚintÚlstripr4   Úoriginal_encodingÚ	bytearrayÚdecodeÚUnicodeDecodeErrorÚchrÚ
ValueErrorÚOverflowErrorrA   )r   r)   Ú	real_namerC   ÚencodingÚes         r    Úhandle_charrefz&BeautifulSoupHTMLParser.handle_charref¶   sa  € ð �?Š?˜3ÑÔð 	"Ý˜DŸKšK¨Ñ,Ô,¨bÑ1Ô1ˆIˆIØ�_Š_˜SÑ!Ô!ð 	"Ý˜DŸKšK¨Ñ,Ô,¨bÑ1Ô1ˆIˆIå˜D™	œ	ˆIàˆØ�sŠ?ˆ?ð "œYÔ8¸.ÐIð ð �Øð ØðÝ$ i [Ñ1Ô1×8Ò8¸ÑBÔB�D�DøÝ)ð ð ð Ø�D�D�D�Døøøøðøøøàð 	ðÝ˜9‘~”~��øÝ¥Ð.ð ð ð Ø����øøøøðøøøàÐ2Ð2ˆØ×Ò˜ÑÔÐÐÐs$   Â#CÃ
CÃCÃC, Ã,DÄDc                 ó‚   — t           j                             |¦  «        }|�|}nd|z  }|                      |¦  «         dS )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ÚgetrA   )r   r)   Ú	characterrC   s       r    Úhandle_entityrefz(BeautifulSoupHTMLParser.handle_entityrefÞ   sL   € õ 'Ô?×CÒCÀDÑIÔIˆ	ØÐ ØˆDˆDð ˜4‘<ˆDØ×Ò˜ÑÔÐÐÐr!   c                 óª   — | j                              ¦   «          | j                              |¦  «         | j                              t          ¦  «         dS )zOHandle an HTML comment.

        :param data: The text of the comment.
        N)r4   ÚendDatarA   r   rB   s     r    Úhandle_commentz&BeautifulSoupHTMLParser.handle_commentñ   sJ   € ð
 	Œ	×ÒÑÔÐØŒ	×Ò˜dÑ#Ô#Ð#ØŒ	×Ò�'Ñ"Ô"Ð"Ð"Ð"r!   c                 óØ   — | j                              ¦   «          |t          d¦  «        d…         }| j                              |¦  «         | j                              t          ¦  «         dS )zYHandle a DOCTYPE declaration.

        :param data: The text of the declaration.
        zDOCTYPE N)r4   r]   ÚlenrA   r	   rB   s     r    Úhandle_declz#BeautifulSoupHTMLParser.handle_declú   s`   € ð
 	Œ	×ÒÑÔÐØ•C˜
‘O”OÐ$Ð$Ô%ˆØŒ	×Ò˜dÑ#Ô#Ð#ØŒ	×Ò�'Ñ"Ô"Ð"Ð"Ð"r!   c                 ó:  — |                      ¦   «                              d¦  «        rt          }|t          d¦  «        d…         }nt          }| j                             ¦   «          | j                             |¦  «         | j                             |¦  «         dS )z{Handle a declaration of unknown type -- probably a CDATA block.

        :param data: The text of the declaration.
        zCDATA[N)ÚupperrI   r   r`   r   r4   r]   rA   )r   rC   Úclss      r    Úunknown_declz$BeautifulSoupHTMLParser.unknown_decl  sˆ   € ð
 �:Š:‰<Œ<×"Ò" 8Ñ,Ô,ð 	ÝˆCØ�˜H™œ˜˜Ô'ˆDˆDåˆCØŒ	×ÒÑÔÐØŒ	×Ò˜dÑ#Ô#Ð#ØŒ	×Ò˜#ÑÔÐÐÐr!   c                 óÔ   — | j                              ¦   «          | j                              |¦  «         |                      |¦  «         | j                              t          ¦  «         dS )z\Handle a processing instruction.

        :param data: The text of the instruction.
        N)r4   r]   rA   Ú_document_might_be_xmlr
   rB   s     r    Ú	handle_piz!BeautifulSoupHTMLParser.handle_pi  s_   € ð
 	Œ	×ÒÑÔÐØŒ	×Ò˜dÑ#Ô#Ð#Ø×#Ò# DÑ)Ô)Ð)ØŒ	×ÒÕ/Ñ0Ô0Ð0Ð0Ð0r!   N)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r2   r   r   r$   r,   r'   r(   rA   rV   r[   r^   ra   re   rh   © r!   r    r   r   $   sê   € € € € € ðð ð €FØ€Gð(ð (ð (ð8,ð ,ð ,ð !ð !ð !ð5-ð 5-ð 5-ð 5-ðn*ð *ð *ð *ð$$ð $ð $ð&ð &ð &ðPð ð ð&#ð #ð #ð#ð #ð #ðð ð ð1ð 1ð 1ð 1ð 1r!   r   c                   óP   ‡ — e Zd ZdZdZdZeZeee	gZ
dZdˆ fd„	Z	 	 d	d„Zd„ Zˆ xZS )
r   zpA Beautiful soup `TreeBuilder` that uses the `HTMLParser` parser,
    found in the Python standard library.
    FTNc                 ó   •— t          ¦   «         }dD ] }||v r|                     |¦  «        }|||<   Œ! t          t          | ¦  «        j        di |¤Ž |pg }|pi }|                     |¦  «         d|d<   ||f| _        dS )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_charrefsNrm   )Údictr   Úsuperr   r   ÚupdateÚparser_args)r   rt   Úparser_kwargsr   Úextra_parser_kwargsÚargr;   Ú	__class__s          €r    r   zHTMLParserTreeBuilder.__init__*  s­   ø€ õ #™fœfÐØ.ð 	1ð 	1ˆCØ�fˆ}ˆ}ØŸ
š
 3™œ�Ø+0Ð# CÑ(øØ3�Õ# TÑ*Ô*Ô3Ð=Ð=°fÐ=Ð=Ð=Ø!Ð' RˆØ%Ð+¨ˆØ×ÒÐ0Ñ1Ô1Ð1Ø,1ˆÐ(Ñ)Ø'¨Ð7ˆÔÐÐr!   c              #   ó¼   K  — t          |t          ¦  «        r
|dddfV — dS |g}|g}||g}t          |||d|¬¦  «        }|j        |j        |j        |j        fV — dS )aÜ  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 converting the
         document to Unicode and parsing it. Each strategy will be tried 
         in turn.
        NFT)Úknown_definite_encodingsÚuser_encodingsÚis_htmlÚexclude_encodings)Ú
isinstanceÚstrr   ÚmarkuprL   Údeclared_html_encodingÚcontains_replacement_characters)	r   r€   Úuser_specified_encodingÚdocument_declared_encodingr}   rz   r{   Útry_encodingsÚdammits	            r    Úprepare_markupz$HTMLParserTreeBuilder.prepare_markupC  s­   è è € õ* �f�cÑ"Ô"ð 	à˜4  uÐ-Ð-Ð-Ð-ØˆFð %<Ð#<Ð ð 5Ð5ˆà0Ð2LÐMˆÝØØ%=Ø)ØØ/ð
ñ 
ô 
ˆð Œ}˜fÔ6ØÔ,ØÔ5ð7ð 	7ð 	7ð 	7ð 	7ð 	7r!   c                 óð   — | j         \  }}t          |i |¤Ž}| j        |_        	 |                     |¦  «         |                     ¦   «          n!# t
          $ r}t          |¦  «        ‚d}~ww xY wg |_        dS )z{Run some incoming markup through some parsing process,
        populating the `BeautifulSoup` object in self.soup.
        N)rt   r   r4   ÚfeedÚcloseÚAssertionErrorr   r   )r   r€   r   r   ÚparserrU   s         r    r‰   zHTMLParserTreeBuilder.feedt  s�   € ð Ô'‰ˆˆfÝ(¨$Ð9°&Ð9Ð9ˆØ”iˆŒð	*Ø�KŠK˜ÑÔÐØ�LŠL‰NŒNˆNˆNøÝð 	*ð 	*ð 	*õ ' qÑ)Ô)Ð)øøøøð		*øøøð
 /1ˆÔ+Ð+Ð+s   ¤)A Á
A,ÁA'Á'A,)NN)NNN)ri   rj   rk   rl   Úis_xmlÚ	picklableÚ
HTMLPARSERÚNAMEr   r   ÚfeaturesÚTRACKS_LINE_NUMBERSr   r‡   r‰   Ú__classcell__)rx   s   @r    r   r     s™   ø€ € € € € ðð ð €FØ€IØ€DØ�d˜FÐ#€Hð Ðð8ð 8ð 8ð 8ð 8ð 8ð2 >BØJNð/7ð /7ð /7ð /7ðb1ð 1ð 1ð 1ð 1ð 1ð 1r!   )rl   Ú__license__Ú__all__Úhtml.parserr   ÚsysÚwarningsÚbs4.elementr   r   r   r	   r
   Ú
bs4.dammitr   r   Úbs4.builderr   r   r   r   r   r�   r   r   rm   r!   r    ú<module>rœ      se  ðà IÐ Ið €ð ð€ð #Ð "Ð "Ð "Ð "Ð "à 
€
€
€
Ø €€€ðð ð ð ð ð ð ð ð ð ð ð ð ð ð 9Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8ðð ð ð ð ð ð ð ð ð ð ð ð ð ð €
ðv1ð v1ð v1ð v1ð v1˜jÐ*@ñ v1ô v1ð v1ðrf1ð f1ð f1ð f1ð f1˜Oñ f1ô f1ð f1ð f1ð f1r!   