[pypy-svn] r12051 - pypy/dist/pypy/lib
pedronis at codespeak.net
pedronis at codespeak.net
Sat May 7 03:21:05 CEST 2005
Author: pedronis
Date: Sat May 7 03:21:04 2005
New Revision: 12051
Modified:
pypy/dist/pypy/lib/cPickle.py
Log:
better emulation of cPickle
Modified: pypy/dist/pypy/lib/cPickle.py
==============================================================================
--- pypy/dist/pypy/lib/cPickle.py (original)
+++ pypy/dist/pypy/lib/cPickle.py Sat May 7 03:21:04 2005
@@ -5,17 +5,8 @@
from pickle import *
from pickle import __doc__, __version__, format_version, compatible_formats
-class UnpickleableError(PicklingError):
- def __init__(self, *args):
- self.args=args
-
- def __str__(self):
- a=self.args
- a=a and type(a[0]) or '(what)'
- return 'Cannot pickle %s objects' % a
-
-class BadPickleGet(UnpicklingError):
- pass
+BadPickleGet = KeyError
+UnpickleableError = PicklingError
# ____________________________________________________________
# XXX some temporary dark magic to produce pickled dumps that are
@@ -25,10 +16,21 @@
PythonPickler = Pickler
class Pickler(PythonPickler):
+ def __init__(self, *args):
+ self.__f = None
+ if len(args) == 1 and isinstance(args[0], int):
+ self.__f = StringIO()
+ PythonPickler.__init__(self, self.__f, args[0])
+ else:
+ PythonPickler.__init__(self, *args)
+
def memoize(self, obj):
self.memo[None] = None # cPickle starts counting at one
return PythonPickler.memoize(self, obj)
+ def getvalue(self):
+ return self.__f and self.__f.getvalue()
+
def dump(obj, file, protocol=None, bin=None):
Pickler(file, protocol, bin).dump(obj)
More information about the Pypy-commit
mailing list