diff options
author | noah <noah@656d521f-e311-0410-88e0-e7920216d269> | 2007-12-22 01:41:04 +0000 |
---|---|---|
committer | noah <noah@656d521f-e311-0410-88e0-e7920216d269> | 2007-12-22 01:41:04 +0000 |
commit | f7436e5fb8c5b237bd657b1457b6db01de08b096 (patch) | |
tree | 22b8c3bf49ad03f90d5371f39498e23c98addc7e /pexpect | |
parent | 9dce98f7f2503fe719bfdb0d8db71395d9661502 (diff) | |
download | pexpect-f7436e5fb8c5b237bd657b1457b6db01de08b096.tar.gz |
cleaned up fdpexpect a bit.
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@504 656d521f-e311-0410-88e0-e7920216d269
Diffstat (limited to 'pexpect')
-rw-r--r-- | pexpect/fdpexpect.py | 34 | ||||
-rwxr-xr-x | pexpect/tests/test_filedescriptor.py | 3 |
2 files changed, 23 insertions, 14 deletions
diff --git a/pexpect/fdpexpect.py b/pexpect/fdpexpect.py index c9f2d3b..8797e43 100644 --- a/pexpect/fdpexpect.py +++ b/pexpect/fdpexpect.py @@ -1,5 +1,6 @@ -""" -TODO: This is BETA. When it gets stable I will move it into the pexpect.py file. +"""This is like pexpect, but will work on any file descriptor that you pass it. +So you are reponsible for opening and close the file descriptor. + $Id$ """ @@ -9,15 +10,17 @@ import os __all__ = ['fdspawn'] class fdspawn (spawn): - """This is like pexpect.spawn but allows you to supply your own, - already open file descriptor. For example, you could use it to - read through a file looking for patterns, or to control a modem or - serial device. - """ + + """This is like pexpect.spawn but allows you to supply your own open file + 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=[], timeout=30, maxread=2000, searchwindowsize=None, logfile=None): - """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(). - """ + + """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(). """ + ### TODO: Add better handling of trying to use fdspawn in place of spawn ### TODO: (overload to allow fdspawn to also handle commands as spawn does. @@ -41,9 +44,11 @@ class fdspawn (spawn): self.name = '<file descriptor %d>' % fd def __del__ (self): + return def close (self): + if super(fdspawn, self).child_fd == -1: return if self.own_fd: @@ -55,9 +60,10 @@ class fdspawn (spawn): self.closed = True def isalive (self): - """This checks if the file descriptor is still valid. - If os.fstat() does not raise an exception then we assume it is alive. - """ + + """This checks if the file descriptor is still valid. If os.fstat() + does not raise an exception then we assume it is alive. """ + if self.child_fd == -1: return False try: @@ -67,8 +73,10 @@ class fdspawn (spawn): return False def terminate (self, force=False): + raise ExceptionPexpect ('This method is not valid for file descriptors.') def kill (self, sig): + return diff --git a/pexpect/tests/test_filedescriptor.py b/pexpect/tests/test_filedescriptor.py index 4243548..34e32d5 100755 --- a/pexpect/tests/test_filedescriptor.py +++ b/pexpect/tests/test_filedescriptor.py @@ -37,7 +37,8 @@ class ExpectTestCase(PexpectTestCase.PexpectTestCase): fd = os.open ('TESTDATA.txt', os.O_RDONLY) s = fdpexpect.fdspawn (fd) assert not s.isatty() - os.close(fd) + #os.close(fd) + fd.close(fd) ### def test_close_does_not_close_fd (self): ### """Calling close() on a fdpexpect.fdspawn object should not |