@@ -88,10 +88,7 @@ def __init__(self, msg, errno=-1):
88
88
self .errno = errno
89
89
90
90
91
- # Check if this is Windows NT and above.
92
- if sys .platform == "win32" and sys .getwindowsversion ()[3 ] == 2 :
93
-
94
- import winprocess
91
+ if sys .platform .startswith ("win" ):
95
92
import subprocess
96
93
97
94
# In Python 3 on Windows, a lot of the functions previously
@@ -106,6 +103,16 @@ def subprocess_import(attr):
106
103
return value
107
104
raise ImportError
108
105
106
+ GetStdHandle = subprocess_import ('GetStdHandle' )
107
+ STD_INPUT_HANDLE = subprocess_import ('STD_INPUT_HANDLE' )
108
+ STD_OUTPUT_HANDLE = subprocess_import ('STD_OUTPUT_HANDLE' )
109
+ STD_ERROR_HANDLE = subprocess_import ('STD_ERROR_HANDLE' )
110
+
111
+
112
+ # Check if this is Windows NT and above.
113
+ if sys .platform == "win32" and sys .getwindowsversion ()[3 ] == 2 :
114
+ import winprocess
115
+
109
116
try :
110
117
# These subprocess variables have moved around between Python versions.
111
118
list2cmdline = subprocess_import ('list2cmdline' )
@@ -389,16 +396,14 @@ def _needToHackAroundStdHandles(cls):
389
396
if sys .platform != "win32" :
390
397
cls .__needToHackAroundStdHandles = False
391
398
else :
392
- from _subprocess import GetStdHandle , STD_INPUT_HANDLE
393
399
stdin_handle = GetStdHandle (STD_INPUT_HANDLE )
394
400
if stdin_handle is not None :
395
401
cls .__needToHackAroundStdHandles = True
396
402
else :
397
403
cls .__needToHackAroundStdHandles = False
398
404
return cls .__needToHackAroundStdHandles
399
405
400
- @classmethod
401
- def _isFileObjInheritable (cls , fileobj , stream_name ):
406
+ def _isFileObjInheritable (self , fileobj , stream_name ):
402
407
"""Check if a given file-like object (or whatever else subprocess.Popen
403
408
takes as a handle/stream) can be correctly inherited by a child process.
404
409
This just duplicates the code in subprocess.Popen._get_handles to make
@@ -408,7 +413,6 @@ def _isFileObjInheritable(cls, fileobj, stream_name):
408
413
@param fileobj The object being used as a fd/handle/whatever
409
414
@param stream_name The name of the stream, "stdin", "stdout", or "stderr"
410
415
"""
411
- import _subprocess
412
416
import ctypes
413
417
import msvcrt
414
418
new_handle = None
@@ -423,11 +427,11 @@ def _isFileObjInheritable(cls, fileobj, stream_name):
423
427
try :
424
428
if fileobj is None :
425
429
std_handle = {
426
- "stdin" : _subprocess . STD_INPUT_HANDLE ,
427
- "stdout" : _subprocess . STD_OUTPUT_HANDLE ,
428
- "stderr" : _subprocess . STD_ERROR_HANDLE ,
430
+ "stdin" : STD_INPUT_HANDLE ,
431
+ "stdout" : STD_OUTPUT_HANDLE ,
432
+ "stderr" : STD_ERROR_HANDLE ,
429
433
}[stream_name ]
430
- handle = _subprocess . GetStdHandle (std_handle )
434
+ handle = GetStdHandle (std_handle )
431
435
if handle is None :
432
436
# subprocess.Popen._get_handles creates a new pipe here
433
437
# we don't have to worry about things we create
0 commit comments