Tryag File Manager
Home
-
Turbo Force
Current Path :
/
usr
/
lib
/
python2.4
/
site-packages
/
lxml
/
Upload File :
New :
File
Dir
//usr/lib/python2.4/site-packages/lxml/builder.pyo
mò ÔZ´Gc @ sb d Z d k Z y d k l Z Wn e j o d „ Z n Xd e f d „ ƒ YZ e ƒ Z d S( s9 The ``E`` Element factory for generating XML documents. N( s partialc s ‡ ‡ d † S( Nc s ˆ ˆ | | Ž S( N( t funct tagt argst kwargs( R R ( R R ( t0 /usr/lib/python2.4/site-packages/lxml/builder.pyt <lambda>/ s ( ( R R ( ( R R R t partial. s t ElementMakerc B s5 t Z d Z e e e e d „ Z d „ Z d „ Z RS( sª 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")) '<tag/>' >>> ET.tostring(E("tag", "text")) '<tag>text</tag>' >>> ET.tostring(E("tag", "text", key="value")) '<tag key="value">text</tag>' >>> ET.tostring(E("tag", E("subtag", "text"), "tail")) '<tag><subtag>text</subtag>tail</tag>' For simple tags, the factory also allows you to write ``E.tag(...)`` instead of ``E('tag', ...)``:: >>> ET.tostring(E.tag()) '<tag/>' >>> ET.tostring(E.tag("text")) '<tag>text</tag>' >>> ET.tostring(E.tag(E.subtag("text"), "tail")) '<tag><subtag>text</subtag>tail</tag>' 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 reservered characters: <spam&egg>."), ET.XML("<p>And finally, here is an embedded XHTML fragment.</p>"), ) ) ) print ET.tostring(page) Here's a prettyprinted version of the output from the above script:: <html> <head> <title>This is a sample document</title> </head> <body> <h1 class="title">Hello!</h1> <p>This is a paragraph with <b>bold</b> text in it!</p> <p>This is another paragraph, with <a href="http://www.python.org">link</a>.</p> <p>Here are some reservered characters: <spam&egg>.</p> <p>And finally, here is an embedded XHTML fragment.</p> </body> </html> c s | d j o d | d | _ n d | _ | o t | ƒ | _ n d | _ | d j o | | _ n t i | _ ˆ o ˆ i ƒ ‰ n h ‰ d „ } t ˆ j o | ˆ t <n t ˆ j o | ˆ t <n ‡ d † } t ˆ j o | ˆ t <n ˆ | _ d S( Nt {t }c C sK t | ƒ o# | d i p d | | d _ n | i p d | | _ d S( Niÿÿÿÿt ( t lent elemt tailt itemt text( R R ( ( R t add_text™ s #c se | i } xU | i ƒ D]G \ } } t | t ƒ o | | | <q ˆ t | ƒ d | ƒ | | <q Wd S( N( R t attribR t itemst kt vt isinstancet basestringt typemapt typet None( R R R R R ( R ( R t add_dict£ s ( t namespaceR t selft _namespacet nsmapt dictt _nsmapt makeelementt _makeelementt ETt ElementR t copyR t strt unicodeR t _typemap( R R R R R! R R ( ( R R t __init__€ s, c O s- | i i } | i d j o"