mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
Pexpect: Return the match object instead of the result
The result is just the *index* of the pattern that matched. But since we never pass a *list* it's just always 0. spawn.match is the MatchObject that produced the match, so it can be used to post-process the matched output, e.g. ```python m = expect_re('\d+') m.group() # is now the matched number ```
This commit is contained in:
parent
8f5a84cdc7
commit
04562300e8
1 changed files with 5 additions and 2 deletions
|
@ -182,12 +182,15 @@ class SpawnedProc(object):
|
||||||
On failure, this prints an error and exits.
|
On failure, this prints an error and exits.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
res = self.spawn.expect(pat, **kwargs)
|
self.spawn.expect(pat, **kwargs)
|
||||||
when = self.time_since_first_message()
|
when = self.time_since_first_message()
|
||||||
self.messages.append(
|
self.messages.append(
|
||||||
Message.received_output(self.spawn.match.group(), when)
|
Message.received_output(self.spawn.match.group(), when)
|
||||||
)
|
)
|
||||||
return res
|
# When a match is found,
|
||||||
|
# spawn.match is the MatchObject that produced it.
|
||||||
|
# This can be used to check what exactly was matched.
|
||||||
|
return self.spawn.match
|
||||||
except pexpect.ExceptionPexpect as err:
|
except pexpect.ExceptionPexpect as err:
|
||||||
if not pat_desc:
|
if not pat_desc:
|
||||||
pat_desc = str(pat)
|
pat_desc = str(pat)
|
||||||
|
|
Loading…
Reference in a new issue