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:
|
self.feed(b"", isFinal=True) |
The following line not support empty data and isFinal at the same time:
|
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)
Hi,
I try to understand why ExpatParser raise exception during close action.
I create a xml parser with asyncio protocol to parse xmpp message.
during
connection_madecall I create parser and attach handler:In
data_receivedfunction I parse data on close document:But the close() call raise exception:
I check with pdb and the issue come from:
cpython/Lib/xml/sax/expatreader.py
Line 248 in cb18269
The following line not support empty data and isFinal at the same time:
cpython/Lib/xml/sax/expatreader.py
Line 211 in cb18269
In my debugger I can see the following values for this line:
CPython versions tested on:
3.11.2
Operating systems tested on:
Linux (debian)