summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Kluyver <takowl@gmail.com>2015-09-12 12:40:17 +0100
committerThomas Kluyver <takowl@gmail.com>2015-09-12 12:40:17 +0100
commit343973ded2d15bbb9a0c2385db1e9fbd9bda2363 (patch)
tree60ca1d9301611d8ce7f39c39d71a4af9cdbbe459
parentd7d75979bc8ac10bf3044947a944bafb166dfe7c (diff)
downloadpexpect-git-343973ded2d15bbb9a0c2385db1e9fbd9bda2363.tar.gz
Fix return value of send() on Python 2
-rw-r--r--pexpect/popen_spawn.py12
1 files 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