##// END OF EJS Templates
more lints
M Bussonnier -
Show More
@@ -2,19 +2,6
2
2
3 This file is only meant to be imported by process.py, not by end-users.
3 This file is only meant to be imported by process.py, not by end-users.
4 """
4 """
5
6 #-----------------------------------------------------------------------------
7 # Copyright (C) 2010-2011 The IPython Development Team
8 #
9 # Distributed under the terms of the BSD License. The full license is in
10 # the file COPYING, distributed as part of this software.
11 #-----------------------------------------------------------------------------
12
13 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
16
17 # stdlib
18 import ctypes
5 import ctypes
19 import os
6 import os
20 import subprocess
7 import subprocess
@@ -25,18 +12,15 from ctypes.wintypes import HLOCAL, LPCWSTR
25 from subprocess import STDOUT
12 from subprocess import STDOUT
26 from threading import Thread
13 from threading import Thread
27 from types import TracebackType
14 from types import TracebackType
28 from typing import IO, Any, List, Optional
15 from typing import List, Optional
29
16
30 from . import py3compat
17 from . import py3compat
31 from ._process_common import arg_split as py_arg_split
18 from ._process_common import arg_split as py_arg_split
32
19
33 # our own imports
34 from ._process_common import process_handler, read_no_interrupt
20 from ._process_common import process_handler, read_no_interrupt
35 from .encoding import DEFAULT_ENCODING
21 from .encoding import DEFAULT_ENCODING
36
22
37 #-----------------------------------------------------------------------------
23
38 # Function definitions
39 #-----------------------------------------------------------------------------
40
24
41 class AvoidUNCPath:
25 class AvoidUNCPath:
42 """A context manager to protect command execution from UNC paths.
26 """A context manager to protect command execution from UNC paths.
@@ -72,7 +56,10 class AvoidUNCPath:
72 return None
56 return None
73
57
74 def __exit__(
58 def __exit__(
75 self, exc_type: Optional[type[BaseException]], exc_value: Optional[BaseException], traceback:TracebackType
59 self,
60 exc_type: Optional[type[BaseException]],
61 exc_value: Optional[BaseException],
62 traceback: TracebackType,
76 ) -> None:
63 ) -> None:
77 if self.is_unc_path:
64 if self.is_unc_path:
78 os.chdir(self.path)
65 os.chdir(self.path)
@@ -142,14 +129,15 def system(cmd: str) -> Optional[int]:
142 """
129 """
143 # The controller provides interactivity with both
130 # The controller provides interactivity with both
144 # stdin and stdout
131 # stdin and stdout
145 #import _process_win32_controller
132 # import _process_win32_controller
146 #_process_win32_controller.system(cmd)
133 # _process_win32_controller.system(cmd)
147
134
148 with AvoidUNCPath() as path:
135 with AvoidUNCPath() as path:
149 if path is not None:
136 if path is not None:
150 cmd = '"pushd %s &&"%s' % (path, cmd)
137 cmd = '"pushd %s &&"%s' % (path, cmd)
151 return process_handler(cmd, _system_body)
138 return process_handler(cmd, _system_body)
152
139
140
153 def getoutput(cmd: str) -> str:
141 def getoutput(cmd: str) -> str:
154 """Return standard output of executing cmd in a shell.
142 """Return standard output of executing cmd in a shell.
155
143
@@ -171,9 +159,10 def getoutput(cmd: str) -> str:
171 out = process_handler(cmd, lambda p: p.communicate()[0], STDOUT)
159 out = process_handler(cmd, lambda p: p.communicate()[0], STDOUT)
172
160
173 if out is None:
161 if out is None:
174 out = b''
162 out = b""
175 return py3compat.decode(out)
163 return py3compat.decode(out)
176
164
165
177 try:
166 try:
178 windll = ctypes.windll # type: ignore [attr-defined]
167 windll = ctypes.windll # type: ignore [attr-defined]
179 CommandLineToArgvW = windll.shell32.CommandLineToArgvW
168 CommandLineToArgvW = windll.shell32.CommandLineToArgvW
@@ -193,7 +182,7 try:
193
182
194 If strict=False, process_common.arg_split(...strict=False) is used instead.
183 If strict=False, process_common.arg_split(...strict=False) is used instead.
195 """
184 """
196 #CommandLineToArgvW returns path to executable if called with empty string.
185 # CommandLineToArgvW returns path to executable if called with empty string.
197 if commandline.strip() == "":
186 if commandline.strip() == "":
198 return []
187 return []
199 if not strict:
188 if not strict:
@@ -209,11 +198,13 try:
209 )
198 )
210 if arg is not None
199 if arg is not None
211 ]
200 ]
212 LocalFree(result_pointer)
201 # for side effects
202 _ = LocalFree(result_pointer)
213 return result
203 return result
214 except AttributeError:
204 except AttributeError:
215 arg_split = py_arg_split
205 arg_split = py_arg_split
216
206
207
217 def check_pid(pid: int) -> bool:
208 def check_pid(pid: int) -> bool:
218 # OpenProcess returns 0 if no such process (of ours) exists
209 # OpenProcess returns 0 if no such process (of ours) exists
219 # positive int otherwise
210 # positive int otherwise
General Comments 0
You need to be logged in to leave comments. Login now