summaryrefslogtreecommitdiff
path: root/pexpect
diff options
context:
space:
mode:
authorJeff Quast <contact@jeffquast.com>2015-09-22 12:42:24 -0700
committerJeff Quast <contact@jeffquast.com>2015-09-22 12:42:24 -0700
commit3c1bc018218b86177e1cdf8e93ead035afacc421 (patch)
tree7c928ee4ad19c6c9610849f5f3b4bde7b5e8d4c4 /pexpect
parentae480683db601dc162ab2d02643ff84e1c3786be (diff)
parentea586fb9a545854f9b1212779653ec80f3428a2c (diff)
downloadpexpect-default-handle-sighup-pull.tar.gz
Merge remote-tracking branch 'origin/master' into default-handle-sighupdefault-handle-sighup-pull
Diffstat (limited to 'pexpect')
-rw-r--r--pexpect/pty_spawn.py20
-rw-r--r--pexpect/spawnbase.py10
2 files changed, 23 insertions, 7 deletions
diff --git a/pexpect/pty_spawn.py b/pexpect/pty_spawn.py
index 1eeceec..7280a01 100644
--- a/pexpect/pty_spawn.py
+++ b/pexpect/pty_spawn.py
@@ -37,7 +37,7 @@ class spawn(SpawnBase):
def __init__(self, command, args=[], timeout=30, maxread=2000,
searchwindowsize=None, logfile=None, cwd=None, env=None,
ignore_sighup=False, echo=True, preexec_fn=None,
- encoding=None, codec_errors='strict'):
+ encoding=None, codec_errors='strict', dimensions=None):
'''This is the constructor. The command parameter may be a string that
includes a command and any arguments to the command. For example::
@@ -85,6 +85,13 @@ class spawn(SpawnBase):
:meth:`~.expect` returns, the full buffer attribute remains up to
size *maxread* irrespective of *searchwindowsize* value.
+ When the keyword argument ``timeout`` is specified as a number,
+ (default: *30*), then :class:`TIMEOUT` will be raised after the value
+ specified has elapsed, in seconds, for any of the :meth:`~.expect`
+ family of method calls. When None, TIMEOUT will not be raised, and
+ :meth:`~.expect` may block indefinitely until match.
+
+
The logfile member turns on or off logging. All input and output will
be copied to the given file object. Set logfile to None to stop
logging. This is the default. Set logfile to sys.stdout to echo
@@ -166,6 +173,10 @@ class spawn(SpawnBase):
If preexec_fn is given, it will be called in the child process before
launching the given command. This is useful to e.g. reset inherited
signal handlers.
+
+ The dimensions attribute specifies the size of the pseudo-terminal as
+ seen by the subprocess, and is specified as a two-entry tuple (rows,
+ columns). If this is unspecified, the defaults in ptyprocess will apply.
'''
super(spawn, self).__init__(timeout=timeout, maxread=maxread, searchwindowsize=searchwindowsize,
logfile=logfile, encoding=encoding, codec_errors=codec_errors)
@@ -182,7 +193,7 @@ class spawn(SpawnBase):
self.args = None
self.name = '<pexpect factory incomplete>'
else:
- self._spawn(command, args, preexec_fn)
+ self._spawn(command, args, preexec_fn, dimensions)
def __str__(self):
'''This returns a human-readable string that represents the state of
@@ -218,7 +229,7 @@ class spawn(SpawnBase):
s.append('delayafterterminate: ' + str(self.delayafterterminate))
return '\n'.join(s)
- def _spawn(self, command, args=[], preexec_fn=None):
+ def _spawn(self, command, args=[], preexec_fn=None, dimensions=None):
'''This starts the given command in a child process. This does all the
fork/exec type of stuff for a pty. This is called by __init__. If args
is empty then command will be parsed (split on spaces) and args will be
@@ -273,6 +284,9 @@ class spawn(SpawnBase):
preexec_fn()
kwargs['preexec_fn'] = preexec_wrapper
+ if dimensions is not None:
+ kwargs['dimensions'] = dimensions
+
self.ptyproc = ptyprocess.PtyProcess.spawn(self.args, env=self.env,
cwd=self.cwd, **kwargs)
diff --git a/pexpect/spawnbase.py b/pexpect/spawnbase.py
index aa7ef86..0518d83 100644
--- a/pexpect/spawnbase.py
+++ b/pexpect/spawnbase.py
@@ -251,7 +251,10 @@ class SpawnBase(object):
*before* is all data received up to the exception, while *match* and
*after* attributes are value None.
- If timeout is -1 then timeout will be set to the self.timeout value.
+ When the keyword argument timeout is -1 (default), then TIMEOUT will
+ raise after the default value specified by the class timeout
+ attribute. When None, TIMEOUT will not be raised and may block
+ indefinitely until match.
When the keyword argument searchwindowsize is -1 (default), then the
value specified by the class maxread attribute is used.
@@ -319,9 +322,8 @@ class SpawnBase(object):
expressions). This method is similar to the expect() method except that
expect_list() does not recompile the pattern list on every call. This
may help if you are trying to optimize for speed, otherwise just use
- the expect() method. This is called by expect(). If timeout==-1 then
- the self.timeout value is used. If searchwindowsize==-1 then the
- self.searchwindowsize value is used.
+ the expect() method. This is called by expect().
+
Like :meth:`expect`, passing ``async=True`` will make this return an
asyncio coroutine.