There seems to be a bug in the spawn.readline() function that makes it impossible to use with spawnu objects (i.e. when using strings rather than bytes). I have attached a small patch that fixes this. I patched against the pexpect-3.2 tarball and tested with Python 3.2 on cygwin.
I can reproduce this with code such as:
child = pexpect.spawnu("echo foobar") foobar = child.readline()
Without the patch I get this TypeError message:
File "REDACTED", line 39, in username username = child.readline() File "/usr/lib/python3.2/site-packages/pexpect/__init__.py", line 975, in readline index = self.expect([b'\r\n', self.delimiter]) File "/usr/lib/python3.2/site-packages/pexpect/__init__.py", line 1416, in expect compiled_pattern_list = self.compile_pattern_list(pattern) File "/usr/lib/python3.2/site-packages/pexpect/__init__.py", line 1336, in compile_pattern_list self._pattern_type_err(p) File "/usr/lib/python3.2/site-packages/pexpect/__init__.py", line 1286, in _pattern_type_err for ast in self.allowed_string_types]) TypeError: got <class 'bytes'> (b'\r\n') as pattern, must be one of: <class 'str'>, pexpect.EOF, pexpect.TIMEOUT
Regards,
Jonathan Glines
Title should be "TypeError using readline with spawnu". I slipped and hit submit instead of preview.
Thanks. Pexpect development has moved to Github - do you have time to submit the patch as a pull request?
https://github.com/pexpect/pexpect
It would also be good to have a test for this.
I will write a unit test and submit a pull request on github by tomorrow.
On Mon, Jun 2, 2014 at 4:41 PM, Thomas Kluyver takowl@users.sf.net wrote:
Related
Bugs:
#36This is now tracked on Github at https://github.com/pexpect/pexpect/pull/67
I've closed the issue here.