PATCH: Make PickleResultReader handle StringIO files
Mark Mitchell
mark at codesourcery.com
Sun Sep 28 23:04:53 UTC 2003
This patch fixes the reading of expectation files in the GUI. (Before
this patch, you get an unhandled exception in the GUI.)
When the ResultReader abstraction was created, this code (which was in
load_outcomes) did not get moved into the PickleResultReader class.
Nathaniel, did you make this change purposefully, or was it just an
accident?
It would be nice if Python provided a better way to handle the EOF
condition, but I haven't found it yet. If anyone has suggestions, that
would be great.
--
Mark Mitchell <mark at codesourcery.com>
CodeSourcery, LLC
-------------- next part --------------
2003-09-28 Mark Mitchell <mark at codesourcery.com>
* qm/test/classes/pickle_result_stream.py
(PickleResultReader.__init__): Treat cPickle.UnpicklingError like
EOFError.
Index: qm/test/classes/pickle_result_stream.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/test/classes/pickle_result_stream.py,v
retrieving revision 1.5
diff -c -5 -p -r1.5 pickle_result_stream.py
*** qm/test/classes/pickle_result_stream.py 15 Jul 2003 00:10:36 -0000 1.5
--- qm/test/classes/pickle_result_stream.py 28 Sep 2003 21:56:10 -0000
*************** class PickleResultReader(FileResultReade
*** 179,189 ****
self._annotations = {}
# Check for a version number
try:
version = self.__unpickler.load()
! except EOFError:
# This file is empty, no more handling needed.
return
if not isinstance(version, int):
# Version 0 file, no version number; in fact, we're
--- 179,189 ----
self._annotations = {}
# Check for a version number
try:
version = self.__unpickler.load()
! except (EOFError, cPickle.UnpicklingError):
# This file is empty, no more handling needed.
return
if not isinstance(version, int):
# Version 0 file, no version number; in fact, we're
*************** class PickleResultReader(FileResultReade
*** 247,257 ****
def GetResult(self):
while 1:
try:
thing = self.__unpickler.load()
! except EOFError:
return None
else:
if thing is _annotation_sentinel:
# We're looking for results, but this is an annotation,
# so skip over it.
--- 247,261 ----
def GetResult(self):
while 1:
try:
thing = self.__unpickler.load()
! except (EOFError, cPickle.UnpicklingError):
! # When reading from a StringIO, no EOFError will be
! # raised when the unpickler tries to read from the file.
! # Instead, the unpickler raises UnpicklingError when it
! # tries to unpickle the empty string.
return None
else:
if thing is _annotation_sentinel:
# We're looking for results, but this is an annotation,
# so skip over it.
More information about the qmtest
mailing list