summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoah <noah@656d521f-e311-0410-88e0-e7920216d269>2003-02-25 08:52:29 +0000
committernoah <noah@656d521f-e311-0410-88e0-e7920216d269>2003-02-25 08:52:29 +0000
commit66311e2d604ac62d8d931a843de85035378dd76d (patch)
tree912fe2f02e419eab1bb3ccdeeab27b3ffa4ac9c3
parent48b1195b9035bce5ad66767d9c760a03142576ce (diff)
downloadpexpect-66311e2d604ac62d8d931a843de85035378dd76d.tar.gz
Added Chad Schroeder's suggestions for making Pexpect work with generic
file descriptors opened prior to starting spawn. Just pass the fs as the command. The integer will trigger a different contstructor behavior. git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@151 656d521f-e311-0410-88e0-e7920216d269
-rw-r--r--pexpect/Makefile2
-rw-r--r--pexpect/pexpect.py31
-rw-r--r--pexpect/setup.py51
-rwxr-xr-xpexpect/tests/test_expect.py2
4 files changed, 75 insertions, 11 deletions
diff --git a/pexpect/Makefile b/pexpect/Makefile
index 15393c5..2a3220a 100644
--- a/pexpect/Makefile
+++ b/pexpect/Makefile
@@ -1,6 +1,6 @@
SHELL = /bin/sh
-VERSION= 0.96
+VERSION= 0.97
#DOCGENERATOR= happydoc
DOCGENERATOR= pydoc -w
# This is for GNU Make. This does not work on BSD Make.
diff --git a/pexpect/pexpect.py b/pexpect/pexpect.py
index 0d7896a..22898a9 100644
--- a/pexpect/pexpect.py
+++ b/pexpect/pexpect.py
@@ -42,7 +42,7 @@ Currently pexpect is intended for UNIX operating systems (including OS-X)."""
-__version__ = '0.96'
+__version__ = '0.97'
__revision__ = '$Revision$'
__all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn',
'__version__', '__revision__']
@@ -101,9 +101,24 @@ class spawn:
self.before = None
self.after = None
self.match = None
+ self.nofork = None # Don't spawn a child.
self.softspace = 0 # File-like object.
self.name = '' # File-like object.
+ # If command is an int type then it must represent an open file descriptor.
+ if type (command) == type(0):
+ try:
+ os.fstat(command)
+ except OSError:
+ raise ExceptionPexpect, 'Command is an int type, but is not a valid file descriptor.'
+ self.nofork = 1
+ self.pid = -1
+ self.child_fd = command
+ self.args = None
+ self.command = None
+ self.name = '<file descriptor>'
+ return
+
if type (args) != type([]):
raise TypeError, 'The second argument, args, must be a list.'
@@ -116,6 +131,7 @@ class spawn:
self.command = command
self.name = '<' + reduce(lambda x, y: x+' '+y, self.args) + '>'
+ self.nofork = 0
self.__spawn()
def __del__(self):
@@ -388,11 +404,14 @@ class spawn:
I don't want to use signals. Signals on UNIX suck and they
mess up Python pipes (setting SIGCHLD to SIGIGNORE).
"""
+ if (self.pid == -1): ### For attached fd with no pid, this should check fd status.
+ return(1) ### This should really check os.fstat(fd)
+
try:
pid, status = os.waitpid(self.pid, os.WNOHANG)
except OSError, e:
return 0
-
+
# I have to do this twice for Solaris.
# I can't even believe that I figured this out...
try:
@@ -428,7 +447,7 @@ class spawn:
you send the right signal.
"""
# Same as os.kill, but the pid is given for you.
- if self.isalive():
+ if self.isalive() and (not self.nofork):
os.kill(self.pid, sig)
def compile_pattern_list(self, patterns):
@@ -546,6 +565,8 @@ class spawn:
index = -1
for str_target in pattern_list:
index = index + 1
+ if str_target is EOF or str_target is TIMEOUT:
+ continue # The Exception patterns are handled differently.
match_index = incoming.find (str_target)
if match_index >= 0:
self.before = incoming [ : match_index]
@@ -591,8 +612,8 @@ class spawn:
index = -1
for cre in pattern_list:
index = index + 1
- if cre is EOF:
- continue # The EOF pattern is not a regular expression.
+ if cre is EOF or cre is TIMEOUT:
+ continue # The Exception patterns are handled differently.
match = cre.search(incoming)
if match is not None:
self.before = incoming[ : match.start()]
diff --git a/pexpect/setup.py b/pexpect/setup.py
index 3d7b604..cb7592f 100644
--- a/pexpect/setup.py
+++ b/pexpect/setup.py
@@ -4,14 +4,57 @@ $Date$
'''
from distutils.core import setup
setup (name='pexpect',
- version='0.96',
+ version='0.97',
py_modules=['pexpect'],
- description='Pexpect, a pure Python Expect allows control of other applications.',
+ description='Pexpect is a pure Python Expect. It allows easy control of other applications.',
author='Noah Spurrier',
author_email='noah@noah.org',
url='http://pexpect.sourceforge.net/',
license='Python Software Foundation License',
- platforms='UNIX'
- )
+ platforms='UNIX',
+ classifiers = [
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Console',
+ 'Environment :: Console (Text Based)',
+ 'Intended Audience :: Developers',
+ 'Intended Audience :: System Administrators',
+ 'Intended Audience :: Quality Engineers',
+ 'License :: OSI Approved :: Python Software Foundation License',
+ 'Operating System :: POSIX',
+ 'Operating System :: MacOS :: MacOS X',
+ 'Programming Language :: Python',
+ 'Topic :: Software Development',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ 'Topic :: Software Development :: Quality Assurance',
+ 'Topic :: Software Development :: Testing',
+ 'Topic :: System, System :: Archiving :: Packaging, System :: Installation/Setup',
+ 'Topic :: System :: Shells',
+ 'Topic :: System :: Software Distribution',
+ 'Topic :: Terminals, Utilities',
+ ],
+
+)
+
+# classifiers = [
+# 'Development Status :: 4 - Beta',
+# 'Environment :: Console',
+# 'Environment :: Console (Text Based)',
+# 'Intended Audience :: Developers',
+# 'Intended Audience :: System Administrators',
+# 'Intended Audience :: Quality Engineers',
+# 'License :: OSI Approved :: Python Software Foundation License',
+# 'Operating System :: POSIX',
+# 'Operating System :: MacOS :: MacOS X',
+# 'Programming Language :: Python',
+# 'Topic :: Software Development',
+# 'Topic :: Software Development :: Libraries :: Python Modules',
+# 'Topic :: Software Development :: Quality Assurance',
+# 'Topic :: Software Development :: Testing',
+# 'Topic :: System, System :: Archiving :: Packaging, System :: Installation/Setup',
+# 'Topic :: System :: Shells',
+# 'Topic :: System :: Software Distribution',
+# 'Topic :: Terminals, Utilities',
+# ],
+
diff --git a/pexpect/tests/test_expect.py b/pexpect/tests/test_expect.py
index 12d7221..7efed49 100755
--- a/pexpect/tests/test_expect.py
+++ b/pexpect/tests/test_expect.py
@@ -58,7 +58,7 @@ class ExpectTestCase(unittest.TestCase):
def test_expect_timeout (self):
the_old_way = commands.getoutput('ls -l /bin')
- p = pexpect.spawn('ls -l /bin')
+ p = pexpect.spawn('cat')
i = p.expect(pexpect.TIMEOUT)
assert p.after == pexpect.TIMEOUT