From 343973ded2d15bbb9a0c2385db1e9fbd9bda2363 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sat, 12 Sep 2015 12:40:17 +0100 Subject: Fix return value of send() on Python 2 --- pexpect/popen_spawn.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pexpect/popen_spawn.py b/pexpect/popen_spawn.py index 0b8ff77..f5eb204 100644 --- a/pexpect/popen_spawn.py +++ b/pexpect/popen_spawn.py @@ -116,14 +116,18 @@ class PopenSpawn(SpawnBase): for s in sequence: self.send(s) - def _send(self, s): - return self.proc.stdin.write(s) - def send(self, s): s = self._coerce_send_string(s) self._log(s, 'send') - return self._send(s) + b = self._encoder.encode(s, final=False) + if PY3: + return self.proc.stdin.write(b) + else: + # On Python 2, .write() returns None, so we return the length of + # bytes written ourselves. This assumes they all got written. + self.proc.stdin.write(b) + return len(b) def sendline(self, s=''): '''Wraps send(), sending string ``s`` to child process, with os.linesep -- cgit v1.2.1