h%!dZddlmZejZddlmZ ddlm Z n#e $rdZ YnwxYw e n #e $reZ YnwxYw en #e $reZYnwxYwGddZeZdS)z9 The ``E`` Element factory for generating XML documents. Npartial) GenericAliasc&|jd|jdS)N[])__name__clsitems \/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/lxml/builder.py _GenericAliasr4s,111111c0eZdZdZ ddZdZdZdZdS) ElementMakerac Element generator factory. Unlike the ordinary Element factory, the E factory allows you to pass in more than just a tag and some optional attributes; you can also pass in text and other elements. The text is added as either text or tail attributes, and elements are inserted at the right spot. Some small examples:: >>> from lxml import etree as ET >>> from lxml.builder import E >>> ET.tostring(E("tag")) '' >>> ET.tostring(E("tag", "text")) 'text' >>> ET.tostring(E("tag", "text", key="value")) 'text' >>> ET.tostring(E("tag", E("subtag", "text"), "tail")) 'texttail' For simple tags, the factory also allows you to write ``E.tag(...)`` instead of ``E('tag', ...)``:: >>> ET.tostring(E.tag()) '' >>> ET.tostring(E.tag("text")) 'text' >>> ET.tostring(E.tag(E.subtag("text"), "tail")) 'texttail' Here's a somewhat larger example; this shows how to generate HTML documents, using a mix of prepared factory functions for inline elements, nested ``E.tag`` calls, and embedded XHTML fragments:: # some common inline elements A = E.a I = E.i B = E.b def CLASS(v): # helper function, 'class' is a reserved word return {'class': v} page = ( E.html( E.head( E.title("This is a sample document") ), E.body( E.h1("Hello!", CLASS("title")), E.p("This is a paragraph with ", B("bold"), " text in it!"), E.p("This is another paragraph, with a ", A("link", href="http://www.python.org"), "."), E.p("Here are some reserved characters: ."), ET.XML("

And finally, here is an embedded XHTML fragment.

"), ) ) ) print ET.tostring(page) Here's a prettyprinted version of the output from the above script:: This is a sample document

Hello!

This is a paragraph with bold text in it!

This is another paragraph, with link.

Here are some reserved characters: <spam&egg>.

And finally, here is an embedded XHTML fragment.

For namespace support, you can pass a namespace map (``nsmap``) and/or a specific target ``namespace`` to the ElementMaker class:: >>> E = ElementMaker(namespace="http://my.ns/") >>> print(ET.tostring( E.test )) >>> E = ElementMaker(namespace="http://my.ns/", nsmap={'p':'http://my.ns/'}) >>> print(ET.tostring( E.test )) Nc|d|zdznd|_|rt|nd|_|t|sJ||n tj|_rtnid}d}tvr |t<tvr |t<tj vr|tj <fd}tvr |t<|_ dS)N{}c~ |d}|jpd|z|_dS#t$r|jpd|z|_YdSwxYw)N)tail IndexErrortext)elemr last_childs r add_textz'ElementMaker.__init__..add_texts_ A!"X $.?#8bD"@  5 5 5!Y_"4  5s <<cP|jrtd|jz||_dS)Nz.add_cdatas0y m !_bfbk!klllDIIIrc|j}|D]B\}}t|tr|||< t |d|||<CdSN)attribitems isinstance basestringtype)rr r$kvtypemaps r add_dictz'ElementMaker.__init__..add_dictsn[F  : :1a,,: !F1II 0Q 0q 9 9F1II  : :r) _namespacedict_nsmapcallableETElement _makeelementstrunicodeCDATA_typemap)selfr+ namespacensmap makeelementrr!r,s ` r __init__zElementMaker.__init__s3<3H# /C//d%*4d5kkk "h{&;&;"""+6+BKK $+2$w--- A A A    g  #GCL ' ! !'GG  87 " " )GBH  : : : : : w  $GDM rc|j}t|tst|tr|j}n|j|ddkr |j|z}|||j}|r|t|||D]}t|r |}| t|}|tj |r||it|jD]}| |}|n)t!dt|jd|d|||} | r,| t| || |S)Nrr)r:zbad argument type: ())r7r&r4_QNamerr-r3r/r.r0getr(r1 iselementappend__mro__ TypeErrorr ) r8tagchildrenr$r+rr tbasetyper*s r __call__zElementMaker.__call__s-#s## ( 3(?(? ((CC _ (SVs]]/C'C  DK 88  ( GDM$ ' ' ' . .D~~ tvv DJJ''Ay<%%KK%%% $T 2AAH H--A}%$)%)$ZZ%8%8%8$$$%@AAA$ A .$ DGG$$T1--- rc"t||Sr#r)r8rFs r __getattr__zElementMaker.__getattr__stS!!!rc"t||Sr#)rr s r __class_getitem__zElementMaker.__class_getitem__sS$'''r)NNNN)r __module__ __qualname____doc__r<rJrLrNrr rrBslVVp $9=* * * * X!!!F"""(((((rr)rQ lxml.etreeetreer1QNamer@ functoolsrtypesrr ImportErrorr' NameErrorr4r5rErRrr r[s-L  23333333222222222 JJJJJ GGGGGm(m(m(m(m(m(m(m(bLNNs)))0::AA  A