From 284a788ebc97e88858f9299669470438dcf0ebfb Mon Sep 17 00:00:00 2001 From: Nadeem Vawda Date: Mon, 28 Oct 2013 21:35:23 +0100 Subject: #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. --- Lib/test/test_lzma.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Lib/test/test_lzma.py') diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py index a13cf3bd09..ad9045604e 100644 --- a/Lib/test/test_lzma.py +++ b/Lib/test/test_lzma.py @@ -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): -- cgit v1.2.1