本文整理匯總了Python中typing.TextIO.fileno方法的典型用法代碼示例。如果您正苦於以下問題:Python TextIO.fileno方法的具體用法?Python TextIO.fileno怎麽用?Python TextIO.fileno使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類typing.TextIO
的用法示例。
在下文中一共展示了TextIO.fileno方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: from_pty
# 需要導入模塊: from typing import TextIO [as 別名]
# 或者: from typing.TextIO import fileno [as 別名]
def from_pty(cls, stdout: TextIO, term: Optional[str] = None) -> 'Vt100_Output':
"""
Create an Output class from a pseudo terminal.
(This will take the dimensions by reading the pseudo
terminal attributes.)
"""
# Normally, this requires a real TTY device, but people instantiate
# this class often during unit tests as well. For convenience, we print
# an error message, use standard dimensions, and go on.
isatty = stdout.isatty()
fd = stdout.fileno()
if not isatty and fd not in cls._fds_not_a_terminal:
msg = 'Warning: Output is not to a terminal (fd=%r).\n'
sys.stderr.write(msg % fd)
cls._fds_not_a_terminal.add(fd)
def get_size() -> Size:
# If terminal (incorrectly) reports its size as 0, pick a
# reasonable default. See
# https://github.com/ipython/ipython/issues/10071
rows, columns = (None, None)
if isatty:
rows, columns = _get_size(stdout.fileno())
return Size(rows=rows or 24, columns=columns or 80)
return cls(stdout, get_size, term=term)
示例2: __init__
# 需要導入模塊: from typing import TextIO [as 別名]
# 或者: from typing.TextIO import fileno [as 別名]
def __init__(self, stdin: TextIO) -> None:
# Test whether the given input object has a file descriptor.
# (Idle reports stdin to be a TTY, but fileno() is not implemented.)
try:
# This should not raise, but can return 0.
stdin.fileno()
except io.UnsupportedOperation:
if 'idlelib.run' in sys.modules:
raise io.UnsupportedOperation(
'Stdin is not a terminal. Running from Idle is not supported.')
else:
raise io.UnsupportedOperation('Stdin is not a terminal.')
# Even when we have a file descriptor, it doesn't mean it's a TTY.
# Normally, this requires a real TTY device, but people instantiate
# this class often during unit tests as well. They use for instance
# pexpect to pipe data into an application. For convenience, we print
# an error message and go on.
isatty = stdin.isatty()
fd = stdin.fileno()
if not isatty and fd not in Vt100Input._fds_not_a_terminal:
msg = 'Warning: Input is not to a terminal (fd=%r).\n'
sys.stderr.write(msg % fd)
Vt100Input._fds_not_a_terminal.add(fd)
#
self.stdin = stdin
# Create a backup of the fileno(). We want this to work even if the
# underlying file is closed, so that `typeahead_hash()` keeps working.
self._fileno = stdin.fileno()
self._buffer: List[KeyPress] = [] # Buffer to collect the Key objects.
self.stdin_reader = PosixStdinReader(self._fileno)
self.vt100_parser = Vt100Parser(
lambda key_press: self._buffer.append(key_press))