#19395: Raise exception when pickling a (BZ2|LZMA)(Compressor|Decompressor).

The underlying C libraries provide no mechanism for serializing compressor and
decompressor objects, so actually pickling these classes is impractical.
Previously, these objects would be pickled without error, but attempting to use
a deserialized instance would segfault the interpreter.
This commit is contained in:
Nadeem Vawda 2013-10-28 21:41:24 +01:00
commit e6514f533e
4 changed files with 57 additions and 2 deletions

View file

@ -1,5 +1,6 @@
from io import BytesIO, UnsupportedOperation
import os
import pickle
import random
import unittest
@ -216,6 +217,14 @@ class CompressorDecompressorTestCase(unittest.TestCase):
finally:
input = cdata = ddata = None
# Pickling raises an exception; there's no way to serialize an lzma_stream.
def test_pickle(self):
with self.assertRaises(TypeError):
pickle.dumps(LZMACompressor())
with self.assertRaises(TypeError):
pickle.dumps(LZMADecompressor())
class CompressDecompressFunctionTestCase(unittest.TestCase):