[pypy-commit] pyrepl py3k-readline: Various fixes until pyrepl works for pypy3k.
amauryfa
noreply at buildbot.pypy.org
Sat Sep 15 23:12:13 CEST 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k-readline
Changeset: r199:30f8edda619f
Date: 2012-09-15 23:10 +0200
http://bitbucket.org/pypy/pyrepl/changeset/30f8edda619f/
Log: Various fixes until pyrepl works for pypy3k.
diff --git a/pyrepl/curses.py b/pyrepl/curses.py
--- a/pyrepl/curses.py
+++ b/pyrepl/curses.py
@@ -20,4 +20,16 @@
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-from ._minimal_curses import setupterm, tigetstr, tparm, error
+import imp
+
+try:
+ # Forces import of the builtin module. Seems necessary with PyPy.
+ _curses = imp.init_builtin('_minimal_curses2')
+ if not _curses:
+ raise ImportError
+ setupterm = _curses.setupterm
+ tigetstr = _curses.tigetstr
+ tparm = _curses.tparm
+ error = _curses.error
+except ImportError:
+ from ._minimal_curses import setupterm, tigetstr, tparm, error
diff --git a/pyrepl/reader.py b/pyrepl/reader.py
--- a/pyrepl/reader.py
+++ b/pyrepl/reader.py
@@ -28,23 +28,21 @@
except NameError:
unicode = str
unichr = chr
- basestring = bytes, str
def _make_unctrl_map():
uc_map = {}
- for c in map(unichr, range(256)):
- if unicodedata.category(c)[0] != 'C':
- uc_map[c] = c
- for i in range(32):
- c = unichr(i)
- uc_map[c] = '^' + unichr(ord('A') + i - 1)
- uc_map[b'\t'] = ' ' # display TABs as 4 characters
- uc_map[b'\177'] = unicode('^?')
for i in range(256):
c = unichr(i)
- if c not in uc_map:
- uc_map[c] = unicode('\\%03o') % i
+ if unicodedata.category(c)[0] != 'C':
+ uc_map[i] = c
+ for i in range(32):
+ uc_map[i] = '^' + unichr(ord('A') + i - 1)
+ uc_map[ord(b'\t')] = ' ' # display TABs as 4 characters
+ uc_map[ord(b'\177')] = unicode('^?')
+ for i in range(256):
+ if i not in uc_map:
+ uc_map[i] = unicode('\\%03o') % i
return uc_map
@@ -53,7 +51,7 @@
return u[c]
else:
if unicodedata.category(c).startswith('C'):
- return b'\u%04x' % ord(c)
+ return br'\u%04x' % ord(c)
else:
return c
@@ -521,12 +519,11 @@
def do_cmd(self, cmd):
#print cmd
- if isinstance(cmd[0], basestring):
- #XXX: unify to text
+ if isinstance(cmd[0], str):
cmd = self.commands.get(cmd[0],
commands.invalid_command)(self, *cmd)
elif isinstance(cmd[0], type):
- cmd = cmd[0](self, cmd)
+ cmd = cmd[0](self, *cmd)
else:
return # nothing to do
@@ -617,7 +614,7 @@
def get_buffer(self, encoding=None):
if encoding is None:
encoding = self.console.encoding
- return unicode('').join(self.buffer).encode(self.console.encoding)
+ return self.get_unicode().encode(encoding)
def get_unicode(self):
"""Return the current buffer as a unicode string."""
diff --git a/pyrepl/unix_console.py b/pyrepl/unix_console.py
--- a/pyrepl/unix_console.py
+++ b/pyrepl/unix_console.py
@@ -459,7 +459,7 @@
return int(os.environ["LINES"]), int(os.environ["COLUMNS"])
except KeyError:
height, width = struct.unpack(
- "hhhh", ioctl(self.input_fd, TIOCGWINSZ, "\000"*8))[0:2]
+ "hhhh", ioctl(self.input_fd, TIOCGWINSZ, b"\000"*8))[0:2]
if not height: return 25, 80
return height, width
else:
@@ -521,7 +521,7 @@
if FIONREAD:
def getpending(self):
- e = Event('key', '', '')
+ e = Event('key', '', b'')
while not self.event_queue.empty():
e2 = self.event_queue.get()
@@ -529,14 +529,15 @@
e.raw += e.raw
amount = struct.unpack(
- "i", ioctl(self.input_fd, FIONREAD, "\0\0\0\0"))[0]
- raw = unicode(os.read(self.input_fd, amount), self.encoding, 'replace')
- e.data += raw
+ "i", ioctl(self.input_fd, FIONREAD, b"\0\0\0\0"))[0]
+ raw = os.read(self.input_fd, amount)
+ data = unicode(raw, self.encoding, 'replace')
+ e.data += data
e.raw += raw
return e
else:
def getpending(self):
- e = Event('key', '', '')
+ e = Event('key', '', b'')
while not self.event_queue.empty():
e2 = self.event_queue.get()
@@ -544,8 +545,9 @@
e.raw += e.raw
amount = 10000
- raw = unicode(os.read(self.input_fd, amount), self.encoding, 'replace')
- e.data += raw
+ raw = os.read(self.input_fd, amount)
+ data = unicode(raw, self.encoding, 'replace')
+ e.data += data
e.raw += raw
return e
diff --git a/pyrepl/unix_eventqueue.py b/pyrepl/unix_eventqueue.py
--- a/pyrepl/unix_eventqueue.py
+++ b/pyrepl/unix_eventqueue.py
@@ -91,7 +91,7 @@
def flush_buf(self):
old = self.buf
self.buf = bytearray()
- return old
+ return bytes(old)
def insert(self, event):
trace('added event {event}', event=event)
More information about the pypy-commit
mailing list