diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-04-18 17:37:06 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-04-18 17:37:06 (GMT) |
commit | 5b235d0923d44ce1b535ee7d63ce5d556f8dd1f8 (patch) | |
tree | 2e7847d7060eacaaead514f1be0d1a6902f584f2 /Doc | |
parent | 323d2927f0a2858802b96988f77dc41dffd74744 (diff) | |
download | cpython-5b235d0923d44ce1b535ee7d63ce5d556f8dd1f8.zip cpython-5b235d0923d44ce1b535ee7d63ce5d556f8dd1f8.tar.gz cpython-5b235d0923d44ce1b535ee7d63ce5d556f8dd1f8.tar.bz2 |
Issue #17741: Add ElementTree.IncrementalParser, an event-driven parser for non-blocking applications.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/xml.etree.elementtree.rst | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Doc/library/xml.etree.elementtree.rst b/Doc/library/xml.etree.elementtree.rst index 6597a25..da03764 100644 --- a/Doc/library/xml.etree.elementtree.rst +++ b/Doc/library/xml.etree.elementtree.rst @@ -397,6 +397,9 @@ Functions If you need a fully populated element, look for "end" events instead. + .. note:: + For real event-driven parsing, see :class:`IncrementalParser`. + .. function:: parse(source, parser=None) @@ -833,6 +836,48 @@ QName Objects :class:`QName` instances are opaque. +IncrementalParser Objects +^^^^^^^^^^^^^^^^^^^^^^^^^ + + +.. class:: IncrementalParser(events=None, parser=None) + + An incremental, event-driven parser suitable for non-blocking applications. + *events* is a list of events to report back. The supported events are the + strings ``"start"``, ``"end"``, ``"start-ns"`` and ``"end-ns"`` (the "ns" + events are used to get detailed namespace information). If *events* is + omitted, only ``"end"`` events are reported. *parser* is an optional + parser instance. If not given, the standard :class:`XMLParser` parser is + used. + + .. method:: data_received(data) + + Feed the given bytes data to the incremental parser. + + .. method:: eof_received() + + Signal the incremental parser that the data stream is terminated. + + .. method:: events() + + Iterate over the events which have been encountered in the data fed + to the parser. This method yields ``(event, elem)`` pairs, where + *event* is a string representing the type of event (e.g. ``"end"``) + and *elem* is the encountered :class:`Element` object. + + .. note:: + + :class:`IncrementalParser` only guarantees that it has seen the ">" + character of a starting tag when it emits a "start" event, so the + attributes are defined, but the contents of the text and tail attributes + are undefined at that point. The same applies to the element children; + they may or may not be present. + + If you need a fully populated element, look for "end" events instead. + + .. versionadded:: 3.4 + + .. _elementtree-treebuilder-objects: TreeBuilder Objects |