#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.
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py
index 912fac1..6764e59 100644
--- a/Lib/test/test_bz2.py
+++ b/Lib/test/test_bz2.py
@@ -5,6 +5,7 @@
import unittest
from io import BytesIO
import os
+import pickle
import random
import subprocess
import sys
@@ -621,6 +622,11 @@
finally:
data = None
+ def testPickle(self):
+ with self.assertRaises(TypeError):
+ pickle.dumps(BZ2Compressor())
+
+
class BZ2DecompressorTest(BaseTest):
def test_Constructor(self):
self.assertRaises(TypeError, BZ2Decompressor, 42)
@@ -672,6 +678,10 @@
compressed = None
decompressed = None
+ def testPickle(self):
+ with self.assertRaises(TypeError):
+ pickle.dumps(BZ2Decompressor())
+
class CompressDecompressTest(BaseTest):
def testCompress(self):