Commit dd6265a5 authored by Gero Müller's avatar Gero Müller
Browse files

further codeeditor fixes

parent 9653addf
......@@ -15,8 +15,6 @@ import fcntl
logger = logging.getLogger(__name__)
from vispa.remote.helper import UTF8Reader
def expand(path):
return os.path.expanduser(os.path.expandvars(path))
......@@ -46,7 +44,6 @@ class CodeEditorRpc:
self._abort = True
def _send(self, topic, data=None):
print "topic: ", topic, "send: ", data
vispa.remote.send_topic(
self._topic + "." + topic, window_id=self._window_id, data=data)
......@@ -100,27 +97,21 @@ class CodeEditorRpc:
fcntl.fcntl(errno, fcntl.F_SETFL, fl | os.O_NONBLOCK)
reads = [outno, errno]
print "reads:", reads
while reads and not self._abort:
rs, _, _ = select.select(reads, [], [], 0.1)
print "rs:", reads
for r in rs:
if read_amount >= CodeEditorRpc.BURST_BUFFER:
time.sleep(CodeEditorRpc.BURST_DELAY)
elif r == outno:
data = stdout.read(CodeEditorRpc.MAX_BURST)
print data
if not data:
print "remove out"
reads.remove(outno)
else:
read_amount += len(data)
self._send('stdout', data)
elif r == errno:
data = stderr.read(CodeEditorRpc.MAX_BURST)
print data
if not data:
print "remove err"
reads.remove(errno)
else:
read_amount += len(data)
......@@ -131,7 +122,6 @@ class CodeEditorRpc:
returncode = self._popen.poll()
if returncode is not None:
print "ended"
break
# soft kill
......@@ -161,14 +151,12 @@ class CodeEditorRpc:
else:
read_delay = float(read_burst) / CodeEditorRpc.MAX_RATE
if r == outno:
print "read stdout"
data = stdout.read()
if not data:
reads.remove(outno)
else:
self._send('stdout', data)
elif r == errno:
print "read stderr"
data = stderr.read()
if not data:
reads.remove(errno)
......
def truncated_utf8(utf8_bytes):
""" returns the bytes containing complete and truncated bytes """
if not utf8_bytes:
return b"", b""
# https://en.wikipedia.org/wiki/UTF-8#Description
# last byte is 1 byte code pint
if not utf8_bytes[-1] & 0b10000000:
return utf8_bytes, b""
else:
# find initial code point
for i in [-2, -3, -4]:
if utf8_bytes[i] & 0b11000000:
return utf8_bytes[:i+1], utf8_bytes[i+1:]
raise Exception("invalid utf-8 string")
class UTF8Reader(object):
def __init__(self, f):
self._file = f
self._remainder = None
def read(self, n=-1):
utf8_bytes = self._file.read(n)
if utf8_bytes is None:
return None
if self._remainder:
data, self._remainder = truncated_utf8(self._remainder + utf8_bytes)
else:
data, self._remainder = truncated_utf8(utf8_bytes)
return data
class UTF8Buffer(object):
"""
Buffers incoming UTF8 encoded data, and prevents chunks from being created in the middle of a
......
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