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

Method read_nonblocking

pexpect/spawnbase.py:170–193  ·  view source on GitHub ↗

This reads data from the file descriptor. This is a simple implementation suitable for a regular file. Subclasses using ptys or pipes should override it. The timeout parameter is ignored.

(self, size=1, timeout=None)

Source from the content-addressed store, hash-verified

168 buffer = property(_get_buffer, _set_buffer)
169
170 def read_nonblocking(self, size=1, timeout=None):
171 """This reads data from the file descriptor.
172
173 This is a simple implementation suitable for a regular file. Subclasses using ptys or pipes should override it.
174
175 The timeout parameter is ignored.
176 """
177
178 try:
179 s = os.read(self.child_fd, size)
180 except OSError as err:
181 if err.args[0] == errno.EIO:
182 # Linux-style EOF
183 self.flag_eof = True
184 raise EOF('End Of File (EOF). Exception style platform.')
185 raise
186 if s == b'':
187 # BSD-style EOF
188 self.flag_eof = True
189 raise EOF('End Of File (EOF). Empty string style platform.')
190
191 s = self._decoder.decode(s, final=False)
192 self._log(s, 'read')
193 return s
194
195 def _pattern_type_err(self, pattern):
196 raise TypeError('got {badtype} ({badobj!r}) as pattern, must be one'

Callers

nothing calls this directly

Calls 4

_logMethod · 0.95
EOFClass · 0.85
readMethod · 0.80
decodeMethod · 0.80

Tested by

no test coverage detected