[L iyHUddlmZdZddlmZddlZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZddlZddlZddlmZmZmZmZmZmZmZmZmZm Z ddl!m"Z"dd l#m$Z$m%Z%dd l&m'Z'erdd l(m)Z)dd lm*Z*m+Z+dd l#m,Z,m-Z-m.Z.m/Z/m0Z0gdZ1dZ2dZ3dZ4dZ5dZ6dZ7gdZ1Gdde8Z9e9Z:de;d<Gdde8Z<Gdde<Z=Gdde<Z>Gdd e8Z?d&d!Z@d"d#lAmBZBe@eB d"d$lAmCZCe@eC d"d%lAmEZEe@eEy#eD$rYwxYw#eD$rYywxYw)') annotationsMIT) defaultdictN) ModuleType) AnycastDictIterableListOptionalPatternSetTupleType TYPE_CHECKING) AttributeDictAttributeValueListCharsetMetaAttributeValueContentMetaAttributeValueRubyParenthesisStringRubyTextString StylesheetScriptTemplateStringnonwhitespace_re)ParserRejectedMarkup)_AttributeValues_RawAttributeValue)XMLParsedAsHTMLWarning) BeautifulSoup)NavigableStringTag)_AttributeValue _Encoding _Encodings_RawOrProcessedAttributeValues _RawMarkup)HTMLTreeBuilderSAXTreeBuilder TreeBuilderTreeBuilderRegistryfast permissivestrictxmlhtmlhtml5)r+r*r(DetectsXMLParsedAsHTMLrc>eZdZUdZded<ded<d dZd dZd dZy ) r+zYA way of looking up TreeBuilder subclasses by their name or by desired features. z"Dict[str, List[Type[TreeBuilder]]]builders_for_featurezList[Type[TreeBuilder]]buildersc:tt|_g|_yN)rlistr4r5selfs Z/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/bs4/builder/__init__.py__init__zTreeBuilderRegistry.__init__^s$/$5! c|jD]!}|j|jd|#|jjd|y)zRegister a treebuilder based on its advertised features. :param treebuilder_class: A subclass of `TreeBuilder`. its `TreeBuilder.features` attribute should list its features. rN)featuresr4insertr5)r:treebuilder_classfeatures r;registerzTreeBuilderRegistry.registerbsL )11 LG  % %g . 5 5a9J K L Q 12r=ct|jdk(ryt|dk(r|jdSt|}|jd}d}t|dkDru|j }|j j |g}t|dkDr,||}t|}n||jt|}t|dkDru||y|D] }||vs|cSy)ajLook up a TreeBuilder subclass with the desired features. :param features: A list of features to look for. If none are provided, the most recently registered TreeBuilder subclass will be used. :return: A TreeBuilder subclass, or None if there's no registered subclass with all the requested features. rN) lenr5r8reversepopr4getset intersection)r:r? feature_list candidates candidate_setrBwe_have_the_feature candidates r;lookupzTreeBuilderRegistry.lookupls  t}}  " x=A ==# #H~   ,!#"&&(G"&";";"?"?"L &'!+%!4J$' OM".$1$>$>sCV?W$XM,!#  J$6# !IM)   !r=NreturnNone)rAztype[TreeBuilder]rRrS)r?strrRzOptional[Type[TreeBuilder]])__name__ __module__ __qualname____doc____annotations__r<rCrPr=r;r+r+Vs$=<%%3+r=r+builder_registryceZdZUdZeZded<eeeeeeef d)d Z d Z d ed<gZ ded<gZ ded<dZ ded<dZded<ded<dZded <ded<ded<d ed<ded<eeZded<eZded<iZded<dZded<dZded <d*d!Zd+d"Zd,d#Zd-d$Z d. d/d%Zd0d&Zd1d'Z d2d(Zy)3r*aTurn a textual document into a Beautiful Soup object tree. This is an abstract superclass which smooths out the behavior of different parser libraries into a single, unified interface. :param multi_valued_attributes: If this is set to None, the TreeBuilder will not turn any values for attributes like 'class' into lists. Setting this to a dictionary will customize this behavior; look at :py:attr:`bs4.builder.HTMLTreeBuilder.DEFAULT_CDATA_LIST_ATTRIBUTES` for an example. Internally, these are called "CDATA list attributes", but that probably doesn't make sense to an end-user, so the argument name is ``multi_valued_attributes``. :param preserve_whitespace_tags: A set of tags to treat the way
 tags are treated in HTML. Tags in this set
     are immune from pretty-printing; their contents will always be
     output as-is.

    :param string_containers: A dictionary mapping tag names to
     the classes that should be instantiated to contain the textual
     contents of those tags. The default is to use NavigableString
     for every tag, no matter what the name. You can override the
     default by changing :py:attr:`DEFAULT_STRING_CONTAINERS`.

    :param store_line_numbers: If the parser keeps track of the line
     numbers and positions of the original markup, that information
     will, by default, be stored in each corresponding
     :py:class:`bs4.element.Tag` object. You can turn this off by
     passing store_line_numbers=False; then Tag.sourcepos and
     Tag.sourceline will always be None. If the parser you're using
     doesn't keep track of this information, then store_line_numbers
     is irrelevant.

    :param attribute_dict_class: The value of a multi-valued attribute
      (such as HTML's 'class') willl be stored in an instance of this
      class.  The default is Beautiful Soup's built-in
      `AttributeValueList`, which is a normal Python list, and you
      will probably never need to change it.
    rUSE_DEFAULTDict[str, Set[str]]preserve_whitespace_tagsSet[str]boolstring_containers Dict[str, Type[NavigableString]]empty_element_tagscd|_||jur|j}||_||jur|j}||_||jur|j|_n||_||jk(r|j}||_	||jk(r|j}||_||_||_
yr7)soupr]DEFAULT_CDATA_LIST_ATTRIBUTEScdata_list_attributes DEFAULT_PRESERVE_WHITESPACE_TAGSr_DEFAULT_EMPTY_ELEMENT_TAGSrdTRACKS_LINE_NUMBERSstore_line_numbersDEFAULT_STRING_CONTAINERSrbattribute_dict_classattribute_value_list_class)r:multi_valued_attributesr_rlrbrdrnros        r;r<zTreeBuilder.__init__s	"d&6&66&*&H&H#%<"#t'7'77'+'L'L$(@%!1!11&*&E&ED#&8D#!1!11!%!9!9"4 0 00 $ > >!2$8!*D'r=z[Unknown tree builder]rTNAMEz
Iterable[str]ALTERNATE_NAMESr?Fis_xml	picklablezOptional[BeautifulSoup]rfNOptional[Set[str]]rhtracks_line_numbersrgri,Dict[str, Type[bs4.element.NavigableString]]rmrjrkc||_y)zThe BeautifulSoup object has been initialized and is now
        being associated with the TreeBuilder.

        :param soup: A BeautifulSoup object.
        N)rf)r:rfs  r;initialize_soupzTreeBuilder.initialize_soups	r=cy)zDo any work necessary to reset the underlying parser
        for a new document.

        By default, this does nothing.
        NrZr9s r;resetzTreeBuilder.resets	
r=c8|jy||jvS)aMight a tag with this name be an empty-element tag?

        The final markup may or may not actually present this tag as
        self-closing.

        For instance: an HTMLBuilder does not consider a 

tag to be an empty-element tag (it's not in HTMLBuilder.empty_element_tags). This means an empty

tag will be presented as "

", not "

" or "

". The default implementation has no opinion about which tags are empty-element tags, so a tag will be presented as an empty-element tag if and only if it has no children. "" will become "", and "bar" will be left alone. :param tag_name: The name of a markup tag. T)rd)r:tag_names r;can_be_empty_elementz TreeBuilder.can_be_empty_element"s$&  " " *42222r=ct)z1Run incoming markup through some parsing process.NotImplementedErrorr:markups r;feedzTreeBuilder.feed9s !##r=c#K|dddfyw)aRun any preliminary steps necessary to make incoming markup acceptable to the parser. :param markup: The markup that's about to be parsed. :param user_specified_encoding: The user asked to try this encoding to convert the markup into a Unicode string. :param document_declared_encoding: The markup itself claims to be in this encoding. NOTE: This argument is not used by the calling code and can probably be removed. :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 that the parser can try to convert the document to Unicode and parse it. Each strategy will be tried in turn. By default, the only strategy is to parse the markup as-is. See `LXMLTreeBuilderForXML` and `HTMLParserTreeBuilder` for implementations that take into account the quirks of particular parsers. :meta private: NFrZ)r:ruser_specified_encodingdocument_declared_encodingexclude_encodingss r;prepare_markupzTreeBuilder.prepare_markup=sDdD%''s c|S)aWrap an HTML fragment to make it look like a document. Different parsers do this differently. For instance, lxml introduces an empty tag, and html5lib doesn't. Abstracting this away lets us write simple tests which run HTML fragments through the parser and compare the results against other HTML fragments. This method should not be used outside of unit tests. :param fragment: A fragment of HTML. :return: A full HTML document. :meta private: rZ)r:fragments r;test_fragment_to_documentz%TreeBuilder.test_fragment_to_documentas r=cy)a,Set up any substitutions that will need to be performed on a `Tag` when it's output as a string. By default, this does nothing. See `HTMLTreeBuilder` for a case where this is used. :return: Whether or not a substitution was performed. :meta private: FrZ)r:tags r;set_up_substitutionsz TreeBuilder.set_up_substitutionsrsr=ctt|}|r |js|S|jjdt }|jj|j d}t |jD]O}||vs|s ||vs||}t|tr%|jtj|}n|}|||<Q|S)a)When an attribute value is associated with a tag that can have multiple values for that attribute, convert the string value to a list of strings. Basically, replaces class="foo bar" with class=["foo", "bar"] NOTE: This method modifies its input in place. :param tag_name: The name of a tag. :param attrs: A dictionary containing the tag's attributes. Any appropriate attribute values will be modified in place. :return: The modified dictionary that was originally passed in. *N) rrrhrHrIlowerr8keys isinstancerrorfindall) r:r}attrsmodified_attrs universal tag_specificattroriginal_valuemodified_values r;$_replace_cdata_list_attribute_valuesz0TreeBuilder._replace_cdata_list_attribute_values~s(.6T%?%?! !#88<I'24A?QE!4E#+E! E < E % E2E%=EB)D#(%'O]' Hm FDIt !!.2*1..&&77:ES9I!#6I25$h6OQKP 6: 29!&% 3.$8<:>26 "("("5"(%8 "( 0 "( U "(H" 66$B6 6r=r*ceZdZdZdfd ZddZddZddZddZ ddZ ddZ dd Z dd Z dd Z dd Zdd ZxZS)r)a/A Beautiful Soup treebuilder that listens for SAX events. This is not currently used for anything, and it will be removed soon. It was a good idea, but it wasn't properly integrated into the rest of Beautiful Soup, so there have been long stretches where it hasn't worked properly. cdtjdtdtt||i|y)NzThe SAXTreeBuilder class was deprecated in 4.13.0 and will be removed soon thereafter. It is completely untested and probably doesn't work; do not use it. stacklevel)warningswarnDeprecationWarningsuperr)r<)r:argskwargs __class__s r;r<zSAXTreeBuilder.__init__s1  i  nd,d=f=r=ctr7rrs r;rzSAXTreeBuilder.feeds !##r=cyr7rZr9s r;closezSAXTreeBuilder.close r=ctdt|jD}|jJ|jj |dd|y)Nc30K|]\}}|d|fyw)NrZ).0keyvalues r; z.SAXTreeBuilder.startElement..sT*#us1vuoTs)rr8itemsrfhandle_starttag)r:namers r; startElementzSAXTreeBuilder.startElementsETU[[]@STTyy$$$ !!$dE:r=cV|jJ|jj|yr7)rf handle_endtagr:rs r; endElementzSAXTreeBuilder.endElements$yy$$$ %r=c(|j||yr7)r)r:nsTuplenodeNamers r;startElementNSzSAXTreeBuilder.startElementNSs (E*r=c&|j|yr7)r)r:rrs r; endElementNSzSAXTreeBuilder.endElementNSs !r=cyr7rZ)r:prefix nodeValues r;startPrefixMappingz!SAXTreeBuilder.startPrefixMappings r=cyr7rZ)r:rs r;endPrefixMappingzSAXTreeBuilder.endPrefixMappings r=cV|jJ|jj|yr7)rf handle_data)r:contents r; characterszSAXTreeBuilder.characterss$yy$$$ g&r=cyr7rZr9s r; startDocumentzSAXTreeBuilder.startDocumentrr=cyr7rZr9s r; endDocumentzSAXTreeBuilder.endDocumentrr=)rrrrrRrSrrQ)rrTrDict[str, str]rRrSrrTrRrS)rTuple[str, str]rrTrrrRrS)rrrrTrRrS)rrTrrTrRrS)rrTrRrS)rrTrRrS)rUrVrWrXr<rrrrrrrrrrr __classcell__)rs@r;r)r)sd>$ ; & +&+25+>L+ + "   '  r=r)c eZdZUdZegdZded<egdZded<ee e e e dZ d ed <hd d d hd d hdhdhdhdhd hdhdhdhd Zded<eddgZded<ddZy)r(zpThis TreeBuilder knows facts about HTML, such as which tags are treated specially by the HTML standard. )areabasebrcolembedhrimginputkeygenlinkmenuitemmetaparamsourcetrackwbrbasefontbgsoundcommandframeimageisindexnextidspacerrurj)#addressarticleaside blockquotecanvasdddivdldtfieldset figcaptionfigurefooterformh1h2h3h4h5h6headerrlimainnavnoscriptoloutputppresectiontabletfootulvideor`DEFAULT_BLOCK_ELEMENTS)rtrpstylescripttemplaterwrm>classdropzone accesskeyrelrevheaderszaccept-charsetarchivesizessandboxfor) rartdthrrriconiframer r^rgrtextareazset[str]ricT|jdk7ryttt|j d}ttt|j d}|j d}d}|t ||d<d}|S|"td|Drt||d<d}|S)aReplace the declared encoding in a tag with a placeholder, to be substituted when the tag is output to a string. An HTML document may come in to Beautiful Soup as one encoding, but exit in a different encoding, and the tag needs to be changed to reflect this. :return: Whether or not a substitution was performed. :meta private: rFrcharsetz http-equivTc3BK|]}|jdk(yw)z content-typeN)r)rxs r;rz7HTMLTreeBuilder.set_up_substitutions..s ) ,-AGGI ') s) rrr rTrHget_attribute_listranyr)r:rrr+ http_equiv substituteds r;rz$HTMLTreeBuilder.set_up_substitutions|s 88v  "&hsmSWWY5G!H!%hsmSWWY5G!H !$ 6 6| D   7w?C NK S) 1;) & 7w?C NKr=Nr)rUrVrWrXrIrjrYrrrrrrrmrgrirrZr=r;r(r(s 69 6 2F(+$ &(H&r#" OK 0U^kk!"+ +' :!#6 "25eZ5H1I$hI4r=r(ceZdZUdZej dej Zded<ej dej Z ded<dZ d ed <d Z d ed <ded<ded<e d ddZ e dddZddZddZddZy)r2aA mixin class for any class (a TreeBuilder, or some class used by a TreeBuilder) that's in a position to detect whether an XML document is being incorrectly parsed as HTML, and issue an appropriate warning. This requires being able to observe an incoming processing instruction that might be an XML declaration, and also able to observe tags as they're opened. If you can't do that for a given `TreeBuilder`, there's a less reliable implementation based on examining the raw markup. z <[^ +]htmlz Pattern[str]LOOKS_LIKE_HTMLs <[^ +]htmlzPattern[bytes]LOOKS_LIKE_HTML_Bz fe $$H%00  ;++226:: #H%009))0088   IIaI 0r=cXtjtjt|y)z/Issue a warning about XML being parsed as HTML.rN)rrrMESSAGE)r>rs r;r=zDetectsXMLParsedAsHTML._warns  " * * "! r=c d|_d|_y)z+Call this method before parsing a document.Nr8r9r9s r;_initialize_xml_detectorz/DetectsXMLParsedAsHTML._initialize_xml_detectors-1*"r=cD|j |jy||_y)a.Call this method when encountering an XML declaration, or a "processing instruction" that might be an XML declaration. This helps Beautiful Soup detect potential issues later, if the XML document turns out to be a non-XHTML document that's being parsed as XML. NrF)r:processing_instructions r;_document_might_be_xmlz-DetectsXMLParsedAsHTML._document_might_be_xmls)  . . :"". -C*r=c|jy||_|dk7rJ|j=|jjjdr|j dyyyy)zCall this when you encounter the document's root tag. This is where we actually check whether an XML document is being incorrectly parsed as HTML, and issue the warning. Nr0zxml r)r9r8rr;r=rs r;_root_tag_encounteredz,DetectsXMLParsedAsHTML._root_tag_encounteredso    * " FN22>2288:EEfM JJ"J % N? r=N))rzOptional[_RawMarkup]rintrRra))rrOrRrSrQ)rIrTrRrSr)rUrVrWrXrecompileIr3rYr4r5r7 classmethodrBr=rGrJrMrZr=r;r2r2s %/BJJ|RTT$BO\B)3 ="$$(G~GJ#L%"$10!!=> ) 7:    D  # D*&r=r2ctjt}|jD]b}t ||}t |t s t||||jj||jj|dy)z9Copy TreeBuilders from the given module into this module.N) sysmodulesrU__all__getattr issubclassr*setattrappendr[rC)module this_modulerobjs r;register_treebuilders_fromr`/sm++h'K7fd# c; ' Ks +    & &t ,  ( ( 1 1# 67r=r) _htmlparser) _html5lib)_lxml)r]rrRrS)F __future__r __license__ collectionsrrQtypesrtypingrrr r r r r rrrrrrV bs4.elementrrrrrrrrrrbs4.exceptionsr bs4._typingrr bs4._warningsrbs4r r!r"r#r$r%r&r'rXFAST PERMISSIVESTRICTXMLHTMLHTML_5rr+r[rYr*r)r(r2r`rarb ImportErrorrcrZr=r;rvsH" #         0 1!       A&AL)<(=%=U&Up> [> Bxkxvy&Vy&x 7";' y) u%     s$0D?DDDD! D!