9,j7\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+j-Z.Gdde/Z0Gdde+j1Z2Gdde2Z3Gdde2Z4dS)MITHTML5TreeBuilder) AnycastDictIterableOptionalSequence TYPE_CHECKINGTupleUnion) TypeAlias)_AttributeValue_AttributeValues _Encoding _Encodings _NamespaceURL _RawMarkupN)DetectsXMLParsedAsHTML PERMISSIVEHTMLHTML_5HTMLTreeBuilder)NamespacedAttribute PageElementnonwhitespace_re) namespaces)CommentDoctypeNavigableStringTag BeautifulSoup)basec"eZdZUdZdZeed<eeee gZ e eed<dZ e ed<ded<eeed < dd ed eed eed eede eeeeeee ff dZd edd fdZde ddfdZdedefdZd S)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]$\}}|rtjd|d|dd%tj|d|dddfVdS) 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 EC:\PYTHON\GemmaClient\venv\Lib\site-packages\bs4/builder/_html5lib.pyprepare_markupzHTML5TreeBuilder.prepare_markupWs(?$ ()E F  3 4   NHd  mmmfjmmm  namespaceHTMLElementscRt||j|j|_|jS)zCalled by html5lib to instantiate the kind of class it calls a 'TreeBuilder'. :param namespaceHTMLElements: Whether or not to namespace HTML elements. :meta private: )store_line_numbers)r*rCrUr+)r9rSs r<rFz#HTML5TreeBuilder.create_treebuilders2#9 !49AX# # # &&r>fragmentc d|zS)zSee `TreeBuilder`.z)%s)r9rVs r<test_fragment_to_documentz*HTML5TreeBuilder.test_fragment_to_documents :XEEr>)NNN)__name__ __module__ __qualname____doc__r'rJ__annotations__rrrr(rr)boolr rrrr r=rRrFrYrXr>r<rr;sp D##Z>Hhsm>>>!%$$$0000%i0000 8<:>26 ***"*)!4*%-Y$7 * $J/ * % HY$7)9LdRS T ****<#.:#.$#.#.#.#.J '%) ' ! ' ' ' 'F#F#FFFFFFr>c eZdZUded<eejed< ddededdedeffd Z dd Z d e e efd dfdZ de de d d fdZde d dfdZddZddZddZddZddZxZS)r*r#rCrGNTrSrUkwargsc |r||_n2tjdtdddlm}| d d|i||_t t||d|_ ||_ dS) 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" html.parserrU)rdre) rCr6r7DeprecationWarningbs4r#superr*__init__rGrU)r9rSrCrUrar# __class__s r<rizTreeBuilderForHtml5lib.__init__s  DII M^"     * ) ) ) ) ) & !6HLRDI $d++445JKKK "4r>r0Elementcj|jt|j|jdSN)rCresetrkr9s r< documentClassz$TreeBuilderForHtml5lib.documentClasss* ty$)T222r>tokenc4tt|d}ttt|d}ttt|d}tj|||}|j|dS)Nr;publicIdsystemId)rrJr rfor_name_and_idsrCobject_was_parsed)r9rqr;rsrtdoctypes r< insertDoctypez$TreeBuilderForHtml5lib.insertDoctypesueFm,,"&x}eJ6G"H"H"&x}eJ6G"H"H*48DD ##G,,,,,r>r; namespacecd}d}|j6|jr/|jjj\}}|J|dz }|j||||}t||j|S)N) sourceline sourcepos)rGrUrMrNpositionrCnew_tagrk)r9r;ryr|r}tags r< elementClassz#TreeBuilderForHtml5lib.elementClasss$( #' ; "t'> "%)K$9$@$I$I$K$K !J (((!A Ii ) i   sDIy111r>dataTextNodecFtt||jSrm)rrrC)r9rs r< commentClassz#TreeBuilderForHtml5lib.commentClasss ty111r>ct)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. NotImplementedErrorros r< fragmentClassz$TreeBuilderForHtml5lib.fragmentClasss "###r>ctzThis is only used by the html5lib unit tests. Since we don't currently hook into those tests, the implementation is left blank. rros r< getFragmentz"TreeBuilderForHtml5lib.getFragment "###r>nodecD|j|jdSrm)rCappendelementr9rs r< appendChildz"TreeBuilderForHtml5lib.appendChilds" &&&&&r>c|jSrm)rCros r< getDocumentz"TreeBuilderForHtml5lib.getDocument s yr>ctrrrs r<testSerializerz%TreeBuilderForHtml5lib.testSerializer rr>)NT)r0rkrrkr0N)r0r#)rZr[r\r^r r&rEr_rrirprrJrxrrrrrrr __classcell__)rjs@r<r*r*s  X( )))) +/#' 55#5'5! 5  555555B3333-4S>-d----2222222 222222$$$$$$$$''''$$$$$$$$r>r*ceZdZUdZeed<eed<defdZdee e e ffdZ de de dd fd Z dee e e ffd Zdee fd Zdefd Zde de fdZde defdZd S)AttrListz@Represents a Tag's attributes in a way compatible with html5lib.rattrscP||_t|jj|_dSrm)rrHr)r9rs r<rizAttrList.__init__s! $,,-- r>r0crt|jSrm)listritems__iter__ros r<rzAttrList.__iter__s*DJ$$&&''00222r>r;valueNcv|jjpi}||dgvs0|jj|vrz|||jjgvrXt |t sCt |t sJ|jtj |}||j|<dS)N*) rcdata_list_attributesgetr;rIrrJattribute_value_list_classrfindall)r9r;r list_attrs r< __setitem__zAttrList.__setitem__"sL6<" 9==b)) ) ) L  * * dl&7<<<<eT** !%----- ??$,U33# Tr>cNt|jSrm)rrrros r<rzAttrList.items3sDJ$$&&'''r>cNt|jSrmrrkeysros r<rz AttrList.keys6sDJOO%%&&&r>c*t|jSrm)lenrros r<__len__zAttrList.__len__9s4:r>c|j|Srm)rr9r;s r< __getitem__zAttrList.__getitem__<sz$r>cR|t|jvSrmrrs r< __contains__zAttrList.__contains__?s!tDJOO--....r>)rZr[r\r]r!r^rrirr rJrrrrrintrrr_rrXr>r<rrsGJJ LLL .....3(5o)=#>?3333##O#####"(xc?&: ;<(((('hsm''''      ////////r>rceZdZUeeed<eeed<ded<eeed<ede fdZ ede fdZ de jfd Zd S) BeautifulSoupNoderstringr#rCryr0c^|j |jJ|j|jS|jJ|jSrm)rrros r<rzBeautifulSoupNode.elementJs<x#t{'>'>> 8 8O;***; r>ct)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. rros r<nodeTypezBeautifulSoupNode.nodeTypeSs"###r>ctrmrros r< cloneNodezBeautifulSoupNode.cloneNode_s!###r>N)rZr[r\r r!r^r rpropertyrrrrtreebuilder_baseNoderrXr>r<rrCs # _ %%%%  &&&& X$#$$$X$$+0$$$$$$r>rceZdZUeeed<dedddeefdZdd Zde fd Z e e e e e ffZeed <eee fZeed <deedd fdZee eZ dde deddd fdZ ddZddZddZdefdZdejfdZde eee ffdZeeZd S) rkryrrCr#c||_d|_||_||_tj||jdSrm)rrrCryrrrir;)r9rrCrys r<rizElement.__init__fsA  "&&tW\:::::r>rrr0NcPd}t|jtur |jx}}n|j}||_|5|j.t |t s|j||j|jj rxt|jj dturR|jj d}|j ||z}| |||j _ dSt |t r|j |}|j'|jj r|jd}n-|jj|j }n|j}|j ||j|dS)NF)parentmost_recent_element)typerr rrrIrJextractrcontentsrC new_string replace_with_most_recent_element_last_descendant next_elementrv)r9r string_childchild old_element new_elementrs r<rzElement.appendChildos26    / /$(; .L55LE    (uc**) L " " "  $$):$TX&r*++>> (+B/K)..{\/IJJK  $ $[ 1 1 1-8DI * * *$$$ 3 ,,T22 x#(9#&*h&?&?&F&F##*6 '+i&@&@&B&B##&*l# I ' 'dhc<|jJt|jSrm)rrros r< getAttributeszElement.getAttributess x###!!!r>_Html5libAttributeName_Html5libAttributes attributesc|jJ|t|dkrt|D]+\}}t |t rt |}||=|||<,tt|}|j j |j |t|D]\}}||j|<|j j |jdSdSdSNr)rrrrrItuplerrrrCbuilder$_replace_cdata_list_attribute_valuesr;set_up_substitutions)r9rr;rnew_namenormalized_attributesvalue_or_valuess r< setAttributeszElement.setAttributess!x###  !c*oo&9&9 $J$4$4$6$677 1 1 edE**12D9H"4(+0Jx(%))9:$F$F ! I  B B 0    *..C.I.I.K.K)L)L 1 1%o!0 I  2 248 < < < < <; " !&9&9r>r insertBeforect|j||j}|r|||dS||dSrm)rrCrrr)r9rrtexts r< insertTextzElement.insertTextsc ,,T22DI>>  #   dL 1 1 1 1 1   T " " " " "r>refNodec|jJ|j|j}t|jtur|jjrt|jj|dz turf|jj|dz }t|tusJ|j||jz}||dS|j ||j||_ dS)Nr{) rindexrrr rrCrrinsertr)r9rrrold_nodenew_strs r<rzElement.insertBeforesx###w//   / 1 1! 2TX&uqy122oEEx(3H>>_4444i**8dl+BCCG  ! !' * * * * * HOOE4< 0 0 0DKKKr>c8|jdSrm)rrrs r< removeChildzElement.removeChilds r> newParentc`|j}|J|j}|J|j}|dd}t|jdkr|J|jd}|j}n d}|j}|j}t|dkrr|d} ||| _n|| _|| _|| |_n| |_|| |_|ddd} | J|| _|| |_d| _|D]#} || _|j | $g|_||_dS)z1Move all of this tag's children into another tag.NFrrT)is_initialized accept_self) r next_siblingrrrrprevious_elementprevious_siblingrr) r9rrnew_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 ("""&]!---%1&8&I&I%QV&W&W# !* + +a / / /:::%7%@%D "+8 5 4 &* "7I7V 4$ y>>A  $A,K*6/J ,,/A ,+AK (*6;F+882="/%16A&3 +4B-*H*H$$+I++ ' /:::8 ( 48C 09I8< ' 4 6 6E-EL  ' . .u 5 5 5 51r>cN|jdupt|jjdkSr)rrrros r< hasContentzElement.hasContentGs&x4=3tx'8#9#9A#==r>c|jJ|j|jj|j}t ||j|j}|jD]\}}||j|<|Srm)rrCrr;ryrkr)r9rrkeyrs r<rzElement.cloneNodeLskx###i t~>>sDIt~66/ ) )JC#(DOC  r>cT|jtd|jfS|j|jfS)Nhtml)ryrr;ros r< getNameTuplezElement.getNameTupleTs+ > !f%ty0 0>49, ,r>)rrr0Nrm)rrrrr0Nr)rrkr0N) rZr[r\r rr^r!rirrrr rJr rrrrrrrrrrrr_rrrrr nameTuplerXr>r<rkrkcs  &&&&;;"1;>F}>U;;;;3333j"x"""" ).c5c?.B(CICCC&**@#*E%FFFF=1D(E=$====B-77JHL###'/0C'D# ####'2E &N2N2N2N2l>D>>>> +0-eH]$;S$@A---- &&IIIr>rkceZdZdeddfdZdS)rrrCr#cptj|dd|_||_||_dSrm)rrrirrrC)r9rrCs r<rizTextNode.__init___s4&&tT222  r>N)rZr[r\r rirXr>r<rr]s6r>r)5 __license____all__typingrrrrr r r r r typing_extensionsr bs4._typingrrrrrrr6 bs4.builderrrrrr bs4.elementrrrr&html5lib.constantsrrrr r!rgr#html5lib.treebuildersr$rr TreeBuilderr*objectrrrrkrrXr>r<rs3                        (''''' "!!!!!!::::::pFpFpFpFpFpFpFpFfd$d$d$d$d$-9d$d$d$N+/+/+/+/+/v+/+/+/\$$$$$(-$$$@w'w'w'w'w'w'w'w't r>