mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-20 07:19:40 +08:00
Documented the misbehavior of Windows pipes in combination with Python.
This commit is contained in:
@@ -438,6 +438,13 @@ if sys.version_info[:2] == (3, 3):
|
|||||||
_PICKLE_PROTOCOL = 2
|
_PICKLE_PROTOCOL = 2
|
||||||
is_windows = sys.platform == 'win32'
|
is_windows = sys.platform == 'win32'
|
||||||
|
|
||||||
|
# The Windows shell on Python 2 consumes all control characters (below 32) and expand on
|
||||||
|
# all Python versions \n to \r\n.
|
||||||
|
# pickle starting from protocol version 1 uses binary data, which could not be escaped by
|
||||||
|
# any normal unicode encoder. Therefore, the only bytes encoder which doesn't produce
|
||||||
|
# control characters is binascii.hexlify.
|
||||||
|
|
||||||
|
|
||||||
def pickle_load(file):
|
def pickle_load(file):
|
||||||
if is_windows:
|
if is_windows:
|
||||||
try:
|
try:
|
||||||
@@ -447,6 +454,8 @@ def pickle_load(file):
|
|||||||
return pickle.loads(data, encoding='bytes')
|
return pickle.loads(data, encoding='bytes')
|
||||||
else:
|
else:
|
||||||
return pickle.loads(data)
|
return pickle.loads(data)
|
||||||
|
# Python on Windows don't throw EOF errors for pipes. So reraise them with
|
||||||
|
# the correct type, which is cought upwards.
|
||||||
except OSError:
|
except OSError:
|
||||||
raise EOFError()
|
raise EOFError()
|
||||||
else:
|
else:
|
||||||
@@ -455,6 +464,7 @@ def pickle_load(file):
|
|||||||
else:
|
else:
|
||||||
return pickle.load(file)
|
return pickle.load(file)
|
||||||
|
|
||||||
|
|
||||||
def pickle_dump(data, file):
|
def pickle_dump(data, file):
|
||||||
if is_windows:
|
if is_windows:
|
||||||
try:
|
try:
|
||||||
@@ -462,7 +472,11 @@ def pickle_dump(data, file):
|
|||||||
data = binascii.hexlify(data)
|
data = binascii.hexlify(data)
|
||||||
file.write(data)
|
file.write(data)
|
||||||
file.write(b'\n')
|
file.write(b'\n')
|
||||||
|
# On Python 3.3 flush throws sometimes an error even if the two file writes
|
||||||
|
# should done it already before. This could be also computer / speed depending.
|
||||||
file.flush()
|
file.flush()
|
||||||
|
# Python on Windows don't throw EPIPE errors for pipes. So reraise them with
|
||||||
|
# the correct type and error number.
|
||||||
except OSError:
|
except OSError:
|
||||||
raise IOError(errno.EPIPE)
|
raise IOError(errno.EPIPE)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user