/usr/lib/python3/dist-packages/lxml/__pycache__
NameSizeModeActions
builder.cpython-310.pyc59080644editdlrm
cssselect.cpython-310.pyc36080644editdlrm
doctestcompare.cpython-310.pyc139370644editdlrm
ElementInclude.cpython-310.pyc37760644editdlrm
pyclasslookup.cpython-310.pyc2040644editdlrm
sax.cpython-310.pyc81700644editdlrm
usedoctest.cpython-310.pyc3940644editdlrm
_elementpath.cpython-310.pyc63300644editdlrm
__init__.cpython-310.pyc6650644editdlrm
Edit: /usr/lib/python3/dist-packages/lxml/__pycache__/builder.cpython-310.pyc (5908B)
o ;/b@sdZddlmZddlmZejZddlm Z ze Wn e y&e Z Ynwze Wn e y6e Z YnwGdddeZeZdS)z9 The ``E`` Element factory for generating XML documents. )absolute_importNpartialc@s.eZdZdZ  d ddZddZddZdS) 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 )) Ncs|dur d|dnd|_|rt|nd|_|dus t|s J|dur&|ntj|_r0tnidd}dd}tvrB|t<tvrJ|t<tj vrT|tj <fdd}tvrb|t<|_ dS) N{}cSsFz|d}Wnty|jpd||_YdSw|jpd||_dS)N) IndexErrortexttail)elemitem last_childr./usr/lib/python3/dist-packages/lxml/builder.pyadd_texts   z'ElementMaker.__init__..add_textcSs|jr td|j||_dS)Nz.add_cdatacsF|j}|D]\}}t|tr|||<qt|d|||<qdSN)attribitems isinstance basestringtype)r rrkvtypemaprradd_dicts   z'ElementMaker.__init__..add_dict) _namespacedict_nsmapcallableETElement _makeelementstrunicodeCDATA_typemap)selfr namespacensmap makeelementrrr rrr__init__s"    zElementMaker.__init__c Os |j}t|tst|tr|j}n|jdur!|ddkr!|j|}|j||jd}|r2|t|||D]N}t |r=|}| t |}|durqt |rS||q4t |jD] }| |}|duren qXtdt |j|f|||} | r| t | || q4|S)Nrr)r.zbad argument type: %s(%r))r+rr(_QNamer r!r'r#r"r$getrr% iselementappend__mro__ TypeError__name__) r,tagchildrenrrr rtbasetyperrrr__call__s:      zElementMaker.__call__cCs t||Srr)r,r8rrr __getattr__s zElementMaker.__getattr__)NNNN)r7 __module__ __qualname____doc__r0r<r=rrrrr<sX , #r)r@ __future__r lxml.etreeetreer%QNamer1 functoolsrr NameErrorr(r)objectrErrrrs$%      .