diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-03-20 22:56:36 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-03-20 22:56:36 (GMT) |
commit | 6d58d64919bb12e05fa4bf3a34909650c695cff6 (patch) | |
tree | a8b7d7915779a6cc30f7f6a9d69191d7bd34a002 | |
parent | b938bcd211bfcab13be38200a2f59947691118bb (diff) | |
download | cpython-6d58d64919bb12e05fa4bf3a34909650c695cff6.zip cpython-6d58d64919bb12e05fa4bf3a34909650c695cff6.tar.gz cpython-6d58d64919bb12e05fa4bf3a34909650c695cff6.tar.bz2 |
Issue #11127: Raise a TypeError when trying to pickle a socket object.
-rw-r--r-- | Lib/socket.py | 3 | ||||
-rw-r--r-- | Lib/test/test_socket.py | 7 | ||||
-rw-r--r-- | Misc/NEWS | 2 |
3 files changed, 12 insertions, 0 deletions
diff --git a/Lib/socket.py b/Lib/socket.py index 1e28549..5715034 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -112,6 +112,9 @@ class socket(_socket.socket): s[7:]) return s + def __getstate__(self): + raise TypeError("Cannot serialize socket object") + def dup(self): """dup() -> socket object diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index d761a73..8b23ae9 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -18,6 +18,7 @@ import contextlib from weakref import proxy import signal import math +import pickle try: import fcntl except ImportError: @@ -764,6 +765,12 @@ class GeneralModuleTests(unittest.TestCase): fp.close() self.assertEqual(repr(fp), "<_io.BufferedReader name=-1>") + def test_pickle(self): + sock = socket.socket() + with sock: + for protocol in range(pickle.HIGHEST_PROTOCOL + 1): + self.assertRaises(TypeError, pickle.dumps, sock, protocol) + @unittest.skipUnless(thread, 'Threading required for this test.') class BasicTCPTest(SocketConnectedTest): @@ -83,6 +83,8 @@ Library - Issue #4391: Use proper gettext plural forms in optparse. +- Issue #11127: Raise a TypeError when trying to pickle a socket object. + - Issue #11563: Connection:close header is sent by requests using URLOpener class which helps in closing of sockets after connection is over. Patch contributions by Jeff McNeil and Nadeem Vawda. |