summaryrefslogtreecommitdiff
path: root/pexpect/spawnbase.py
diff options
context:
space:
mode:
authorThomas Kluyver <thomas@kluyver.me.uk>2017-07-19 15:05:01 +0100
committerThomas Kluyver <thomas@kluyver.me.uk>2017-07-19 15:05:01 +0100
commit1eeddba2ef433cb23cefe8adc064f13a4b9265fa (patch)
tree7f00c84456dcfe8ff326e17194f16006d449ff59 /pexpect/spawnbase.py
parent94f91bd8c56f5e277a9859129ee9260658fd170a (diff)
downloadpexpect-git-1eeddba2ef433cb23cefe8adc064f13a4b9265fa.tar.gz
Rename async= parameter to async_=
Closes gh-315
Diffstat (limited to 'pexpect/spawnbase.py')
-rw-r--r--pexpect/spawnbase.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/pexpect/spawnbase.py b/pexpect/spawnbase.py
index cb64582..11e40f5 100644
--- a/pexpect/spawnbase.py
+++ b/pexpect/spawnbase.py
@@ -223,7 +223,7 @@ class SpawnBase(object):
self._pattern_type_err(p)
return compiled_pattern_list
- def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
+ def expect(self, pattern, timeout=-1, searchwindowsize=-1, async_=False, **kw):
'''This seeks through the stream until a pattern is matched. The
pattern is overloaded and may take several types. The pattern can be a
StringType, EOF, a compiled re, or a list of any of those types.
@@ -307,7 +307,7 @@ class SpawnBase(object):
If you are trying to optimize for speed then see expect_list().
On Python 3.4, or Python 3.3 with asyncio installed, passing
- ``async=True`` will make this return an :mod:`asyncio` coroutine,
+ ``async_=True`` will make this return an :mod:`asyncio` coroutine,
which you can yield from to get the same result that this method would
normally give directly. So, inside a coroutine, you can replace this code::
@@ -315,15 +315,19 @@ class SpawnBase(object):
With this non-blocking form::
- index = yield from p.expect(patterns, async=True)
+ index = yield from p.expect(patterns, async_=True)
'''
+ if 'async' in kw:
+ async_ = kw.pop('async')
+ if kw:
+ raise TypeError("Unknown keyword arguments: {}".format(kw))
compiled_pattern_list = self.compile_pattern_list(pattern)
return self.expect_list(compiled_pattern_list,
- timeout, searchwindowsize, async)
+ timeout, searchwindowsize, async_)
def expect_list(self, pattern_list, timeout=-1, searchwindowsize=-1,
- async=False):
+ async_=False, **kw):
'''This takes a list of compiled regular expressions and returns the
index into the pattern_list that matched the child output. The list may
also contain EOF or TIMEOUT(which are not compiled regular
@@ -333,21 +337,25 @@ class SpawnBase(object):
the expect() method. This is called by expect().
- Like :meth:`expect`, passing ``async=True`` will make this return an
+ Like :meth:`expect`, passing ``async_=True`` will make this return an
asyncio coroutine.
'''
if timeout == -1:
timeout = self.timeout
+ if 'async' in kw:
+ async_ = kw.pop('async')
+ if kw:
+ raise TypeError("Unknown keyword arguments: {}".format(kw))
exp = Expecter(self, searcher_re(pattern_list), searchwindowsize)
- if async:
+ if async_:
from .async import expect_async
return expect_async(exp, timeout)
else:
return exp.expect_loop(timeout)
def expect_exact(self, pattern_list, timeout=-1, searchwindowsize=-1,
- async=False):
+ async_=False, **kw):
'''This is similar to expect(), but uses plain string matching instead
of compiled regular expressions in 'pattern_list'. The 'pattern_list'
@@ -361,11 +369,15 @@ class SpawnBase(object):
This method is also useful when you don't want to have to worry about
escaping regular expression characters that you want to match.
- Like :meth:`expect`, passing ``async=True`` will make this return an
+ Like :meth:`expect`, passing ``async_=True`` will make this return an
asyncio coroutine.
'''
if timeout == -1:
timeout = self.timeout
+ if 'async' in kw:
+ async_ = kw.pop('async')
+ if kw:
+ raise TypeError("Unknown keyword arguments: {}".format(kw))
if (isinstance(pattern_list, self.allowed_string_types) or
pattern_list in (TIMEOUT, EOF)):
@@ -385,7 +397,7 @@ class SpawnBase(object):
pattern_list = [prepare_pattern(p) for p in pattern_list]
exp = Expecter(self, searcher_string(pattern_list), searchwindowsize)
- if async:
+ if async_:
from .async import expect_async
return expect_async(exp, timeout)
else: