Commits

Philip Jenvey committed ca985b5 Merge

merge py3.3-fixes2

  • Participants
  • Parent commits c046f2f, e4d0e6a
  • Branches py3.3

Comments (0)

Files changed (2)

File pypy/module/bz2/interp_bz2.py

 from rpython.rtyper.tool import rffi_platform as platform
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rtyper.lltypesystem import lltype
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.typedef import TypeDef, interp_attrproperty_bytes
 from pypy.interpreter.typedef import GetSetProperty
         BZ2_bzCompressEnd(self.bzs)
         lltype.free(self.bzs, flavor='raw')
 
+    def __getstate__(self):
+        raise oefmt(self.space.w_TypeError, "cannot serialize '%T' object", self)
+
     @unwrap_spec(data='bufferstr')
     def compress(self, data):
         """compress(data) -> string
 W_BZ2Compressor.typedef = TypeDef("_bz2.BZ2Compressor",
     __doc__ = W_BZ2Compressor.__doc__,
     __new__ = interp2app(descr_compressor__new__),
+    __getstate__ = interp2app(W_BZ2Compressor.__getstate__),
     compress = interp2app(W_BZ2Compressor.compress),
     flush = interp2app(W_BZ2Compressor.flush),
 )
         BZ2_bzDecompressEnd(self.bzs)
         lltype.free(self.bzs, flavor='raw')
 
+    def __getstate__(self):
+        raise oefmt(self.space.w_TypeError, "cannot serialize '%T' object", self)
+
     def eof_w(self, space):
         if self.running:
             return space.w_False
 W_BZ2Decompressor.typedef = TypeDef("_bz2.BZ2Decompressor",
     __doc__ = W_BZ2Decompressor.__doc__,
     __new__ = interp2app(descr_decompressor__new__),
+    __getstate__ = interp2app(W_BZ2Decompressor.__getstate__),
     unused_data = interp_attrproperty_bytes("unused_data", W_BZ2Decompressor),
     eof = GetSetProperty(W_BZ2Decompressor.eof_w),
     decompress = interp2app(W_BZ2Decompressor.decompress),

File pypy/module/bz2/test/test_bz2_compdecomp.py

         data += bz2c.flush()
         assert self.decompress(data) == self.TEXT
 
+    def test_compressor_pickle_error(self):
+        from bz2 import BZ2Compressor
+        import pickle
+
+        exc = raises(TypeError, pickle.dumps, BZ2Compressor())
+        assert exc.value.args[0] == "cannot serialize '_bz2.BZ2Compressor' object"
+
 
 class AppTestBZ2Decompressor(CheckAllocation):
     spaceconfig = dict(usemodules=('bz2', 'rctime'))
         assert decompressed_data == b''
         raises(IOError, bz2d.decompress, self.BUGGY_DATA)
 
+    def test_decompressor_pickle_error(self):
+        from bz2 import BZ2Decompressor
+        import pickle
+
+        exc = raises(TypeError, pickle.dumps, BZ2Decompressor())
+        assert exc.value.args[0] == "cannot serialize '_bz2.BZ2Decompressor' object"
+
 
 class AppTestBZ2ModuleFunctions(CheckAllocation):
     spaceconfig = dict(usemodules=('bz2', 'rctime'))