Skip to content

Commit

Permalink
interact logs by self._log(s, 'read') and 'send'
Browse files Browse the repository at this point in the history
Closes issue #190: __interact_copy implements
its own read() and write() calls, circumventing
the self._log() system, and omitting to log data
that is sent to the child pty.

Related, resolve old docstring about a setlog()
method that was removed in SpawnBase refactor.
  • Loading branch information
jquast committed Sep 21, 2015
1 parent f599388 commit dcdac8a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pexpect/pty_spawn.py
Expand Up @@ -388,8 +388,8 @@ def read_nonblocking(self, size=1, timeout=-1):
'''This reads at most size characters from the child application. It
includes a timeout. If the read does not complete within the timeout
period then a TIMEOUT exception is raised. If the end of file is read
then an EOF exception will be raised. If a log file was set using
setlog() then all data will also be written to the log file.
then an EOF exception will be raised. If a logfile is specified, a
copy is written to that log.
If timeout is None then the read may block indefinitely.
If timeout is -1 then the self.timeout value is used. If timeout is 0
Expand Down Expand Up @@ -689,6 +689,9 @@ def interact(self, escape_character=chr(29),
entered as ``Ctrl - ]``, the very same as BSD telnet. To prevent
escaping, escape_character may be set to None.
If a logfile is specified, then the data sent and received from the
child process in interact mode is duplicated to the given log.
You may pass in optional input and output filter functions. These
functions should take a string and return a string. The output_filter
will be passed all the output from the child process. The input_filter
Expand Down Expand Up @@ -761,9 +764,7 @@ def __interact_copy(self, escape_character=None,
break
if output_filter:
data = output_filter(data)
if self.logfile is not None:
self.logfile.write(data)
self.logfile.flush()
self._log(data, 'read')
os.write(self.STDOUT_FILENO, data)
if self.STDIN_FILENO in r:
data = self.__interact_read(self.STDIN_FILENO)
Expand All @@ -774,8 +775,11 @@ def __interact_copy(self, escape_character=None,
i = data.rfind(escape_character)
if i != -1:
data = data[:i]
if data:
self._log(data, 'send')
self.__interact_writen(self.child_fd, data)
break
self._log(data, 'send')
self.__interact_writen(self.child_fd, data)

def __select(self, iwtd, owtd, ewtd, timeout=None):
Expand Down

0 comments on commit dcdac8a

Please sign in to comment.