summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Kluyver <takowl@gmail.com>2014-10-11 15:44:23 -0700
committerThomas Kluyver <takowl@gmail.com>2014-10-11 15:44:23 -0700
commit18797ad4af54ffef4975ec4c5ca9a643ecb58d4b (patch)
tree6c3cbbea042adfa1e8d9acc4c76aa3b82d9f5b27
parent75a5fa101370657efaf0344b1f7048a44bdc8eee (diff)
downloadpexpect-18797ad4af54ffef4975ec4c5ca9a643ecb58d4b.tar.gz
Record control characters in log files
-rw-r--r--pexpect/pty_spawn.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/pexpect/pty_spawn.py b/pexpect/pty_spawn.py
index f0b3662..3aa60be 100644
--- a/pexpect/pty_spawn.py
+++ b/pexpect/pty_spawn.py
@@ -474,6 +474,10 @@ class spawn(SpawnBase):
n = n + self.send(self.linesep)
return n
+ def _log_control(self, byte):
+ """Write control characters to the appropriate log files"""
+ self._log(byte, 'send')
+
def sendcontrol(self, char):
'''Helper method that wraps send() with mnemonic access for sending control
character to the child (such as Ctrl-C or Ctrl-D). For example, to send
@@ -483,7 +487,9 @@ class spawn(SpawnBase):
See also, sendintr() and sendeof().
'''
- return self.ptyproc.sendcontrol(char)
+ n, byte = self.ptyproc.sendcontrol(char)
+ self._log_control(byte)
+ return n
def sendeof(self):
'''This sends an EOF to the child. This sends a character which causes
@@ -495,13 +501,15 @@ class spawn(SpawnBase):
It is the responsibility of the caller to ensure the eof is sent at the
beginning of a line. '''
- self.ptyproc.sendeof()
+ n, byte = self.ptyproc.sendeof()
+ self._log_control(byte)
def sendintr(self):
'''This sends a SIGINT to the child. It does not require
the SIGINT to be the first character on a line. '''
- self.ptyproc.sendintr()
+ n, byte = self.ptyproc.sendintr()
+ self._log_control(byte)
@property
def flag_eof(self):
@@ -762,3 +770,7 @@ class spawnu(SpawnBaseUnicode, spawn):
def _send(self, s):
return os.write(self.child_fd, s.encode(self.encoding, self.errors))
+
+ def _log_control(self, byte):
+ s = byte.decode(self.encoding, 'replace')
+ self._log(s, 'send')