windows: correct proc.py to pass test_imphooks tests

This commit is contained in:
Robert W. Brewer 2015-05-15 00:05:12 -04:00
parent 2fb5ed6cf3
commit 29f609191b

View file

@ -107,6 +107,14 @@ class ProcProxy(Thread):
self.stdout = None
self.stderr = None
if ON_WINDOWS:
if self.p2cwrite != -1:
self.p2cwrite = msvcrt.open_osfhandle(self.p2cwrite.Detach(), 0)
if self.c2pread != -1:
self.c2pread = msvcrt.open_osfhandle(self.c2pread.Detach(), 0)
if self.errread != -1:
self.errread = msvcrt.open_osfhandle(self.errread.Detach(), 0)
if self.p2cwrite != -1:
self.stdin = io.open(self.p2cwrite, 'wb', -1)
if universal_newlines:
@ -116,6 +124,7 @@ class ProcProxy(Thread):
self.stdout = io.open(self.c2pread, 'rb', -1)
if universal_newlines:
self.stdout = io.TextIOWrapper(self.stdout)
if self.errread != -1:
self.stderr = io.open(self.errread, 'rb', -1)
if universal_newlines:
@ -134,6 +143,13 @@ class ProcProxy(Thread):
sp_stdin = io.TextIOWrapper(self.stdin)
else:
sp_stdin = io.StringIO("")
if ON_WINDOWS:
if self.c2pwrite != -1:
self.c2pwrite = msvcrt.open_osfhandle(self.c2pwrite.Detach(), 0)
if self.errwrite != -1:
self.errwrite = msvcrt.open_osfhandle(self.errwrite.Detach(), 0)
if self.c2pwrite != -1:
sp_stdout = io.TextIOWrapper(io.open(self.c2pwrite, 'wb', -1))
else:
@ -142,6 +158,7 @@ class ProcProxy(Thread):
sp_stderr = io.TextIOWrapper(io.open(self.errwrite, 'wb', -1))
else:
sp_stderr = sys.stderr
r = self.f(self.args, sp_stdin, sp_stdout, sp_stderr)
self.returncode = r if r is not None else True
@ -170,6 +187,7 @@ class ProcProxy(Thread):
_winapi.DUPLICATE_SAME_ACCESS)
return Handle(h)
def _get_handles(self, stdin, stdout, stderr):
"""Construct and return tuple with IO objects:
p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
@ -241,6 +259,7 @@ class ProcProxy(Thread):
c2pread, c2pwrite,
errread, errwrite)
else:
# POSIX versions
def _get_handles(self, stdin, stdout, stderr):