Author: Ronny Pfannschmidt <[email protected]>
Branch:
Changeset: r181:62bb9c81ed12
Date: 2012-05-03 11:17 +0200
http://bitbucket.org/pypy/pyrepl/changeset/62bb9c81ed12/
Log: move partial char handling to eventqueue
diff --git a/pyrepl/unix_console.py b/pyrepl/unix_console.py
--- a/pyrepl/unix_console.py
+++ b/pyrepl/unix_console.py
@@ -163,8 +163,7 @@
self.__move = self.__move_short
- self.event_queue = EventQueue(self.input_fd)
- self.partial_char = b''
+ self.event_queue = EventQueue(self.input_fd, self.encoding)
self.cursor_visible = 1
def change_encoding(self, encoding):
@@ -402,23 +401,7 @@
def push_char(self, char):
trace('push char {char!r}', char=char)
- self.partial_char += char
- try:
- c = self.partial_char.decode(self.encoding)
- except UnicodeError as e:
- if len(e.args) > 4 and \
- e.args[4] == 'unexpected end of data':
- pass
- else:
- # was: "raise". But it crashes pyrepl, and by extension the
- # pypy currently running, in which we are e.g. in the middle
- # of some debugging session. Argh. Instead just print an
- # error message to stderr and continue running, for now.
- self.partial_char = ''
- sys.stderr.write('\n%s: %s\n' % (e.__class__.__name__, e))
- else:
- self.partial_char = b''
- self.event_queue.push(c)
+ self.event_queue.push(char)
def get_event(self, block=1):
while self.event_queue.empty():
diff --git a/pyrepl/unix_eventqueue.py b/pyrepl/unix_eventqueue.py
--- a/pyrepl/unix_eventqueue.py
+++ b/pyrepl/unix_eventqueue.py
@@ -52,7 +52,7 @@
}
class EventQueue(object):
- def __init__(self, fd):
+ def __init__(self, fd, encoding):
our_keycodes = {}
for key, tiname in _keynames.items():
keycode = curses.tigetstr(tiname)
@@ -63,27 +63,39 @@
self.k = self.ck = keymap.compile_keymap(our_keycodes)
self.events = []
self.buf = []
+ self.encoding=encoding
+
def get(self):
if self.events:
return self.events.pop(0)
else:
return None
+
def empty(self):
return not self.events
+
+ def flush_buf(self):
+ raw = b''.join(self.buf)
+ self.buf = []
+ return raw
+
def insert(self, event):
self.events.append(event)
+
def push(self, char):
if char in self.k:
k = self.k[char]
+ self.buf.append(char)
if isinstance(k, dict):
- self.buf.append(char)
self.k = k
else:
- self.events.append(Event('key', k, ''.join(self.buf) + char))
- self.buf = []
+ self.events.append(Event('key', k, self.flush_buf()))
self.k = self.ck
elif self.buf:
- self.events.extend([Event('key', c, c) for c in self.buf])
+ keys = self.flush_buf()
+ decoded = keys.decode(self.encoding, 'ignore') # XXX surogate?
+ #XXX: incorrect
+ self.events.extend(Event('key', c, c) for c in decoded)
self.buf = []
self.k = self.ck
self.push(char)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit