Commit a49776ef authored by Benjamin Fischer's avatar Benjamin Fischer
Browse files

[workspace] fixed FileStream implementation

- read&write must only raise EOFError
- read must raise if not all data read
parent a321e645
...@@ -248,6 +248,44 @@ class SSHConnectionImpl(object): ...@@ -248,6 +248,44 @@ class SSHConnectionImpl(object):
""" """
TIMEOUT = 30 TIMEOUT = 30
class FileStream(rpyc.core.stream.Stream):
def __init__(self, file_in, file_out):
self._file_in = file_in
self._file_out = file_out
self._in_buffer_event = threading.Event()
self._file_in.channel.in_buffer.set_event(
self._in_buffer_event)
def close(self):
logger.debug("filestream closed")
def closed(self):
return self._file_out.channel.closed
def read(self, count):
try:
data = self._file_out.read(count)
if len(data) < count:
raise EOFError("read too few bytes: %d < %d" % (len(data), count))
return data
except:
c, i, t = sys.exc_info()
raise EOFError, i.args, t
def write(self, data):
try:
return self._file_in.write(data)
except:
c, i, t = sys.exc_info()
raise EOFError, i.args, t
def fileno(self):
raise NotImplementedError
def poll(self, timeout):
return self._in_buffer_event.wait(timeout)
def __init__(self, command, address, def __init__(self, command, address,
missing_host_key_policy="warning", missing_host_key_policy="warning",
**kwargs): **kwargs):
...@@ -398,34 +436,7 @@ class SSHConnectionImpl(object): ...@@ -398,34 +436,7 @@ class SSHConnectionImpl(object):
self.stdin.write("\n") self.stdin.write("\n")
def stream(self): def stream(self):
class FileStream(rpyc.core.stream.Stream): return self.FileStream(self.stdin, self.stdout)
def __init__(self, file_in, file_out):
self._file_in = file_in
self._file_out = file_out
self._in_buffer_event = threading.Event()
self._file_in.channel.in_buffer.set_event(
self._in_buffer_event)
def close(self):
logger.debug("filestream closed")
def closed(self):
return self._file_out.channel.closed
def read(self, count):
return self._file_out.read(count)
def write(self, data):
return self._file_in.write(data)
def fileno(self):
raise NotImplementedError
def poll(self, timeout):
return self._in_buffer_event.wait(timeout)
return FileStream(self.stdin, self.stdout)
def set_on_feed(self, cb): def set_on_feed(self, cb):
self.stdout.channel.in_buffer.on_feed = cb self.stdout.channel.in_buffer.on_feed = cb
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment