Next / Previous / Contents / TCC Help System / NM Tech homepage

14.2. Prologue

The module begins with a comment pointing back to this documentation, and acknowledging Fredrik Lundh's work.

etbuilder.py
"""etbuilder.py: An element builder for lxml.etree
================================================================
    $Revision: 1.55 $  $Date: 2012/08/11 21:44:19 $
================================================================
For documentation, see:
    http://www.nmt.edu/tcc/help/pubs/pylxml/
Borrows heavily from the work of Fredrik Lundh; see:
    http://effbot.org/zone/
"""

The et module is lxml.etree.

etbuilder.py
#================================================================
# Imports
#----------------------------------------------------------------

from lxml import etree as et

The functools.partial() function is used to curry a function call in Section 14.11, “ElementMaker.__getattr__(): Handle arbitrary method calls”.

However, the functools module is new in Python 2.5. In order to make this module work in a Python 2.4 install, we will anticipate a possible failure to import functools, providing that functionality with a substitute partial() function. This function is stolen directly from the Python Library Reference.

etbuilder.py
try:
    from functools import partial
except ImportError:
    def partial(func, *args, **keywords):
        def newfunc(*fargs, **fkeywords):
            newkeywords = keywords.copy()
            newkeywords.update(fkeywords)
            return func(*(args + fargs), **newkeywords)
        newfunc.func  =  func
        newfunc.args  =  args
        newfunc.keywords  =  keywords
        return newfunc