Skip to content

Commit

Permalink
Merge branch 'issue-44-solaris-try-2' of git+ssh://github.com/pexpect…
Browse files Browse the repository at this point in the history
…/pexpect into issue-44-solaris-try-2

Conflicts:
	tests/test_misc.py
  • Loading branch information
jquast committed Jun 3, 2014
2 parents 6529f7a + 7927c72 commit 744a18f
Show file tree
Hide file tree
Showing 25 changed files with 113 additions and 50 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ python:
- 3.4
- pypy

#virtualenv:
# system_site_packages: true

before_install:
- sudo apt-get install python-yaml python3-yaml
install:
Expand Down
2 changes: 2 additions & 0 deletions doc/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Version 3.3
``getwinsize()``, ``setwinsize()`` or ``waitnoecho()``, because the master_fd
side of the pty-pair does not appear as a terminal (``isatty()`` returns
False) (:ghissue:`44`).
* Fixed issue where pexpect would attempt to execute a directory because
it has the 'execute' bit set (:ghissue:`37`).

Version 3.2
```````````
Expand Down
7 changes: 5 additions & 2 deletions examples/astat.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@

from __future__ import absolute_import

import os, sys, time, re, getopt, getpass
import pexpect, pxssh
import os
import sys
import getopt
import getpass
import pxssh


try:
Expand Down
3 changes: 1 addition & 2 deletions examples/chess.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from __future__ import absolute_import

import pexpect
import string
import ANSI

REGEX_MOVE = '(?:[a-z]|\x1b\[C)(?:[0-9]|\x1b\[C)(?:[a-z]|\x1b\[C)(?:[0-9]|\x1b\[C)'
Expand Down Expand Up @@ -95,7 +94,7 @@ def set_depth (self, depth):

def quit(self):
self.child.sendline ('quit')
import sys, os
import sys
print('Starting...')
white = Chess()
white.child.echo = 1
Expand Down
4 changes: 2 additions & 2 deletions examples/chess2.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
from __future__ import absolute_import

import pexpect
import string
import ANSI
import sys, os, time
import sys
import time

class Chess:

Expand Down
3 changes: 1 addition & 2 deletions examples/chess3.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from __future__ import absolute_import

import pexpect
import string
import ANSI

REGEX_MOVE = '(?:[a-z]|\x1b\[C)(?:[0-9]|\x1b\[C)(?:[a-z]|\x1b\[C)(?:[0-9]|\x1b\[C)'
Expand Down Expand Up @@ -98,7 +97,7 @@ def set_depth (self, depth):

def quit(self):
self.child.sendline ('quit')
import sys, os
import sys
print('Starting...')
white = Chess()
white.do_move('b2b4')
Expand Down
1 change: 0 additions & 1 deletion examples/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
import os
import re
import optparse
import types
import time
import getpass
import readline
Expand Down
11 changes: 6 additions & 5 deletions pexpect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1999,23 +1999,24 @@ def search(self, buffer, freshlen, searchwindowsize=None):


def which(filename):

'''This takes a given filename; tries to find it in the environment path;
then checks if it is executable. This returns the full path to the filename
if found and executable. Otherwise this returns None.'''

# Special case where filename contains an explicit path.
if os.path.dirname(filename) != '':
if os.access(filename, os.X_OK):
return filename
if (os.path.dirname(filename) != '' and
os.access(filename, os.X_OK) and
os.path.isfile(os.path.realpath(filename))):
return filename
if 'PATH' not in os.environ or os.environ['PATH'] == '':
p = os.defpath
else:
p = os.environ['PATH']
pathlist = p.split(os.pathsep)
for path in pathlist:
ff = os.path.join(path, filename)
if os.access(ff, os.X_OK):
if (os.access(ff, os.X_OK) and
os.path.isfile(os.path.realpath(ff))):
return ff
return None

Expand Down
1 change: 0 additions & 1 deletion tests/depricated_test_filedescriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import pexpect
import unittest
import PexpectTestCase
import sys
import os

class ExpectTestCase(PexpectTestCase.PexpectTestCase):
Expand Down
4 changes: 3 additions & 1 deletion tests/echo_wait.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
'''
import signal, time, struct, fcntl, termios, os, sys
import time
import termios
import sys

# a dumb PAM will print the password prompt first then set ECHO
# False. What it should do it set ECHO False first then print the
Expand Down
4 changes: 3 additions & 1 deletion tests/pexpectTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
'''

import os, time, pexpect, sys
import time
import pexpect
import sys

def getProcessResults(cmd, timeLimit=20):
'''
Expand Down
11 changes: 1 addition & 10 deletions tests/platform_tests/pexqa.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import os, sys
import select
import signal
import traceback
import os
import time
import re
import struct
from types import *
import posix

import pty
import tty
import termios
import fcntl
class s:
def __init__(self, command, args=None, timeout=30):

Expand Down
5 changes: 4 additions & 1 deletion tests/platform_tests/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env python
import signal, os, time, errno, pty
import signal
import os
import time
import pty

def signal_handler (signum, frame):
print 'Signal handler called with signal:', signum
Expand Down
4 changes: 3 additions & 1 deletion tests/platform_tests/test2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python
import signal, os, time, errno
import signal
import os
import time

def signal_handler (signum, frame):
print 'Signal handler called with signal:', signum
Expand Down
8 changes: 7 additions & 1 deletion tests/platform_tests/test_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env python
import signal, os, time, errno, pty, sys, fcntl, tty
import signal
import os
import time
import pty
import sys
import fcntl
import tty
GLOBAL_SIGCHLD_RECEIVED = 0

def nonblock (fd):
Expand Down
2 changes: 1 addition & 1 deletion tests/platform_tests/test_read.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, sys
import os

filename = os.tmpnam()
print 'filename:', filename
Expand Down
6 changes: 5 additions & 1 deletion tests/platform_tests/test_signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env python
import signal, os, time, errno, pty, sys
import signal
import os
import time
import pty
import sys
GLOBAL_SIGCHLD_RECEIVED = 0

def signal_handler (signum, frame):
Expand Down
1 change: 0 additions & 1 deletion tests/test_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
'''
import pexpect
import unittest
import time
import PexpectTestCase

class TestCaseConstructor(PexpectTestCase.PexpectTestCase):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_isalive.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import pexpect
import unittest
import signal
import sys, os, time
import sys
import time
import PexpectTestCase

class IsAliveTestCase(PexpectTestCase.PexpectTestCase):
Expand Down
61 changes: 61 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import PexpectTestCase
import os
import sys
import tempfile
import re
import signal
import time
Expand Down Expand Up @@ -258,6 +259,66 @@ def test_cwd (self): # This assumes 'pwd' and '/tmp' exist on this platform.
assert default!=tmpdir, "'default' and 'tmpdir' should be different"
assert (b'tmp' in tmpdir), "'tmp' should be returned by 'pwd' command"

def test_basic_which(self):
# should find at least 'ls' program, and it should begin with '/'
exercise = pexpect.which("ls")
assert exercise is not None and exercise.startswith('/')

def test_absolute_which(self):
# make up a path and insert first a non-executable,
# then, make it executable, and assert we may which() find it.
fname = 'gcc'
bin_dir = tempfile.mkdtemp()
bin_path = os.path.join(bin_dir, fname)
save_path = os.environ['PATH']
try:
# setup
os.environ['PATH'] = bin_dir
with open(bin_path, 'w') as fp:
fp.write('#!/bin/sh\necho hello, world\n')
os.chmod(bin_path, 0o400)

# it should not be found because it is not executable
assert pexpect.which(fname) is None, fname

# but now it should -- because it is executable
os.chmod(bin_path, 0o700)
assert pexpect.which(fname) == bin_path, (fname, bin_path)

finally:
# restore,
os.environ['PATH'] = save_path
# destroy scratch files and folders,
if os.path.exists(bin_path):
os.unlink(bin_path)
if os.path.exists(bin_dir):
os.rmdir(bin_dir)

def test_which_should_not_match_folders(self):
# make up a path and insert a folder, which is 'executable', which
# a naive implementation might match (previously pexpect versions
# 3.2 and sh versions 1.0.8, reported by @lcm337.)
fname = 'g++'
bin_dir = tempfile.mkdtemp()
bin_dir2 = os.path.join(bin_dir, fname)
save_path = os.environ['PATH']
try:
os.environ['PATH'] = bin_dir
os.mkdir(bin_dir2, 0o755)
# it should not be found because it is not executable *file*,
# but rather, has the executable bit set, as a good folder
# should -- it shouldn't be returned because it fails isdir()
exercise = pexpect.which(fname)
assert exercise is None, exercise

finally:
# restore,
os.environ['PATH'] = save_path
# destroy scratch folders,
for _dir in (bin_dir2, bin_dir,):
if os.path.exists(_dir):
os.rmdir(_dir)

def test_which (self):
p = os.defpath
ep = os.environ['PATH']
Expand Down
2 changes: 0 additions & 2 deletions tests/test_replwrap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import re
import os
import sys
import unittest

import pexpect
Expand Down
9 changes: 2 additions & 7 deletions tools/merge_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,9 @@
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
'''
import sys, os, re
import os
import re
import pyed
try:
import pexpect
except:
# this happens if Pexpect was never installed to begin with.
sys.path.insert(0, '.')
import pexpect

# extract the version number from the pexpect.py source.
d = pyed.pyed()
Expand Down
1 change: 0 additions & 1 deletion tools/testsweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"""
import pexpect
import sys
import getpass

def test_platform (platform_menu, platform_python_path):
Expand Down
3 changes: 2 additions & 1 deletion tools/tweak_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
'''

import pyed
import sys, os, re
import os
import re

# extract the version number from the pexpect.py source.
d = pyed.pyed()
Expand Down
4 changes: 2 additions & 2 deletions tools/websync.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
'''

import pexpect, pyed
import pexpect
import getpass
import sys, os
import sys

X = getpass.getpass('Password: ')
pp_pattern=["(?i)password:", "(?i)enter passphrase for key '.*?':"]
Expand Down

0 comments on commit 744a18f

Please sign in to comment.