|
43 | 43 | logger = logging.getLogger(__name__)
|
44 | 44 |
|
45 | 45 |
|
| 46 | +class Stdin(object): |
| 47 | + """Stdin stream for a channel. |
| 48 | +
|
| 49 | + Handles EAGAIN. |
| 50 | +
|
| 51 | + Provides ``write`` and ``flush`` only. |
| 52 | + """ |
| 53 | + __slots__ = ('_channel', '_client') |
| 54 | + |
| 55 | + def __init__(self, channel, client): |
| 56 | + """ |
| 57 | + :param channel: The channel the stdin stream is from. |
| 58 | + :type channel: IO object |
| 59 | + :param client: The SSH client the channel is from. |
| 60 | + :type client: ``BaseSSHClient`` |
| 61 | + """ |
| 62 | + self._channel = channel |
| 63 | + self._client = client |
| 64 | + |
| 65 | + def write(self, data): |
| 66 | + """Write to stdin. |
| 67 | +
|
| 68 | + :param data: Data to write. |
| 69 | + :type data: str |
| 70 | + """ |
| 71 | + return self._client._eagain(self._channel.write, data) |
| 72 | + |
| 73 | + def flush(self): |
| 74 | + """Flush pending data written to stdin.""" |
| 75 | + return self._client._eagain(self._channel.flush) |
| 76 | + |
| 77 | + |
46 | 78 | class InteractiveShell(object):
|
47 | 79 | """
|
48 | 80 | Run commands on an interactive shell.
|
@@ -304,9 +336,8 @@ def _make_host_output(self, channel, encoding, read_timeout):
|
304 | 336 | _buffers = HostOutputBuffers(
|
305 | 337 | stdout=BufferData(rw_buffer=_stdout_buffer, reader=_stdout_reader),
|
306 | 338 | stderr=BufferData(rw_buffer=_stderr_buffer, reader=_stderr_reader))
|
307 |
| - stdin = channel |
308 | 339 | host_out = HostOutput(
|
309 |
| - host=self.host, channel=channel, stdin=stdin, |
| 340 | + host=self.host, channel=channel, stdin=Stdin(channel, self), |
310 | 341 | client=self, encoding=encoding, read_timeout=read_timeout,
|
311 | 342 | buffers=_buffers,
|
312 | 343 | )
|
|
0 commit comments