diff options
author | jquast <contact@jeffquast.com> | 2013-09-22 07:50:26 -0700 |
---|---|---|
committer | jquast <contact@jeffquast.com> | 2013-09-22 07:50:26 -0700 |
commit | 09eb306956c8e5968878b4d934faa7c1cb054ec6 (patch) | |
tree | ee74fb8eb4d8af267cc1f04061f70a22d028e268 /pexpect | |
parent | 0d57a29c9549a6b6c542596f2b949bb259c0cda5 (diff) | |
download | pexpect-git-09eb306956c8e5968878b4d934faa7c1cb054ec6.tar.gz |
2 unicode fixes + some docfix lang brevity
interact() method failed, which attempted to write raw bytes:
>>> sys.stdout.write(b'')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be str, not bytes
this is resolved in class spawn, by encoding as 'ascii'.
A much more serious looping test failed, where val == '', and val is b''
>>> b'' == ''
False
Also included is some docfix language
Diffstat (limited to 'pexpect')
-rw-r--r-- | pexpect/__init__.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/pexpect/__init__.py b/pexpect/__init__.py index 1873e46..5276fa2 100644 --- a/pexpect/__init__.py +++ b/pexpect/__init__.py @@ -1045,8 +1045,8 @@ class spawn(object): def sendline(self, s=''): - '''Sends string ``s`` to child process like send(), but it adds a - linefeed (os.linesep), returning number of bytes written. ''' + '''Wraps send(), sending string ``s`` to child process, with os.linesep + automatically appended. Returns number of bytes written. ''' n = self.send(s) n = n + self.send(self.linesep) @@ -1054,8 +1054,9 @@ class spawn(object): def sendcontrol(self, char): - '''This sends a control character to the child such as Ctrl-C or - Ctrl-D. For example, to send a Ctrl-G (ASCII 7, bell):: + '''Helper method that wraps send() with mnumonic access for sending control + character to the child (such as Ctrl-C or Ctrl-D). For example, to send + Ctrl-G (ASCII 7, bell, '\a'):: child.sendcontrol('g') @@ -1611,7 +1612,7 @@ class spawn(object): ''' # Flush the buffer. - self.stdout.write(self.buffer) + self.stdout.write(self.buffer.decode('ascii')) self.stdout.flush() self.buffer = self.string_type() mode = tty.tcgetattr(self.STDIN_FILENO) @@ -1626,7 +1627,7 @@ class spawn(object): '''This is used by the interact() method. ''' - while data != '' and self.isalive(): + while data != b'' and self.isalive(): n = os.write(fd, data) data = data[n:] @@ -1657,7 +1658,7 @@ class spawn(object): data = self.__interact_read(self.STDIN_FILENO) if input_filter: data = input_filter(data) - i = data.rfind(escape_character) + i = data.rfind(self._coerce_expect_string(escape_character)) if i != -1: data = data[:i] self.__interact_writen(self.child_fd, data) |