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

Function bytes_to_read

invoke/terminals.py:227–248  ·  view source on GitHub ↗

Query stream ``input_`` to see how many bytes may be readable. .. note:: If we are unable to tell (e.g. if ``input_`` isn't a true file descriptor or isn't a valid TTY) we fall back to suggesting reading 1 byte only. :param input: Input stream object (file-like

(input_: IO)

Source from the content-addressed store, hash-verified

225
226
227def bytes_to_read(input_: IO) -> int:
228 """
229 Query stream ``input_`` to see how many bytes may be readable.
230
231 .. note::
232 If we are unable to tell (e.g. if ``input_`` isn't a true file
233 descriptor or isn't a valid TTY) we fall back to suggesting reading 1
234 byte only.
235
236 :param input: Input stream object (file-like).
237
238 :returns: `int` number of bytes to read.
239
240 .. versionadded:: 1.0
241 """
242 # NOTE: we have to check both possibilities here; situations exist where
243 # it's not a tty but has a fileno, or vice versa; neither is typically
244 # going to work re: ioctl().
245 if not WINDOWS and isatty(input_) and has_fileno(input_):
246 fionread = fcntl.ioctl(input_, termios.FIONREAD, b" ")
247 return int(struct.unpack("h", fionread)[0])
248 return 1

Calls 2

isattyFunction · 0.85
has_filenoFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…