Skip to content

Commit ad0c57f

Browse files
committed
Issue #21986: Idle now matches interpreter in not pickling user code objects.
Patch by Claudiu Popa
1 parent 9086f92 commit ad0c57f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Lib/idlelib/rpc.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import sys
3131
import os
32+
import io
3233
import socket
3334
import select
3435
import socketserver
@@ -53,16 +54,15 @@ def pickle_code(co):
5354
ms = marshal.dumps(co)
5455
return unpickle_code, (ms,)
5556

56-
# XXX KBK 24Aug02 function pickling capability not used in Idle
57-
# def unpickle_function(ms):
58-
# return ms
57+
def dumps(obj, protocol=None):
58+
f = io.BytesIO()
59+
p = CodePickler(f, protocol)
60+
p.dump(obj)
61+
return f.getvalue()
5962

60-
# def pickle_function(fn):
61-
# assert isinstance(fn, type.FunctionType)
62-
# return repr(fn)
63-
64-
copyreg.pickle(types.CodeType, pickle_code, unpickle_code)
65-
# copyreg.pickle(types.FunctionType, pickle_function, unpickle_function)
63+
class CodePickler(pickle.Pickler):
64+
dispatch_table = {types.CodeType: pickle_code}
65+
dispatch_table.update(copyreg.dispatch_table)
6666

6767
BUFSIZE = 8*1024
6868
LOCALHOST = '127.0.0.1'
@@ -329,7 +329,7 @@ def newseq(self):
329329
def putmessage(self, message):
330330
self.debug("putmessage:%d:" % message[0])
331331
try:
332-
s = pickle.dumps(message)
332+
s = dumps(message)
333333
except pickle.PicklingError:
334334
print("Cannot pickle:", repr(message), file=sys.__stderr__)
335335
raise

0 commit comments

Comments
 (0)