Example #1
0
 def __init__(self, *args, **kw):
     self.__f = None
     if len(args) == 1 and isinstance(args[0], int):
         self.__f = StringIO()
         PythonPickler.__init__(self, self.__f, args[0], **kw)
     else:
         PythonPickler.__init__(self, *args, **kw)
Example #2
0
def dumps(obj, protocol=None):
    if protocol > HIGHEST_PROTOCOL:
        # use cPickle error message, not pickle.py one
        raise ValueError("pickle protocol %d asked for; "
                     "the highest available protocol is %d" % (
                     protocol, HIGHEST_PROTOCOL))
    file = StringIO()
    Pickler(file, protocol).dump(obj)
    return file.getvalue()
Example #3
0
 def __init__(self, *args, **kw):
     self.__f = None
     if len(args) == 1 and isinstance(args[0], int):
         self.__f = StringIO()
         PythonPickler.__init__(self, self.__f, args[0], **kw)
     else:
         PythonPickler.__init__(self, *args, **kw)
Example #4
0
class Pickler(PythonPickler):
    def __init__(self, *args, **kw):
        self.__f = None
        if len(args) == 1 and isinstance(args[0], int):
            self.__f = StringIO()
            PythonPickler.__init__(self, self.__f, args[0], **kw)
        else:
            PythonPickler.__init__(self, *args, **kw)

    def memoize(self, obj):
        self.memo[id(None)] = None   # cPickle starts counting at one
        return PythonPickler.memoize(self, obj)

    def getvalue(self):
        return self.__f and self.__f.getvalue()
Example #5
0
class Pickler(PythonPickler):
    def __init__(self, *args, **kw):
        self.__f = None
        if len(args) == 1 and isinstance(args[0], int):
            self.__f = StringIO()
            PythonPickler.__init__(self, self.__f, args[0], **kw)
        else:
            PythonPickler.__init__(self, *args, **kw)

    def memoize(self, obj):
        self.memo[id(None)] = None   # cPickle starts counting at one
        return PythonPickler.memoize(self, obj)

    def getvalue(self):
        return self.__f and self.__f.getvalue()
Example #6
0
def dumps(obj, protocol=None):
    file = StringIO()
    Pickler(file, protocol).dump(obj)
    return file.getvalue()
Example #7
0
def loads(str):
    f = StringIO(str)
    return Unpickler(f).load()
Example #8
0
def dumps(obj, protocol=None):
    file = StringIO()
    Pickler(file, protocol).dump(obj)
    return file.getvalue()