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 | bda1a67c294368ce98b4810c3a25cace4df762a0 (patch) | |
tree | 22b8c3bf49ad03f90d5371f39498e23c98addc7e /pexpect/fdpexpect.py | |
parent | 17ad1a9f1b5a1115a7b564c35f2ea209d9dfe8df (diff) | |
download | pexpect-bda1a67c294368ce98b4810c3a25cace4df762a0.tar.gz |
cleaned up fdpexpect a bit.
Diffstat (limited to 'pexpect/fdpexpect.py')
-rw-r--r-- | pexpect/fdpexpect.py | 34 |
1 files changed, 21 insertions, 13 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 |