From 99130e7664abd9d1fbc67d098b5399d87cf0758d Mon Sep 17 00:00:00 2001 From: "T.Rzepka" Date: Sat, 17 Feb 2018 13:49:10 +0100 Subject: [PATCH] Fix for Python 2 and 3 on Windows, see #1037. --- jedi/_compatibility.py | 35 +++++++++++++++---- jedi/evaluate/compiled/subprocess/__init__.py | 2 -- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/jedi/_compatibility.py b/jedi/_compatibility.py index 73a981a1..52f23b25 100644 --- a/jedi/_compatibility.py +++ b/jedi/_compatibility.py @@ -2,6 +2,8 @@ To ensure compatibility from Python ``2.7`` - ``3.x``, a module has been created. Clearly there is huge need to use conforming syntax. """ +import binascii +import errno import sys import imp import os @@ -434,14 +436,35 @@ if sys.version_info[:2] == (3, 3): _PICKLE_PROTOCOL = 2 - +is_windows = sys.platform == 'win32' def pickle_load(file): - if is_py3: - return pickle.load(file, encoding='bytes') + if is_windows: + try: + data = file.readline() + data = binascii.unhexlify(data.strip()) + if is_py3: + return pickle.loads(data, encoding='bytes') + else: + return pickle.loads(data) + except OSError: + raise EOFError() else: - return pickle.load(file) - + if is_py3: + return pickle.load(file, encoding='bytes') + else: + return pickle.load(file) def pickle_dump(data, file): - pickle.dump(data, file, protocol=_PICKLE_PROTOCOL) + if is_windows: + try: + data = pickle.dumps(data, protocol=_PICKLE_PROTOCOL) + data = binascii.hexlify(data) + file.write(data) + file.write(b'\n') + file.flush() + except OSError: + raise IOError(errno.EPIPE) + else: + pickle.dump(data, file, protocol=_PICKLE_PROTOCOL) + file.flush() diff --git a/jedi/evaluate/compiled/subprocess/__init__.py b/jedi/evaluate/compiled/subprocess/__init__.py index a8de8792..7a87d552 100644 --- a/jedi/evaluate/compiled/subprocess/__init__.py +++ b/jedi/evaluate/compiled/subprocess/__init__.py @@ -187,7 +187,6 @@ class _CompiledSubprocess(object): data = evaluator_id, function, args, kwargs try: pickle_dump(data, self._process.stdin) - self._process.stdin.flush() except (socket.error, IOError) as e: # Once Python2 will be removed we can just use `BrokenPipeError`. if e.errno != errno.EPIPE: @@ -283,7 +282,6 @@ class Listener(object): result = True, traceback.format_exc(), e pickle_dump(result, file=stdout) - stdout.flush() class AccessHandle(object):