2424import subprocess
2525import sys
2626from copy import copy as _copy
27+ from pathlib import Path
28+ from pipes import quote as _quote
2729from shlex import split
2830from subprocess import CalledProcessError
2931
30- import six
31- from six .moves import map
32-
33-
34- try :
35- # Python 2
36- from pipes import quote as _quote
37- except ImportError :
38- from shutil import quote as _quote
39-
40-
41- try :
42- # Python 3.4
43- from pathlib import Path
44- except ImportError :
45- Path = None
46-
4732
4833__all__ = [
4934 'CalledProcessError' ,
@@ -111,7 +96,7 @@ def _convert_pathlib_path(path):
11196 return path
11297
11398 if isinstance (path , Path ):
114- return six . text_type (path )
99+ return str (path )
115100
116101 return path
117102
@@ -150,14 +135,14 @@ def _normalize_args(args):
150135 CommandWrapper instances into a one-dimensional list of strings.
151136 """
152137
153- if isinstance (args , six . string_types ):
138+ if isinstance (args , ( str ,) ):
154139 return shlex .split (args )
155140
156141 def normalize_arg (arg ):
157142 arg = _convert_pathlib_path (arg )
158143
159- if isinstance (arg , six . string_types ):
160- return [six . text_type (arg )]
144+ if isinstance (arg , ( str ,) ):
145+ return [str (arg )]
161146 if isinstance (arg , AbstractWrapper ):
162147 return list (map (_convert_pathlib_path , arg .command ))
163148
@@ -173,42 +158,14 @@ def normalize_arg(arg):
173158# -----------------------------------------------------------------------------
174159# Decorators
175160
176- def _backport_devnull (func ):
177- """Decorator used to backport the subprocess.DEVNULL functionality from
178- Python 3 to Python 2.
179- """
180-
181- # DEVNULL was introduced in Python 3.3
182- if _PY_VERSION >= (3 , 3 ):
183- return func
184-
185- @functools .wraps (func )
186- def wrapper (command , ** kwargs ):
187- stdout = kwargs .get ('stdout' , sys .stdout )
188- stderr = kwargs .get ('stderr' , sys .stderr )
189-
190- if stdout != DEVNULL and stderr != DEVNULL :
191- return func (command , ** kwargs )
192-
193- with open (os .devnull , 'w' ) as devnull :
194- if stdout == DEVNULL :
195- kwargs ['stdout' ] = devnull
196- if stderr == DEVNULL :
197- kwargs ['stderr' ] = devnull
198-
199- return func (command , ** kwargs )
200-
201- return wrapper
202-
203-
204161def _normalize_command (func ):
205162 """Decorator used to uniformly normalize the input command of the
206163 subprocess wrappers.
207164 """
208165
209166 @functools .wraps (func )
210167 def wrapper (command , ** kwargs ):
211- if not isinstance (command , six . string_types ):
168+ if not isinstance (command , ( str ,) ):
212169 command = _normalize_args (command )
213170
214171 return func (command , ** kwargs )
@@ -237,10 +194,9 @@ def wrapper(command, **kwargs):
237194# Public Functions
238195
239196def quote (command ):
240- """Extension of the standard pipes.quote (Python 2) or shutil.quote
241- (Python 3) that handles both strings and lists of strings. This mirrors
242- how the subprocess package can handle commands as both a standalone string
243- or list of strings.
197+ """Extension of the standard shutil.quote that handles both strings and
198+ lists of strings. This mirrors how the subprocess package can handle
199+ commands as both a standalone string or list of strings.
244200
245201 >>> quote('/Applications/App Store.app')
246202 "'/Applications/App Store.app'"
@@ -249,7 +205,7 @@ def quote(command):
249205 "rm -rf '~/Documents/My Homework'"
250206 """
251207
252- if isinstance (command , six . string_types ):
208+ if isinstance (command , ( str ,) ):
253209 return _quote (command )
254210
255211 if isinstance (command , collections .Iterable ):
@@ -288,7 +244,6 @@ def __init__(self, command, **kwargs):
288244 solution to this problem in the form of their `method_decorator`.
289245 """
290246
291- @_backport_devnull
292247 @_normalize_command
293248 @_add_echo_kwarg
294249 def closure (command , ** kwargs ):
@@ -305,7 +260,6 @@ def __exit__(self, *exc):
305260 self .wait ()
306261
307262
308- @_backport_devnull
309263@_normalize_command
310264@_add_echo_kwarg
311265def call (command , ** kwargs ):
@@ -316,7 +270,6 @@ def call(command, **kwargs):
316270 return subprocess .call (command , ** kwargs )
317271
318272
319- @_backport_devnull
320273@_normalize_command
321274@_add_echo_kwarg
322275def check_call (command , ** kwargs ):
@@ -327,7 +280,6 @@ def check_call(command, **kwargs):
327280 return subprocess .check_call (command , ** kwargs )
328281
329282
330- @_backport_devnull
331283@_normalize_command
332284@_add_echo_kwarg
333285def check_output (command , ** kwargs ):
@@ -337,16 +289,11 @@ def check_output(command, **kwargs):
337289 Output is returned as a unicode string.
338290 """
339291
340- if six .PY3 :
341- kwargs ['encoding' ] = 'utf-8'
292+ kwargs ['encoding' ] = 'utf-8'
342293
343294 output = subprocess .check_output (command , ** kwargs )
344295
345- if six .PY3 :
346- return output
347-
348- # Return unicode string rather than bytes in Python 2.
349- return six .text_type (output , errors = 'ignore' )
296+ return output
350297
351298
352299# -----------------------------------------------------------------------------
@@ -484,8 +431,7 @@ def wraps(command):
484431 return CommandWrapper (command )
485432
486433
487- @six .add_metaclass (abc .ABCMeta )
488- class AbstractWrapper (object ):
434+ class AbstractWrapper (object , metaclass = abc .ABCMeta ):
489435 """Abstract base class for implementing wrappers around command line
490436 utilities and executables. Subclasses must implement the `command` method
491437 which returns a command list suitable for use with executor instances.
@@ -555,7 +501,7 @@ def __init__(self):
555501
556502 self .EXECUTABLE = _convert_pathlib_path (self .EXECUTABLE )
557503
558- if not isinstance (self .EXECUTABLE , six . string_types ):
504+ if not isinstance (self .EXECUTABLE , ( str ,) ):
559505 raise AttributeError (
560506 '{}.EXECUTABLE must be an executable name or path' .format (
561507 type (self ).__name__ ))
0 commit comments