From 211b0b7b63d109c2b9006e7c3b78be942a81e0b9 2011-11-26 01:10:38 From: Thomas Kluyver Date: 2011-11-26 01:10:38 Subject: [PATCH] Handle subprocesses more consistently between pexpect and pexpect-u. --- diff --git a/IPython/external/pexpect/_pexpect.py b/IPython/external/pexpect/_pexpect.py index eae954c..b8b99f5 100644 --- a/IPython/external/pexpect/_pexpect.py +++ b/IPython/external/pexpect/_pexpect.py @@ -88,7 +88,7 @@ support it. Pexpect is intended for UNIX-like operating systems.""") __version__ = '2.6.dev' version = __version__ version_info = (2,6,'dev') -__all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'run', 'which', +__all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'spawnb', 'run', 'which', 'split_command_line', '__version__'] # Exception classes used by this module. diff --git a/IPython/utils/_process_posix.py b/IPython/utils/_process_posix.py index ab4b127..9d17a00 100644 --- a/IPython/utils/_process_posix.py +++ b/IPython/utils/_process_posix.py @@ -148,16 +148,16 @@ class ProcessHandler(object): # We only search for the 'patterns' timeout or EOF, which aren't in # the text itself. #child = pexpect.spawn(pcmd, searchwindowsize=1) - try: - child = pexpect.spawn(self.sh, args=['-c', cmd], encoding=enc) # Pexpect-U - except TypeError: - child = pexpect.spawn(self.sh, args=['-c', cmd]) # Vanilla Pexpect + if hasattr(pexpect, 'spawnb'): + child = pexpect.spawnb(self.sh, args=['-c', cmd]) # Pexpect-U + else: + child = pexpect.spawn(self.sh, args=['-c', cmd]) # Vanilla Pexpect flush = sys.stdout.flush while True: # res is the index of the pattern that caused the match, so we # know whether we've finished (if we matched EOF) or not res_idx = child.expect_list(patterns, self.read_timeout) - print(py3compat.cast_unicode(child.before[out_size:], enc), end='') + print(child.before[out_size:].decode(enc, 'replace'), end='') flush() if res_idx==EOF_index: break @@ -173,7 +173,7 @@ class ProcessHandler(object): try: out_size = len(child.before) child.expect_list(patterns, self.terminate_timeout) - print(py3compat.cast_unicode(child.before[out_size:], enc), end='') + print(child.before[out_size:].decode(enc, 'replace'), end='') sys.stdout.flush() except KeyboardInterrupt: # Impatient users tend to type it multiple times