Message71339
While porting Leo to Python 3.0, I found that passing any byte stream to
xml.sax.parser.parse will hang the parser. My quick fix was to change:
while buffer != "":
to:
while buffer != "" and buffer != b"":
at line 123 of xmlreader.py
Here is the entire function:
def parse(self, source):
from . import saxutils
source = saxutils.prepare_input_source(source)
self.prepareParser(source)
file = source.getByteStream()
buffer = file.read(self._bufsize)
### while buffer != "":
while buffer != "" and buffer != b"": ### EKR
self.feed(buffer)
buffer = file.read(self._bufsize)
self.close()
For reference, here is the code in Leo that was hanging::
parser = xml.sax.make_parser()
parser.setFeature(xml.sax.handler.feature_external_ges,1)
handler = saxContentHandler(c,inputFileName,silent,inClipboard)
parser.setContentHandler(handler)
parser.parse(theFile)
Looking at the test_expat_file function in test_sax.py, it appears that
the essential difference between the code that hangs and the successful
unit test is that that Leo opens the file in 'rb' mode. (code not shown)
It's doubtful that 'rb' mode is correct--from the unit test I deduce
that the default 'r' mode would be better. Anyway, it would be nice if
parser.parse didn't hang on dubious streams.
HTH.
Edward |
|
Date |
User |
Action |
Args |
2008-08-18 15:06:15 | edreamleo | set | recipients:
+ edreamleo |
2008-08-18 15:06:15 | edreamleo | set | messageid: <1219071975.28.0.899711064426.issue3590@psf.upfronthosting.co.za> |
2008-08-18 15:06:14 | edreamleo | link | issue3590 messages |
2008-08-18 15:06:13 | edreamleo | create | |
|