Ñò IJ¿Kc@sudZddklZyddklZWnej od„ZnXd„Zdefd„ƒYZ e ƒZ dS( swetbuilder.py: An element builder for lxml.etree ================================================================ $Revision: 1.30 $ $Date: 2010/04/09 22:55:22 $ ================================================================ For documentation, see: http://www.nmt.edu/tcc/help/pubs/pylxml/ Borrows heavily from the work of Fredrik Lundh; see: http://effbot.org/ iÿÿÿÿ(tetree(tpartialcs4‡‡‡fd†}ˆ|_ˆ|_ˆ|_|S(Ncs*ˆiƒ}|i|ƒˆˆ||ŽS(N(tcopytupdate(tfargst fkeywordst newkeywords(targstfunctkeywords(s//u/www/docs/tcc/help/pubs/python25/etbuilder.pytnewfuncs  (RRR (RRR R ((R RRs//u/www/docs/tcc/help/pubs/python25/etbuilder.pyRs    cGshdi|ƒd6S(sþHelper function for adding 'class=...' attributes to tags. [ names is a list of strings -> return a dictionary with one key 'class' and the related value the concatenation of (names) with one space between them ] t tclass(tjoin(tnames((s//u/www/docs/tcc/help/pubs/python25/etbuilder.pytCLASSst ElementMakercBs5eZdZdd„Zd„Zd„Zd„ZRS(s{ElementTree element factory class Exports: ElementMaker ( typeMap=None ): [ (typeMap is an optional dictionary whose keys are type objects T, and each corresponding value is a function with calling sequence f(elt, item) and generic intended function [ (elt is an et.Element) and (item has type T) -> elt := elt with item added ]) -> return a new ElementMaker instance that has calling sequence E(*p, **kw) and intended function [ p[0] exists and is a str -> return a new et.Element instance whose name is p[0], and remaining elements of p become string content of that element (for types str, unicode, and int) or attributes (for type dict, and members of kw) or children (for type et.Element), plus additional handling from typeMap if it is provided ] and allows arbitrary method calls of the form E.tag(*p, **kw) with intended function [ return a new et.Element instance whose name is (tag), and elements of p and kw have the same effects as E(*(p[1:]), **kw) ] cs«|djo hˆ_n|iƒˆ_d„}|ˆit<ˆit<‡fd†}|ˆit if type(arg) is a key in self.__typeMap -> elt := elt modified as per self.__typeMap[type(arg)] else -> raise TypeError ] sInvalid argument type: %rN(tcallableRR+tKeyErrort TypeError(RRR2R!thandler((s//u/www/docs/tcc/help/pubs/python25/etbuilder.pyt __handleArg·s  cCs t||ƒS(síHandle arbitrary method calls. [ tag is a string -> return a new et.Element instance whose name is (tag), and elements of p and kw have the same effects as E(*(p[1:]), **kw) ] (R(RR/((s//u/www/docs/tcc/help/pubs/python25/etbuilder.pyt __getattr__ÓsN(t__name__t __module__t__doc__R%R-R3R.R9(((s//u/www/docs/tcc/help/pubs/python25/etbuilder.pyR(s  Q  N( R<tlxmlRR)t functoolsRt ImportErrorRtobjectRtE(((s//u/www/docs/tcc/help/pubs/python25/etbuilder.pyt s ¶