This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author scoder
Recipients eli.bendersky, flox, jcea, pitrou, python-dev, scoder
Date 2013-08-09.18:11:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1376071914.4.0.606005764169.issue17741@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2013-08-09 18:11:54scodersetrecipients: + scoder, jcea, pitrou, eli.bendersky, flox, python-dev
2013-08-09 18:11:54scodersetmessageid: <1376071914.4.0.606005764169.issue17741@psf.upfronthosting.co.za>
2013-08-09 18:11:54scoderlinkissue17741 messages
2013-08-09 18:11:54scodercreate