How to use the aioconsole.stream.ainput function in aioconsole

To help you get started, we’ve selected a few aioconsole examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vxgmichel / aioconsole / tests / test_stream.py View on Github external
def test_read_from_closed_pipe():
    stdin_r, stdin_w = os.pipe()
    stdout_r, stdout_w = os.pipe()
    stderr_r, stderr_w = os.pipe()

    stdin = open(stdin_w, 'wb')
    stdin.write(b'hello\n')
    stdin.close()

    reader, writer1, writer2 = yield from create_standard_streams(
        open(stdin_r, 'rb'), open(stdout_w, 'wb'), open(stderr_w, 'rb'))

    result = yield from ainput('>>> ', streams=(reader, writer1))
    assert result == 'hello'

    os.close(stdout_w)
    os.close(stderr_w)

    assert open(stdout_r).read() == '>>> '
    assert open(stderr_r).read() == ''
github vxgmichel / aioconsole / tests / test_stream.py View on Github external
def test_ainput_with_standard_stream(monkeypatch):
    string = 'a\nb\n'
    monkeypatch.setattr('sys.stdin', io.StringIO(string))
    monkeypatch.setattr('sys.stdout', io.StringIO())
    monkeypatch.setattr('sys.stderr', io.StringIO())

    assert (yield from ainput()) == 'a'
    assert (yield from ainput('>>> ')) == 'b'
    assert sys.stdout.getvalue() == '>>> '
    assert sys.stderr.getvalue() == ''
github vxgmichel / aioconsole / tests / test_stream.py View on Github external
def test_ainput_with_standard_stream(monkeypatch):
    string = 'a\nb\n'
    monkeypatch.setattr('sys.stdin', io.StringIO(string))
    monkeypatch.setattr('sys.stdout', io.StringIO())
    monkeypatch.setattr('sys.stderr', io.StringIO())

    assert (yield from ainput()) == 'a'
    assert (yield from ainput('>>> ')) == 'b'
    assert sys.stdout.getvalue() == '>>> '
    assert sys.stderr.getvalue() == ''
github vxgmichel / aioconsole / aioconsole / code.py View on Github external
def ainput(self, prompt='', *, streams=None, use_stderr=False, loop=None):
        # Get the console streams by default
        if streams is None and use_stderr is False:
            streams = self.reader, self.writer
        # Wrap the prompt with prompt control characters
        if self.prompt_control and self.prompt_control not in prompt:
            prompt = self.prompt_control + prompt + self.prompt_control
        # Run ainput
        return (yield from stream.ainput(
            prompt, streams=streams, use_stderr=use_stderr, loop=loop))
github vxgmichel / aioconsole / aioconsole / code.py View on Github external
    @functools.wraps(stream.ainput)
    @asyncio.coroutine
    def ainput(self, prompt='', *, streams=None, use_stderr=False, loop=None):
        # Get the console streams by default
        if streams is None and use_stderr is False:
            streams = self.reader, self.writer
        # Wrap the prompt with prompt control characters
        if self.prompt_control and self.prompt_control not in prompt:
            prompt = self.prompt_control + prompt + self.prompt_control
        # Run ainput
        return (yield from stream.ainput(
            prompt, streams=streams, use_stderr=use_stderr, loop=loop))