Next / Previous / Contents / Shipman's homepage

14.2. Prologue

The module begins with a comment pointing back to this documentation, and acknowledging Fredrik Lundh's work.
""" An element builder for lxml.etree
    $Revision: 1.55 $  $Date: 2012/08/11 21:44:19 $
For documentation, see:
Borrows heavily from the work of Fredrik Lundh; see:

The et module is lxml.etree.
# 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.
    from functools import partial
except ImportError:
    def partial(func, *args, **keywords):
        def newfunc(*fargs, **fkeywords):
            newkeywords = keywords.copy()
            return func(*(args + fargs), **newkeywords)
        newfunc.func  =  func
        newfunc.args  =  args
        newfunc.keywords  =  keywords
        return newfunc