[qmtest] PATCH: Make PickleResultReader handle StringIO files

Nathaniel Smith njs at pobox.com
Mon Sep 29 02:24:00 UTC 2003


On Sun, Sep 28, 2003 at 05:09:22PM -0700, Mark Mitchell wrote:
> On Sun, 2003-09-28 at 16:33, Nathaniel Smith wrote:
> > ~$ python2.2
> > Python 2.2.3 (#1, Jun  4 2003, 02:54:59) 
> > [GCC 3.3 (Debian)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> import cStringIO
> 
> Actually, I don't think this is a version thing -- it's a StringIO vs.
> cStringIO thing.  Your test code works fine with Python 2.2.1 on my Red
> Hat 9 box -- but not if you replace cStringIO with StringIO.
> 
> We could use cStringIO internally -- but we've got no good way to
> prevent users from wanting to use StringIO themselves, so I think we
> still need the compensation code in PickleResultReader.  I'm not sure
> why StringIO doesn't sythesize the EOFError exception; that may be a
> misfeature in the Python library.

Hrm, yeah, that makes sense.  Must have gotten confused.

The StringIO bug, for the record, actually does seem to be fixed in
2.3; once we start depending on it, I'll become right about this code
;-).

(I guess if one were worried about still noticing invalid pickle
files, a future-compatible workaround would be to do something like:

except cPickle.UnpicklingError:
    if sys.version_info < (2, 3) \
       and instanceof(self.file, StringIO.StringIO):
         # handle EOF
    else:
         raise

More importantly, it would mark the code clearly self-obsolescing...)

-- Nathaniel

-- 
"Lull'd in the countless chambers of the brain,
Our thoughts are link'd by many a hidden chain:
Awake but one, and lo! what myriads rise!
Each stamps its image as the other flies"
  -- Ann Ward Radcliffe, The Mysteries of Udolpho



More information about the qmtest mailing list