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

Function has_fileno

invoke/util.py:73–94  ·  view source on GitHub ↗

Cleanly determine whether ``stream`` has a useful ``.fileno()``. .. note:: This function helps determine if a given file-like object can be used with various terminal-oriented modules and functions such as `select`, `termios`, and `tty`. For most of those, a fileno

(stream: IO)

Source from the content-addressed store, hash-verified

71
72
73def has_fileno(stream: IO) -> bool:
74 """
75 Cleanly determine whether ``stream`` has a useful ``.fileno()``.
76
77 .. note::
78 This function helps determine if a given file-like object can be used
79 with various terminal-oriented modules and functions such as `select`,
80 `termios`, and `tty`. For most of those, a fileno is all that is
81 required; they'll function even if ``stream.isatty()`` is ``False``.
82
83 :param stream: A file-like object.
84
85 :returns:
86 ``True`` if ``stream.fileno()`` returns an integer, ``False`` otherwise
87 (this includes when ``stream`` lacks a ``fileno`` method).
88
89 .. versionadded:: 1.0
90 """
91 try:
92 return isinstance(stream.fileno(), int)
93 except (AttributeError, io.UnsupportedOperation):
94 return False
95
96
97def isatty(stream: IO) -> Union[bool, Any]:

Callers 5

should_use_ptyMethod · 0.85
isattyFunction · 0.85
ready_for_readingFunction · 0.85
bytes_to_readFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…