Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Moving posix version of arg_split to _process_common.

  • Loading branch information...
commit c72bbc736ec524ce8fe3d3b04e92aa879b65be5f 1 parent 2381b09
J�rgen Stenarson authored
View
25 IPython/utils/_process_common.py
@@ -15,6 +15,7 @@
# Imports
#-----------------------------------------------------------------------------
import subprocess
+import shlex
import sys
from IPython.utils import py3compat
@@ -143,3 +144,27 @@ def getoutputerror(cmd):
return '', ''
out, err = out_err
return py3compat.bytes_to_str(out), py3compat.bytes_to_str(err)
+
+
+def arg_split(s, posix=False):
+ """Split a command line's arguments in a shell-like manner.
+
+ This is a modified version of the standard library's shlex.split()
+ function, but with a default of posix=False for splitting, so that quotes
+ in inputs are respected."""
+
+ # Unfortunately, python's shlex module is buggy with unicode input:
+ # http://bugs.python.org/issue1170
+ # At least encoding the input when it's unicode seems to help, but there
+ # may be more problems lurking. Apparently this is fixed in python3.
+ is_unicode = False
+ if (not py3compat.PY3) and isinstance(s, unicode):
+ is_unicode = True
+ s = s.encode('utf-8')
+ lex = shlex.shlex(s, posix=posix)
+ lex.whitespace_split = True
+ tokens = list(lex)
+ if is_unicode:
+ # Convert the tokens back to unicode.
+ tokens = [x.decode('utf-8') for x in tokens]
+ return tokens
View
26 IPython/utils/_process_posix.py
@@ -18,13 +18,12 @@
# Stdlib
import subprocess as sp
import sys
-import shlex
from IPython.external import pexpect
# Our own
from .autoattr import auto_attr
-from ._process_common import getoutput
+from ._process_common import getoutput, arg_split
from IPython.utils import text
from IPython.utils import py3compat
@@ -194,28 +193,5 @@ def system(self, cmd):
# (ls is a good example) that makes them hard.
system = ProcessHandler().system
-def arg_split(s, posix=False):
- """Split a command line's arguments in a shell-like manner.
-
- This is a modified version of the standard library's shlex.split()
- function, but with a default of posix=False for splitting, so that quotes
- in inputs are respected."""
-
- # Unfortunately, python's shlex module is buggy with unicode input:
- # http://bugs.python.org/issue1170
- # At least encoding the input when it's unicode seems to help, but there
- # may be more problems lurking. Apparently this is fixed in python3.
- is_unicode = False
- if (not py3compat.PY3) and isinstance(s, unicode):
- is_unicode = True
- s = s.encode('utf-8')
- lex = shlex.shlex(s, posix=posix)
- lex.whitespace_split = True
- tokens = list(lex)
- if is_unicode:
- # Convert the tokens back to unicode.
- tokens = [x.decode('utf-8') for x in tokens]
- return tokens
-
View
25 IPython/utils/_process_win32.py
@@ -175,27 +175,4 @@ def arg_split(commandline, posix=False):
retval = LocalFree(result_pointer)
return result
except AttributeError:
- import shlex
- #alternative if CommandLineToArgvW is not available
- def arg_split(s, posix=False):
- """Split a command line's arguments in a shell-like manner.
-
- This is a modified version of the standard library's shlex.split()
- function, but with a default of posix=False for splitting, so that quotes
- in inputs are respected."""
-
- # Unfortunately, python's shlex module is buggy with unicode input:
- # http://bugs.python.org/issue1170
- # At least encoding the input when it's unicode seems to help, but there
- # may be more problems lurking. Apparently this is fixed in python3.
- is_unicode = False
- if (not py3compat.PY3) and isinstance(s, unicode):
- is_unicode = True
- s = s.encode('utf-8')
- lex = shlex.shlex(s, posix=posix)
- lex.whitespace_split = True
- tokens = list(lex)
- if is_unicode:
- # Convert the tokens back to unicode.
- tokens = [x.decode('utf-8') for x in tokens]
- return tokens
+ from ._process_common import arg_split
Please sign in to comment.
Something went wrong with that request. Please try again.