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

14.7. class ElementMaker: The factory class

The name E that the user imports is not a class. It is a factory object, that is, an instance of the ElementMaker factory class.
# - - - - -   c l a s s   E l e m e n t M a k e r

class ElementMaker(object):
    '''ElementTree element factory class

          [ (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) ]

For a discussion of intended functions and the Cleanroom software development methodology, see the author's Cleanroom page.

You can use the optional typeMap argument to provide logic to handle types other than the ones defined in Section 13.1, “Using the etbuilder module”. Refer to the constructor for a discussion of the internal state item .__typeMap and how it works in element construction.