MCPcopy Create free account
hub / github.com/pyinvoke/invoke / ready_for_reading

Function ready_for_reading

invoke/terminals.py:204–224  ·  view source on GitHub ↗

Test ``input_`` to determine whether a read action will succeed. :param input_: Input stream object (file-like). :returns: ``True`` if a read should succeed, ``False`` otherwise. .. versionadded:: 1.0

(input_: IO)

Source from the content-addressed store, hash-verified

202
203
204def ready_for_reading(input_: IO) -> bool:
205 """
206 Test ``input_`` to determine whether a read action will succeed.
207
208 :param input_: Input stream object (file-like).
209
210 :returns: ``True`` if a read should succeed, ``False`` otherwise.
211
212 .. versionadded:: 1.0
213 """
214 # A "real" terminal stdin needs select/kbhit to tell us when it's ready for
215 # a nonblocking read().
216 # Otherwise, assume a "safer" file-like object that can be read from in a
217 # nonblocking fashion (e.g. a StringIO or regular file).
218 if not has_fileno(input_):
219 return True
220 if sys.platform == "win32":
221 return msvcrt.kbhit()
222 else:
223 reads, _, _ = select.select([input_], [], [], 0.0)
224 return bool(reads and reads[0] is input_)
225
226
227def bytes_to_read(input_: IO) -> int:

Callers 1

read_our_stdinMethod · 0.85

Calls 1

has_filenoFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…