summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2013-10-28 21:41:24 +0100
committerNadeem Vawda <nadeem.vawda@gmail.com>2013-10-28 21:41:24 +0100
commite6514f533efba25e5aeba50208515d02d528995a (patch)
tree9895781bdec365d927ee7669366773119c5164ad /Lib
parentd1b48998e5b404387c8f0942197189ba3207c15e (diff)
parent3797065ac55997741fd625a30a8308c04ee5c9b9 (diff)
downloadcpython-git-e6514f533efba25e5aeba50208515d02d528995a.tar.gz
#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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_bz2.py10
-rw-r--r--Lib/test/test_lzma.py9
2 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py
index d087cc3ee9..8d93e2d88f 100644
--- a/Lib/test/test_bz2.py
+++ b/Lib/test/test_bz2.py
@@ -5,6 +5,7 @@ from test.support import bigmemtest, _4G
import unittest
from io import BytesIO
import os
+import pickle
import random
import subprocess
import sys
@@ -628,6 +629,11 @@ class BZ2CompressorTest(BaseTest):
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)
@@ -679,6 +685,10 @@ class BZ2DecompressorTest(BaseTest):
compressed = None
decompressed = None
+ def testPickle(self):
+ with self.assertRaises(TypeError):
+ pickle.dumps(BZ2Decompressor())
+
class CompressDecompressTest(BaseTest):
def testCompress(self):
diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py
index b6af563300..26d19da5e9 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):