§
    ´BÄjšM  ã                  óT  — d Z ddlmZ dZdgZddlmZ ddl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!¦  «        Z0dS )zCUse the HTMLParser library to parse HTML files that aren't too bad.é    )ÚannotationsÚMITÚHTMLParserTreeBuilder)Ú
HTMLParserN)Ú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.parserc                  ó  — 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d0d„Z	 d1d2d„Z	d1d3d„Z
d4d „Z ej        d!¦  «        Z ej        d"¦  «        Zed5d%„¦   «         Zd6d&„Zd6d'„Zd4d(„Zd7d*„Zd4d+„Zd4d,„Zd-S )8ÚBeautifulSoupHTMLParserÚreplaceÚstrÚREPLACEÚignoreÚIGNORE©Úon_duplicate_attributeÚsoupr    Úargsr   r-   ú&Union[str, _DuplicateAttributeHandler]Úkwargsc               ó¤   — || _         || _        |j        j        | _        t	          j        | g|¢R i |¤Ž g | _        |                      ¦   «          d S ©N)r.   r-   ÚbuilderÚattribute_dict_classr   Ú__init__Úalready_closed_empty_elementÚ_initialize_xml_detector)Úselfr.   r-   r/   r1   s        úHC:\Projects\Historical\venv\Lib\site-packages\bs4/builder/_htmlparser.pyr6   z BeautifulSoupHTMLParser.__init__U   sc   € ð ˆŒ	Ø&<ˆÔ#Ø$(¤LÔ$EˆÔ!ÝÔ˜DÐ2 4Ð2Ð2Ð2¨6Ð2Ð2Ð2ð -/ˆÔ)à×%Ò%Ñ'Ô'Ð'Ð'Ð'ó    z	List[str]r7   ÚmessageÚreturnÚNonec                ó    — t          |¦  «        ‚r3   r   )r9   r<   s     r:   ÚerrorzBeautifulSoupHTMLParser.errorp   s   € õ # 7Ñ+Ô+Ð+r;   ÚtagÚattrsúList[Tuple[str, Optional[str]]]c                ód   — |                       ||d¬¦  «         |                      |d¬¦  «         dS )z…Handle an incoming empty-element tag.

        html.parser only calls this method when the markup looks like
        <tag/>.
        F)Úhandle_empty_element©Úcheck_already_closedN)Úhandle_starttagÚhandle_endtag)r9   rA   rB   s      r:   Úhandle_startendtagz*BeautifulSoupHTMLParser.handle_startendtag€   s@   € ð 	×Ò˜S %¸eÐÑDÔDÐDð 	×Ò˜3°UÐÑ;Ô;Ð;Ð;Ð;r;   TrE   Úboolc                ó4  — |                       ¦   «         }|D ]Y\  }}|€d}||v rG| j        }|| j        k    rŒ |d| j        fv r|||<   Œ1t	          t
          |¦  «        } ||||¦  «         ŒT|||<   ŒZ| j        j        j        r|  	                    ¦   «         \  }}	ndx}}	| j         
                    |dd|||	¬¦  «        }
|
�:|
j        r3|r1|                      |d¬¦  «         | j                             |¦  «         | j        €|                      |¦  «         dS dS )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Ú	sourceposFrF   )r5   r-   r+   r)   r	   Ú_DuplicateAttributeHandlerr.   r4   Ústore_line_numbersÚgetposrH   Úis_empty_elementrI   r7   ÚappendÚ_root_tag_nameÚ_root_tag_encountered)r9   rA   rB   rE   Ú	attr_dictÚkeyÚvalueÚon_duperN   rO   ÚtagObjs              r:   rH   z'BeautifulSoupHTMLParser.handle_starttag”   sv  € ð $(×#<Ò#<Ñ#>Ô#>ˆ	Øð 	'ð 	'‰JˆC�ð ˆ}Ø�Ø�iÐÐð Ô5�Ø˜dœkÒ)Ð)ØØ  t¤|Ð 4Ð4Ð4Ø%*�I˜c‘N�Nå"Õ#=¸wÑGÔG�GØ�G˜I s¨EÑ2Ô2Ð2Ð2à!&�	˜#‘�ð Œ9ÔÔ/ð 	*Ø$(§K¢K¡M¤MÑ!ˆJ˜	˜	à%)Ð)ˆJ˜Ø”×*Ò*Ø��t˜Y°:Èð +ñ 
ô 
ˆð Ð &Ô"9ÐÐ>RÐð ×Ò˜s¸ÐÑ?Ô?Ð?ð Ô-×4Ò4°SÑ9Ô9Ð9àÔÐ&Ø×&Ò& sÑ+Ô+Ð+Ð+Ð+ð 'Ð&r;   rG   c                óˆ   — |r%|| j         v r| j                              |¦  «         dS | j                             |¦  «         dS )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)r7   Úremover.   rI   )r9   rA   rG   s      r:   rI   z%BeautifulSoupHTMLParser.handle_endtagÒ   sT   € ð  ð 	) C¨4Ô+LÐ$LÐ$Lð
 Ô-×4Ò4°SÑ9Ô9Ð9Ð9Ð9àŒI×#Ò# CÑ(Ô(Ð(Ð(Ð(r;   Údatac                ó:   — | j                              |¦  «         dS )z4Handle some textual data that shows up between tags.N)r.   Úhandle_data©r9   r^   s     r:   r`   z#BeautifulSoupHTMLParser.handle_dataä   s   € àŒ	×Ò˜dÑ#Ô#Ð#Ð#Ð#r;   z^([0-9]+)(.*)z^([0-9a-f]+)(.*)ÚnameúTuple[str, bool, str]c                óÚ  — d}d}d}d}| j         }|                     d¦  «        s|                     d¦  «        r|dd…         }d}| j        }d}	 t          ||¦  «        }ni# t          $ r\ |                     |¦  «        }|�Bt          |                     ¦   «         d	         |¦  «        }|                     ¦   «         d         }Y nw xY w|€d}|}nt          j        |¦  «        \  }}|||fS )
a°  Convert a numeric character reference into an actual character.

        :param name: The number of the character reference, as
          obtained by html.parser

        :return: A 3-tuple (dereferenced, replacement_added,
          extra_data). `dereferenced` is the dereferenced character
          reference, or the empty string if there was no
          reference. `replacement_added` is True if the reference
          could only be dereferenced by replacing content with U+FFFD
          REPLACEMENT CHARACTER. `extra_data` is a portion of data
          following the character reference, which was deemed to be
          normal data and not part of the reference at all.
        rM   Fé
   ÚxÚXé   Né   r   )	Ú&_DECIMAL_REFERENCE_WITH_FOLLOWING_DATAÚ
startswithÚ"_HEX_REFERENCE_WITH_FOLLOWING_DATAÚintÚ
ValueErrorÚsearchÚgroupsr   Únumeric_character_reference)	Úclsrb   ÚdereferencedÚreplacement_addedÚ
extra_dataÚbaseÚregÚ	real_nameÚmatchs	            r:   Ú(_dereference_numeric_character_referencez@BeautifulSoupHTMLParser._dereference_numeric_character_referenceë   s  € ð  ˆØ!&ÐØˆ
àˆØÔ8ˆØ�?Š?˜3ÑÔð 	9 4§?¢?°3Ñ#7Ô#7ð 	9à˜˜˜”8ˆDØˆDØÔ8ˆCà"&ˆ	ð	/Ý˜D $™œˆIˆIøÝð 	/ð 	/ð 	/ð —J’J˜tÑ$Ô$ˆEØÐ Ý §¢¡¤¨qÔ 1°4Ñ8Ô8�	Ø"Ÿ\š\™^œ^¨AÔ.�
øøð	/øøøð" ÐØˆLØˆJˆJå.;Ô.WÐXaÑ.bÔ.bÑ+ˆLÐ+ØÐ.°
Ð:Ð:s   ÁA! Á!A#CÃCc                ó´   — |                       |¦  «        \  }}}|rd| j        _        |�|                      |¦  «         |�|                      |¦  «         dS 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.
        TN)rz   r.   Úcontains_replacement_charactersr`   )r9   rb   rs   rt   ru   s        r:   Úhandle_charrefz&BeautifulSoupHTMLParser.handle_charref"  st   € ð 7;×6cÒ6cÐdhÑ6iÔ6iÑ3ˆÐ'¨Øð 	=Ø8<ˆDŒIÔ5ØÐ#Ø×Ò˜\Ñ*Ô*Ð*ØÐ!Ø×Ò˜ZÑ(Ô(Ð(Ð(Ð(ð "Ð!r;   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Úgetr`   )r9   rb   Ú	characterr^   s       r:   Úhandle_entityrefz(BeautifulSoupHTMLParser.handle_entityref1  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)r.   ÚendDatar`   r   ra   s     r:   Úhandle_commentz&BeautifulSoupHTMLParser.handle_commentD  sJ   € ð
 	Œ	×ÒÑÔÐØŒ	×Ò˜dÑ#Ô#Ð#ØŒ	×Ò�'Ñ"Ô"Ð"Ð"Ð"r;   Údeclc                óØ   — | j                              ¦   «          |t          d¦  «        d…         }| j                              |¦  «         | j                              t          ¦  «         dS )zYHandle a DOCTYPE declaration.

        :param data: The text of the declaration.
        zDOCTYPE N)r.   r„   Úlenr`   r   )r9   r†   s     r:   Úhandle_declz#BeautifulSoupHTMLParser.handle_declM  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)Úupperrk   r   rˆ   r   r.   r„   r`   )r9   r^   rr   s      r:   Úunknown_declz$BeautifulSoupHTMLParser.unknown_declW  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)r.   r„   r`   Ú_document_might_be_xmlr   ra   s     r:   Ú	handle_piz!BeautifulSoupHTMLParser.handle_pif  s_   € ð
 	Œ	×ÒÑÔÐØŒ	×Ò˜dÑ#Ô#Ð#Ø×#Ò# DÑ)Ô)Ð)ØŒ	×ÒÕ/Ñ0Ô0Ð0Ð0Ð0r;   N)r.   r    r/   r   r-   r0   r1   r   )r<   r(   r=   r>   )rA   r(   rB   rC   r=   r>   )T)rA   r(   rB   rC   rE   rK   r=   r>   )rA   r(   rG   rK   r=   r>   )r^   r(   r=   r>   )rb   r(   r=   rc   )rb   r(   r=   r>   )r†   r(   r=   r>   )Ú__name__Ú
__module__Ú__qualname__r)   Ú__annotations__r+   r6   r@   rJ   rH   rI   r`   ÚreÚcompilerj   rl   Úclassmethodrz   r}   r‚   r…   r‰   rŒ   r�   © r;   r:   r&   r&   >   s¿  € € € € € € ð €GÐÐÐÑð €FÐÐÐÑðð$ JQð	(ð (ð (ð (ð (ð (ð. CÐBÐBÑBØ+Ð+Ð+Ñ+ØÐÐÑð,ð ,ð ,ð ,ð <ð <ð <ð <ð0 &*ð	<,ð <,ð <,ð <,ð <,ð|)ð )ð )ð )ð )ð$$ð $ð $ð $ð .8¨R¬Z¸Ñ-HÔ-HÐ*Ø)3¨¬Ð4FÑ)GÔ)GÐ&àð4;ð 4;ð 4;ñ „[ð4;ðl)ð )ð )ð )ðð ð ð ð&#ð #ð #ð #ð#ð #ð #ð #ðð ð ð ð1ð 1ð 1ð 1ð 1ð 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.

    FrK   Úis_xmlTÚ	picklabler(   ÚNAMEzIterable[str]Úfeaturesz$Tuple[Iterable[Any], Dict[str, Any]]Úparser_argsÚTRACKS_LINE_NUMBERSNúOptional[Iterable[Any]]Úparser_kwargsúOptional[Dict[str, Any]]r1   r   c                ó   •— 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_charrefsNr—   )ÚdictÚpopÚsuperr   r6   Úupdater�   )r9   r�   r    r1   Úextra_parser_kwargsÚargrY   Ú	__class__s          €r:   r6   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;   Úmarkupr$   Úuser_specified_encodingúOptional[_Encoding]Údocument_declared_encodingÚexclude_encodingsúOptional[_Encodings]r=   úDIterable[Tuple[str, Optional[_Encoding], Optional[_Encoding], bool]]c              #  ó8  K  — t          |t          ¦  «        r
|dddfV — dS g }|r|                     |¦  «         g }|r|                     |¦  «         t          |||d|¬¦  «        }|j        €t          d¦  «        ‚|j        |j        |j        |j        fV — dS )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_htmlr¯   zPCould not convert input to Unicode, and html.parser will not accept bytestrings.)	Ú
isinstancer(   rT   r   Úunicode_markupr   Úoriginal_encodingÚdeclared_html_encodingr|   )r9   r«   r¬   r®   r¯   r³   r´   Údammits           r:   Úprepare_markupz$HTMLParserTreeBuilder.prepare_markup   sý   è è € õ2 �f�cÑ"Ô"ð 	à˜4  uÐ-Ð-Ð-Ð-ØˆFð 57Ð Ø"ð 	Eð
 %×+Ò+Ð,CÑDÔDÐDà*,ˆØ%ð 	>ð ×!Ò!Ð"<Ñ=Ô=Ð=åØØ%=Ø)ØØ/ð
ñ 
ô 
ˆð Ô Ð(õ 'Øbñô ð ð
 Ô%ØÔ(ØÔ-ØÔ6ð	ð ð ð ð ð r;   Ú_parser_classútype[BeautifulSoupHTMLParser]r>   c                ó"  — | j         \  }}t          |t          ¦  «        sJ ‚| j        €J ‚ || j        g|¢R i |¤Ž}	 |                     |¦  «         |                     ¦   «          n!# t          $ r}t          |¦  «        ‚d}~ww xY wg |_        dS )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   r7   )r9   r«   r¼   r/   r1   ÚparserÚes          r:   r¿   zHTMLParserTreeBuilder.feedè  s¾   € ð
 Ô'‰ˆˆfõ ˜&¥#Ñ&Ô&Ð&Ð&Ð&ð
 ŒyÐ$Ð$Ð$Ø�˜tœyÐ:¨4Ð:Ð:Ð:°6Ð:Ð:ˆð	*Ø�KŠK˜ÑÔÐØ�LŠL‰NŒNˆNˆNøÝð 	*ð 	*ð 	*õ ' qÑ)Ô)Ð)øøøøð		*øøøð
 /1ˆÔ+Ð+Ð+s   ½)A' Á'
BÁ1B Â B)NN)r�   rŸ   r    r¡   r1   r   )NNN)
r«   r$   r¬   r­   r®   r­   r¯   r°   r=   r±   )r«   r$   r¼   r½   r=   r>   )r�   r‘   r’   Ú__doc__r™   r“   rš   Ú
HTMLPARSERr›   r   r   rœ   rž   r6   r»   r&   r¿   Ú__classcell__)rª   s   @r:   r   r   q  s  ø€ € € € € € ðð ð €FÐÐÐÑØ€IÐÐÐÑØ€DÐÐÐÑØ# T¨6Ð2€HÐ2Ð2Ð2Ñ2Ø5Ð5Ð5Ñ5ð !%ÐÐ$Ð$Ð$Ñ$ð 04Ø26ð8ð 8ð 8ð 8ð 8ð 8ð 8ðB 8<Ø:>Ø26ðFð Fð Fð Fð FðP Ulð 1ð 1ð 1ð 1ð 1ð 1ð 1ð 1ð 1r;   )1rÄ   Ú
__future__r   Ú__license__Ú__all__Úhtml.parserr   r”   Ú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(   rP   r&   r   r—   r;   r:   ú<module>rÒ      s�  ðà IÐ IØ "Ð "Ð "Ð "Ð "Ð "ð €ð ð€ð #Ð "Ð "Ð "Ð "Ð "Ø 	€	€	€	ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð 9Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8ðð ð ð ð ð ð ð ð ð ð ð ð 0Ð /Ð /Ð /Ð /Ð /àð Ø!Ð!Ð!Ð!Ð!Ð!Ø+Ð+Ð+Ð+Ð+Ð+ðð ð ð ð ð ð ð ð ð ð €
à% t¨C°¨H¤~°s¸CÐ&@À$Ð&FÔGÐ ðp1ð p1ð p1ð p1ð p1˜jÐ*@ñ p1ô p1ð p1ðf	T1ð T1ð T1ð T1ð T1˜Oñ T1ô T1ð T1ð T1ð T1r;   