[issue17741] event-driven XML parser

Stefan Behnel report at bugs.python.org
Fri Aug 9 13:32:06 CEST 2013


Stefan Behnel added the comment:

Actually, let me take that last paragraph back. There is an Obvious Way to do it, and that's the feed() and close() methods. They are the existing and established ElementTree interface for incremental parsing. The fact that close() doesn't clean up all state is IMHO a minor issue. The state will be cleaned up automatically once the iteration terminates, and that's the normal behaviour of iterators. So it actually fits both protocols quite nicely.

I'd just leave the stream protocol out completely here. For one, the implementation isn't complete anyway (the connection_*() methods don't make much sense), and as I said, it's not very useful to consider the parser a general end-point to that protocol.

I'd also suggest returning the iterator over the remaining events from close(), just like the TreeBuilder returns the tree. That covers the (less common) use case of first parsing everything and then processing the events. I'll add another patch that does that.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17741>
_______________________________________


More information about the Python-bugs-list mailing list