Stefan Behnel added the comment: What about this idea: instead of changing the internal C implementation, we could provide a simple parser target wrapper class (say, "EventBuilder") that the parser would simply recognise with isinstance(). Then it would unpack the wrapped target and configure itself as it currently does. So you'd use it like this:
target = EventBuilder(TreeBuilder()) parser = XMLParser(target=target) parser.feed(some_xml_data) print list(target.events()) I mean, it doesn't really matter if the implementation is a fake, as long as the API is right. And the only API that the EventBuilder has is its events() method that returns the iterator. The EventBuilder implementation would then be class EventBuilder: def __init__(self, target=None): if target is None: target = TreeBuilder() self._target = target self._events = [] def events(self): # existing code for distructive iteration over self._events goes here ... and the rest would be done by the XMLParser() constructor, i.e. it would register the "_events" list in the expat callbacks. What do you think? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17741> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com