MCPcopy Create free account
hub / github.com/pexpect/pexpect / expect_loop

Method expect_loop

pexpect/expect.py:153–184  ·  view source on GitHub ↗

Blocking expect

(self, timeout=-1)

Source from the content-addressed store, hash-verified

151 spawn.match_index = None
152
153 def expect_loop(self, timeout=-1):
154 """Blocking expect"""
155 spawn = self.spawn
156
157 if timeout is not None:
158 end_time = time.time() + timeout
159
160 try:
161 idx = self.existing_data()
162 if idx is not None:
163 return idx
164 while True:
165 # No match at this point
166 if (timeout is not None) and (timeout < 0):
167 return self.timeout()
168 # Still have time left, so read more data
169 incoming = spawn.read_nonblocking(spawn.maxread, timeout)
170 if self.spawn.delayafterread is not None:
171 time.sleep(self.spawn.delayafterread)
172 idx = self.new_data(incoming)
173 # Keep reading until exception or return.
174 if idx is not None:
175 return idx
176 if timeout is not None:
177 timeout = end_time - time.time()
178 except EOF as e:
179 return self.eof(e)
180 except TIMEOUT as e:
181 return self.timeout(e)
182 except:
183 self.errored()
184 raise
185
186
187class searcher_string(object):

Callers 3

expect_listMethod · 0.95
expect_exactMethod · 0.95
expect_loopMethod · 0.95

Calls 6

existing_dataMethod · 0.95
timeoutMethod · 0.95
new_dataMethod · 0.95
eofMethod · 0.95
erroredMethod · 0.95
read_nonblockingMethod · 0.45

Tested by

no test coverage detected