diff options
author | Ivan Blinkov <ivan@blinkov.ru> | 2022-02-10 16:47:10 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:10 +0300 |
commit | 1aeb9a455974457866f78722ad98114bafc84e8a (patch) | |
tree | e4340eaf1668684d83a0a58c36947c5def5350ad /contrib/python/prompt-toolkit/py2/prompt_toolkit/input.py | |
parent | bd5ef432f5cfb1e18851381329d94665a4c22470 (diff) | |
download | ydb-1aeb9a455974457866f78722ad98114bafc84e8a.tar.gz |
Restoring authorship annotation for Ivan Blinkov <ivan@blinkov.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/prompt-toolkit/py2/prompt_toolkit/input.py')
-rw-r--r-- | contrib/python/prompt-toolkit/py2/prompt_toolkit/input.py | 214 |
1 files changed, 107 insertions, 107 deletions
diff --git a/contrib/python/prompt-toolkit/py2/prompt_toolkit/input.py b/contrib/python/prompt-toolkit/py2/prompt_toolkit/input.py index f123732560..ad6d4cf696 100644 --- a/contrib/python/prompt-toolkit/py2/prompt_toolkit/input.py +++ b/contrib/python/prompt-toolkit/py2/prompt_toolkit/input.py @@ -1,68 +1,68 @@ -""" -Abstraction of CLI Input. -""" -from __future__ import unicode_literals - -from .utils import DummyContext, is_windows -from abc import ABCMeta, abstractmethod -from six import with_metaclass - +""" +Abstraction of CLI Input. +""" +from __future__ import unicode_literals + +from .utils import DummyContext, is_windows +from abc import ABCMeta, abstractmethod +from six import with_metaclass + import io -import os -import sys - -if is_windows(): - from .terminal.win32_input import raw_mode, cooked_mode -else: - from .terminal.vt100_input import raw_mode, cooked_mode - -__all__ = ( - 'Input', - 'StdinInput', - 'PipeInput', -) - - -class Input(with_metaclass(ABCMeta, object)): - """ - Abstraction for any input. - - An instance of this class can be given to the constructor of a - :class:`~prompt_toolkit.interface.CommandLineInterface` and will also be - passed to the :class:`~prompt_toolkit.eventloop.base.EventLoop`. - """ - @abstractmethod - def fileno(self): - """ - Fileno for putting this in an event loop. - """ - - @abstractmethod - def read(self): - """ - Return text from the input. - """ - - @abstractmethod - def raw_mode(self): - """ - Context manager that turns the input into raw mode. - """ - - @abstractmethod - def cooked_mode(self): - """ - Context manager that turns the input into cooked mode. - """ - - -class StdinInput(Input): - """ - Simple wrapper around stdin. - """ - def __init__(self, stdin=None): - self.stdin = stdin or sys.stdin - +import os +import sys + +if is_windows(): + from .terminal.win32_input import raw_mode, cooked_mode +else: + from .terminal.vt100_input import raw_mode, cooked_mode + +__all__ = ( + 'Input', + 'StdinInput', + 'PipeInput', +) + + +class Input(with_metaclass(ABCMeta, object)): + """ + Abstraction for any input. + + An instance of this class can be given to the constructor of a + :class:`~prompt_toolkit.interface.CommandLineInterface` and will also be + passed to the :class:`~prompt_toolkit.eventloop.base.EventLoop`. + """ + @abstractmethod + def fileno(self): + """ + Fileno for putting this in an event loop. + """ + + @abstractmethod + def read(self): + """ + Return text from the input. + """ + + @abstractmethod + def raw_mode(self): + """ + Context manager that turns the input into raw mode. + """ + + @abstractmethod + def cooked_mode(self): + """ + Context manager that turns the input into cooked mode. + """ + + +class StdinInput(Input): + """ + Simple wrapper around stdin. + """ + def __init__(self, stdin=None): + self.stdin = stdin or sys.stdin + # The input object should be a TTY. assert self.stdin.isatty() @@ -78,54 +78,54 @@ class StdinInput(Input): else: raise io.UnsupportedOperation('Stdin is not a terminal.') - def __repr__(self): - return 'StdinInput(stdin=%r)' % (self.stdin,) - - def raw_mode(self): - return raw_mode(self.stdin.fileno()) - - def cooked_mode(self): - return cooked_mode(self.stdin.fileno()) - - def fileno(self): - return self.stdin.fileno() - - def read(self): - return self.stdin.read() - - -class PipeInput(Input): - """ - Input that is send through a pipe. - This is useful if we want to send the input programatically into the - interface, but still use the eventloop. - - Usage:: - - input = PipeInput() - input.send('inputdata') - """ - def __init__(self): - self._r, self._w = os.pipe() - - def fileno(self): - return self._r - - def read(self): - return os.read(self._r) - + def __repr__(self): + return 'StdinInput(stdin=%r)' % (self.stdin,) + + def raw_mode(self): + return raw_mode(self.stdin.fileno()) + + def cooked_mode(self): + return cooked_mode(self.stdin.fileno()) + + def fileno(self): + return self.stdin.fileno() + + def read(self): + return self.stdin.read() + + +class PipeInput(Input): + """ + Input that is send through a pipe. + This is useful if we want to send the input programatically into the + interface, but still use the eventloop. + + Usage:: + + input = PipeInput() + input.send('inputdata') + """ + def __init__(self): + self._r, self._w = os.pipe() + + def fileno(self): + return self._r + + def read(self): + return os.read(self._r) + def send_text(self, data): " Send text to the input. " - os.write(self._w, data.encode('utf-8')) - + os.write(self._w, data.encode('utf-8')) + # Deprecated alias for `send_text`. send = send_text - def raw_mode(self): - return DummyContext() - - def cooked_mode(self): - return DummyContext() + def raw_mode(self): + return DummyContext() + + def cooked_mode(self): + return DummyContext() def close(self): " Close pipe fds. " |