From 1e6d9e95831d6126961e09c3364da502369fd828 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 15 Mar 2019 11:59:46 +0530 Subject: [PATCH] Replace use of pickle for the editor completion worker --- src/calibre/gui2/tweak_book/completion/worker.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/tweak_book/completion/worker.py b/src/calibre/gui2/tweak_book/completion/worker.py index 4fb0c966aa..13959df159 100644 --- a/src/calibre/gui2/tweak_book/completion/worker.py +++ b/src/calibre/gui2/tweak_book/completion/worker.py @@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2014, Kovid Goyal ' -import cPickle, os, sys +import os, sys from threading import Thread, Event, RLock from Queue import Queue from contextlib import closing @@ -16,6 +16,7 @@ from calibre.constants import iswindows from calibre.gui2.tweak_book.completion.basic import Request from calibre.gui2.tweak_book.completion.utils import DataError from calibre.utils.ipc import eintr_retry_call +from calibre.utils.serialize import msgpack_loads, msgpack_dumps COMPLETION_REQUEST = 'completion request' CLEAR_REQUEST = 'clear request' @@ -46,7 +47,7 @@ class CompletionWorker(Thread): 'from {0} import run_main, {1}; run_main({1})'.format(self.__class__.__module__, self.worker_entry_point)) auth_key = os.urandom(32) address, self.listener = create_listener(auth_key) - eintr_retry_call(p.stdin.write, cPickle.dumps((address, auth_key), -1)) + eintr_retry_call(p.stdin.write, msgpack_dumps((address, auth_key))) p.stdin.flush(), p.stdin.close() self.control_conn = eintr_retry_call(self.listener.accept) self.data_conn = eintr_retry_call(self.listener.accept) @@ -172,7 +173,8 @@ def completion_worker(): def run_main(func): from multiprocessing.connection import Client - address, key = cPickle.loads(eintr_retry_call(sys.stdin.read)) + stdin = getattr(sys.stdin, 'buffer', sys.stdin) + address, key = msgpack_loads(eintr_retry_call(stdin.read)) with closing(Client(address, authkey=key)) as control_conn, closing(Client(address, authkey=key)) as data_conn: func(control_conn, data_conn)