Menu

#36 TypeError using

v1.0 (example)
closed
nobody
None
5
2014-06-03
2014-06-02
No

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

1 Attachments

Related

Bugs: #36

Discussion

  • Jonathan Glines

    Jonathan Glines - 2014-06-02

    Title should be "TypeError using readline with spawnu". I slipped and hit submit instead of preview.

     
  • Thomas Kluyver

    Thomas Kluyver - 2014-06-02

    Thanks. Pexpect development has moved to Github - do you have time to submit the patch as a pull request?

    https://github.com/pexpect/pexpect

     
  • Thomas Kluyver

    Thomas Kluyver - 2014-06-02

    It would also be good to have a test for this.

     
    • Jonathan Glines

      Jonathan Glines - 2014-06-02

      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:

      It would also be good to have a test for this.

      Status: open
      Group: v1.0 (example)
      Created: Mon Jun 02, 2014 10:16 PM UTC by Jonathan Glines
      Last Updated: Mon Jun 02, 2014 10:41 PM UTC
      Owner: nobody

      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


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/pexpect/bugs/36/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #36

  • Thomas Kluyver

    Thomas Kluyver - 2014-06-03
    • status: open --> closed
     
  • Thomas Kluyver

    Thomas Kluyver - 2014-06-03

    This is now tracked on Github at https://github.com/pexpect/pexpect/pull/67

    I've closed the issue here.

     

Log in to post a comment.