def custom_factory(tag, attrs): for element in boundElements: if(element.is_match(tag, attrs)): #for this to work properly, we need to construct the objects #by calling a class method or something, since their #constructors have been modified (from the default __init__(self, tag, *attrs) #to make them easier to build by hand #(see outputMe above) return element(tag, attrs) return _ElementInterface(tag, attrs)