python-streamexpect icon indicating copy to clipboard operation
python-streamexpect copied to clipboard

Provide convenience function to SearcherCollection

Open nastevens opened this issue 9 years ago • 0 comments

Right now accessing SearcherCollection to expect on a list of multiple patterns is clunky:

pat1 = RegexSearcher('pattern 1')
pat2 = RegexSearcher('pattern 2')
search = SearcherCollection([pat1, pat2])
with streamexpect.wrap(buf) as stream:
    match = stream.expect(search)
if match.searcher is pat1:
    # do stuff
else:
    pass

Instead, the expect_regex and expect_text functions could be extended to automatically add a SearcherCollection when they are passed a collection (list, tuple, etc):

pat1 = 'pattern 1'
pat2 = 'pattern 2'
with streamexpect.wrap(buf) as stream:
    match = stream.expect_regex([pat1, pat2])
if match.searcher is pat1:
    # do stuff
else:
    pass

nastevens avatar Jan 21 '16 20:01 nastevens