-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Closed as not planned
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Hi,
I try to understand why ExpatParser raise exception during close action.
I create a xml parser with asyncio protocol to parse xmpp message.
class XMLProtocol(asyncio.Protocol):
during connection_made
call I create parser and attach handler:
self._parser = make_parser()
self._handler = XMLHandler(self._transport, self._bunny)
self._parser.setContentHandler(self._handler)
In data_received
function I parse data on close document:
def data_received(self, data):
try:
data = data.replace(b"<?xml version='1.0' encoding='UTF-8'?>", b"").decode().strip()
self._parser.feed(data)
self._parser.close()
self._parser.setContentHandler(self._handler)
self._parser.reset()
except UnicodeDecodeError:
pass
But the close() call raise exception:
xml.sax._exceptions.SAXParseException: <unknown>:1:109: no element found
I check with pdb and the issue come from:
cpython/Lib/xml/sax/expatreader.py
Line 248 in cb18269
self.feed(b"", isFinal=True) |
The following line not support empty data and isFinal at the same time:
cpython/Lib/xml/sax/expatreader.py
Line 211 in cb18269
self._parser.Parse(data, isFinal) |
In my debugger I can see the following values for this line:
(Pdb) self._parser
<pyexpat.xmlparser object at 0x7f5041bfffa0>
(Pdb) self._parser.Parse
<built-in method Parse of pyexpat.xmlparser object at 0x7f5041bfffa0>
(Pdb) data
b''
(Pdb) isFinal
True
CPython versions tested on:
3.11.2
Operating systems tested on:
Linux (debian)
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error