summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2014-10-10 23:34:38 (GMT)
committerTerry Jan Reedy <tjreedy@udel.edu>2014-10-10 23:34:38 (GMT)
commitda821db8375f5637530f05a22c66e9aeee733d91 (patch)
tree918f530cd4309bcdaaa8408983935740d9cfec8b
parent759920c5cb7aa8f9218b35148a3e4fb129cb86f2 (diff)
parentad0c57fed8ede5b7291d0e401f3595975f5eddad (diff)
downloadcpython-da821db8375f5637530f05a22c66e9aeee733d91.zip
cpython-da821db8375f5637530f05a22c66e9aeee733d91.tar.gz
cpython-da821db8375f5637530f05a22c66e9aeee733d91.tar.bz2
Merge with 3.4: #21986, don't pickle user code objects.
-rw-r--r--Lib/idlelib/rpc.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/Lib/idlelib/rpc.py b/Lib/idlelib/rpc.py
index 9c51b8f..f2aae51 100644
--- a/Lib/idlelib/rpc.py
+++ b/Lib/idlelib/rpc.py
@@ -29,6 +29,7 @@ accomplished in Idle.
import sys
import os
+import io
import socket
import select
import socketserver
@@ -53,16 +54,15 @@ def pickle_code(co):
ms = marshal.dumps(co)
return unpickle_code, (ms,)
-# XXX KBK 24Aug02 function pickling capability not used in Idle
-# def unpickle_function(ms):
-# return ms
+def dumps(obj, protocol=None):
+ f = io.BytesIO()
+ p = CodePickler(f, protocol)
+ p.dump(obj)
+ return f.getvalue()
-# def pickle_function(fn):
-# assert isinstance(fn, type.FunctionType)
-# return repr(fn)
-
-copyreg.pickle(types.CodeType, pickle_code, unpickle_code)
-# copyreg.pickle(types.FunctionType, pickle_function, unpickle_function)
+class CodePickler(pickle.Pickler):
+ dispatch_table = {types.CodeType: pickle_code}
+ dispatch_table.update(copyreg.dispatch_table)
BUFSIZE = 8*1024
LOCALHOST = '127.0.0.1'
@@ -329,7 +329,7 @@ class SocketIO(object):
def putmessage(self, message):
self.debug("putmessage:%d:" % message[0])
try:
- s = pickle.dumps(message)
+ s = dumps(message)
except pickle.PicklingError:
print("Cannot pickle:", repr(message), file=sys.__stderr__)
raise