summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Kluyver <takowl@gmail.com>2015-09-12 11:43:46 +0100
committerThomas Kluyver <takowl@gmail.com>2015-09-12 11:46:18 +0100
commitb485f7e2bd673f85950bc15b37908884be806fcb (patch)
tree3668a354e33b79c9dbff68aa2494d49ab0f878bb
parent9681f4c10e54ac10f611bae827c33a68d81a98af (diff)
downloadpexpect-git-b485f7e2bd673f85950bc15b37908884be806fcb.tar.gz
Add encoding parameter for fdspawn
Closes gh-92
-rw-r--r--pexpect/fdpexpect.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/pexpect/fdpexpect.py b/pexpect/fdpexpect.py
index 2b51e24..ca8cf07 100644
--- a/pexpect/fdpexpect.py
+++ b/pexpect/fdpexpect.py
@@ -32,7 +32,8 @@ class fdspawn(SpawnBase):
descriptor. For example, you could use it to read through a file looking
for patterns, or to control a modem or serial device. '''
- def __init__ (self, fd, args=None, timeout=30, maxread=2000, searchwindowsize=None, logfile=None):
+ def __init__ (self, fd, args=None, timeout=30, maxread=2000, searchwindowsize=None,
+ logfile=None, encoding=None, codec_errors='strict'):
'''This takes a file descriptor (an int) or an object that support the
fileno() method (returning an int). All Python file-like objects
support fileno(). '''
@@ -50,7 +51,8 @@ class fdspawn(SpawnBase):
self.args = None
self.command = None
- SpawnBase.__init__(self, timeout, maxread, searchwindowsize, logfile)
+ SpawnBase.__init__(self, timeout, maxread, searchwindowsize, logfile,
+ encoding=encoding, codec_errors=codec_errors)
self.child_fd = fd
self.own_fd = False
self.closed = False
@@ -93,7 +95,8 @@ class fdspawn(SpawnBase):
s = self._coerce_send_string(s)
self._log(s, 'send')
- return os.write(self.child_fd, s)
+ b = self._encoder.encode(s, final=False)
+ return os.write(self.child_fd, b)
def sendline(self, s):
"Write to fd with trailing newline, return number of bytes written"