[L i7\dZdgZddlmZmZmZmZmZmZm Z m Z m Z ddl m Z ddlmZmZmZmZmZmZddlZddlmZmZmZmZmZddlmZmZmZddl Z dd l!m"Z"dd lm#Z#m$Z$m%Z%m&Z&e rdd l'm(Z(dd l)m*Z+Gd deZ,Gdde+jZZ.Gdde/Z0Gdde+jbZ2Gdde2Z3Gdde2Z4y)MITHTML5TreeBuilder) AnycastDictIterableOptionalSequence TYPE_CHECKINGTupleUnion) TypeAlias)_AttributeValue_AttributeValues _Encoding _Encodings _NamespaceURL _RawMarkupN)DetectsXMLParsedAsHTML PERMISSIVEHTMLHTML_5HTMLTreeBuilder)NamespacedAttribute PageElementnonwhitespace_re) namespaces)CommentDoctypeNavigableStringTag BeautifulSoup)baseceZdZUdZdZeed<eeee gZ e eed<dZ e ed<ded<eeed < dd ed eed eed eede eeeeeee ff dZd edd fdZde ddfdZdedefdZy )rajUse `html5lib `_ to build a tree. Note that `HTML5TreeBuilder` does not support some common HTML `TreeBuilder` features. Some of these features could theoretically be implemented, but at the very least it's quite difficult, because html5lib moves the parse tree around as it's being built. Specifically: * This `TreeBuilder` doesn't use different subclasses of `NavigableString` (e.g. `Script`) based on the name of the tag in which the string was found. * You can't use a `SoupStrainer` to parse only part of a document. html5libNAMEfeaturesTTRACKS_LINE_NUMBERSTreeBuilderForHtml5libunderlying_builderuser_specified_encodingNmarkupdocument_declared_encodingexclude_encodingsreturnc#K||_|df|dffD]&\}}|s tjd|d|dd(tj|d|dddfyw) Nr.r/zYou provided a value for z0, but the html5lib tree builder doesn't support . stacklevelF)r,warningswarnrwarn_if_markup_looks_like_xml)selfr-r,r.r/variablenames [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/bs4/builder/_html5lib.pyprepare_markupzHTML5TreeBuilder.prepare_markupWs(?$ ()E F  3 4  NHd /v5efjekklm    <%s)r9rVs r<test_fragment_to_documentz*HTML5TreeBuilder.test_fragment_to_documents :XEErR)NNN)__name__ __module__ __qualname____doc__r'rI__annotations__rrrr(rr)boolr rrrr r=rQrErYrXrRr<rr;s D##Z>Hhsm>!%$00%i00 8<:>26 **"*)!4*%-Y$7 * $J/ * % HY$7)9LdRS T *<#.:#.$#.J '%) ' ! 'F#F#FrRc eZdZUded<eej ed< ddededdedeffd Z dd Z d e e efd dfd Z de de d d fdZde d dfdZddZddZddZddZddZxZS)r*r#rBrFNrSrUkwargsc |r||_n2tjdtdddlm}| dd|i||_t t|#|d|_ ||_ y)NaKThe optionality of the 'soup' argument to the TreeBuilderForHtml5lib constructor is deprecated as of Beautiful Soup 4.13.0: 'soup' is now required. If you can't pass in a BeautifulSoup object here, or you get this warning and it seems mysterious to you, please contact the Beautiful Soup developer team for possible un-deprecation.r4rr"rU)z html.parser) rBr6r7DeprecationWarningbs4r#superr*__init__rFrU)r9rSrBrUrar# __class__s r<rhzTreeBuilderForHtml5lib.__init__sq DI MM^"  * &!6HLRDI $d45JK "4rRr0Elementcx|jjt|j|jdSN)rBresetrjr9s r< documentClassz$TreeBuilderForHtml5lib.documentClasss' tyy$))T22rRtokenctt|d}ttt|d}ttt|d}tj|||}|j j |y)Nr;publicIdsystemId)rrIr rfor_name_and_idsrBobject_was_parsed)r9rpr;rrrsdoctypes r< insertDoctypez$TreeBuilderForHtml5lib.insertDoctypesbeFm,"&x}eJ6G"H"&x}eJ6G"H**48D ##G,rRr; namespacecd}d}|jF|jr:|jjjj \}}|J|dz }|j j ||||}t||j |S)N) sourceline sourcepos)rFrUrLrMpositionrBnew_tagrj)r9r;rxr{r|tags r< elementClassz#TreeBuilderForHtml5lib.elementClasss$( #' ;; "t'>'>%)KK$9$9$@$@$I$I$K !J ( ((!A Iii ) i  sDIIy11rRdataTextNodec@tt||jSrl)rrrB)r9rs r< commentClassz#TreeBuilderForHtml5lib.commentClasss tyy11rRct)zThis is only used by html5lib HTMLParser.parseFragment(), which is never used by Beautiful Soup, only by the html5lib unit tests. Since we don't currently hook into those tests, the implementation is left blank. NotImplementedErrorrns r< fragmentClassz$TreeBuilderForHtml5lib.fragmentClasss "##rRctzThis is only used by the html5lib unit tests. Since we don't currently hook into those tests, the implementation is left blank. rrns r< getFragmentz"TreeBuilderForHtml5lib.getFragment "##rRcN|jj|jyrl)rBappendelementr9nodes r< appendChildz"TreeBuilderForHtml5lib.appendChilds &rRc|jSrl)rBrns r< getDocumentz"TreeBuilderForHtml5lib.getDocument s yyrRctrrrs r<testSerializerz%TreeBuilderForHtml5lib.testSerializer rrR)NT)r0rjrrjr0N)r0r#)rZr[r\r^r r&rDr_rrhrorrIrwrrrrrrr __classcell__)ris@r<r*r*s  X(( )) +/#' 5#5'5! 5  5B3-4S>-d-2222 222$$'$rRr*ceZdZUdZeed<eed<defdZdee e e ffdZ de de dd fd Z dee e e ffd Zdee fd Zdefd Zde de fdZde defdZy )AttrListz@Represents a Tag's attributes in a way compatible with html5lib.rattrscZ||_t|jj|_yrl)rrGr)r9rs r<rhzAttrList.__init__s $,,,,- rRr0cdt|jjjSrl)listritems__iter__rns r<rzAttrList.__iter__s#DJJ$$&'0022rRr;valueNc|jjxsi}||jdgvs@|jj|vrx||j|jjgvrPt |t s@t |t sJ|jjtj|}||j|<y)N*) rcdata_list_attributesgetr;rHrrIattribute_value_list_classrfindall)r9r;r list_attrs r< __setitem__zAttrList.__setitem__"sLL66<" 9==b) ) LL   * dll&7&7<<eT*!%--- ??$,,U3# TrRcHt|jjSrl)rrrrns r<rzAttrList.items3sDJJ$$&''rRcHt|jjSrlrrkeysrns r<rz AttrList.keys6sDJJOO%&&rRc,t|jSrl)lenrrns r<__len__zAttrList.__len__9s4::rRc |j|Srl)rr9r;s r< __getitem__zAttrList.__getitem__<szz$rRcL|t|jjvSrlrrs r< __contains__zAttrList.__contains__?stDJJOO-...rR)rZr[r\r]r!r^rrhrr rIrrrrrintrrr_rrXrRr<rrsJ L ..3(5o)=#>?3##O##"(xc?&: ;<('hsm'   ///rRrceZdZUeeed<eeed<ded<eeed<ede fdZ ede fdZ de jfd Zy ) BeautifulSoupNoderstringr#rBrxr0c|j|jJ|j |jS|jJ|jSrl)rrrns r<rzBeautifulSoupNode.elementJsHxx#t{{'>>> 88 88O;;* **;; rRct)zReturn the html5lib constant corresponding to the type of the underlying DOM object. NOTE: This property is only accessed by the html5lib test suite, not by Beautiful Soup proper. rrns r<nodeTypezBeautifulSoupNode.nodeTypeSs "##rRctrlrrns r< cloneNodezBeautifulSoupNode.cloneNode_s !##rRN)rZr[r\r r!r^r rpropertyrrrrtreebuilder_baseNoderrXrRr<rrCso # _ %%  && $#$$$+00$rRrcHeZdZUeeed<dedddeefdZdd Zde fd Z e e e e e ffZeed <eee fZeed <d eeddfdZee eZ dde dedddfdZ ddZddZddZdefdZdej8fdZde eee ffdZeeZy)rjrxrrBr#c||_d|_||_||_tj j ||jyrl)rrrBrxrrrhr;)r9rrBrxs r<rhzElement.__init__fs:  "&&tW\\:rRrr0Ncd}t|jtur|jx}}n |j}||_|6|j*t |t s|jj||j|jjrt|jjdturZ|jjd}|jj||z}|j|||j_ yt |t r|jj|}|j2|jjr|jjd}n=|jj|jj}n |j}|jj!||j|y)NF)parentmost_recent_element)typerr rrrHrIextractrcontentsrB new_string replace_with_most_recent_element_last_descendant next_elementru)r9r string_childchild old_element new_elementrs r<rzElement.appendChildos26   /$(;; .L5LLE    (uc* LL "  $$):):TXX&&r*+> ((++B/K))..{\/IJK  $ $[ 1-8DII *$$ ,,T2 xx#(9(9&*hh&?&?&F#**6 '+ii&@&@&B#&*ll# II ' 'dhh    dL 1   T "rRcN|jJ|jj|j}t|jtur|jj rt|jj |dz turi|jj |dz }t|tusJ|j j||jz}|j|y|jj||j||_ y)Nrz) rindexrrr rrBrrinsertr)r9rrefNoderold_nodenew_strs r<rzElement.insertBeforesxx###w/  / 1!!TXX&&uqy12oExx((3H>_4 44ii**8dll+BCG  ! !' * HHOOE4<< 0DKrRc8|jjyrl)rrrs r< removeChildzElement.removeChilds rRc~|j}|J|j}|J|j}|jdd}t|jdkDr |J|jd}|j }nd}|j }|j}t|dkDrh|d} ||| _n|| _|| _|| |_n| |_|| |_|djdd} | J|| _|| |_d| _|D]$} || _|jj| &g|_||_y)z1Move all of this tag's children into another tag.NFrrT)is_initialized accept_self) r next_siblingrrrrprevious_elementprevious_siblingrr) r9 newParentrnew_parent_elementfinal_next_elementnew_parents_last_descendantnew_parents_last_child(new_parents_last_descendant_next_element to_append first_childlast_childs_last_descendantrs r<reparentChildrenzElement.reparentChildrens (("""&]]!---%11&8&I&I%QV&W# !** +a / /: ::%7%@%@%D "+88 5 &* "7I7V7V 4$$ y>A $A,K*6/J ,/A ,+AK (*6;F+82="/%16A&3 +4B-*H*H$$+I+ ' /: ::8 ( 48C 09I8< ' 4 6E-EL  ' ' . .u 5 6 1rRcf|jduxs"t|jjdkDSr)rrrrns r< hasContentzElement.hasContentGs*xx4=3txx'8'8#9A#==rRc|jJ|jj|jj|j}t ||j|j}|j D]\}}||j |<|Srl)rrBr~r;rxrjr)r9rrkeyrs r<rzElement.cloneNodeLstxx###ii t~~>sDIIt~~6// )JC#(DOOC  ) rRct|jtd|jfS|j|jfS)Nhtml)rxrr;rns r< getNameTuplezElement.getNameTupleTs3 >> !f%tyy0 0>>499, ,rR)rrr0Nrl)rrrrr0Nr)rrjr0N) rZr[r\r rr^r!rhrrrr rIr rrrrrrrrrrrr_rrrrr nameTuplerXrRr<rjrjcs9 &&;;"1;>F}>U;3j"x" ).c5c?.B(CIC&**@#*E%FF=1D(E=$=B-7JHL##'/0C'D# #'2E &N2l>D> +00-eH]$;S$@A- &IrRrjceZdZdeddfdZy)rrrBr#cntjj|dd|_||_||_yrl)rrrhrrrB)r9rrBs r<rhzTextNode.__init___s-&&tT2  rRN)rZr[r\r rhrXrRr<rr]srRr)5 __license____all__typingrrrrr r r r r typing_extensionsr bs4._typingrrrrrrr6 bs4.builderrrrrr bs4.elementrrrr&html5lib.constantsrrrr r!rfr#html5lib.treebuildersr$rr TreeBuilderr*objectrrrrjrrXrRr<rs     ( !:pFpFfd$-99d$N+/v+/\$(--$@w'w't rR