Commits

Amaury Forgeot d'Arc  committed 30f8edd

Various fixes until pyrepl works for pypy3k.

  • Participants
  • Parent commits 8d689f6
  • Branches py3k-readline

Comments (0)

Files changed (4)

File pyrepl/curses.py

 # 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

File pyrepl/reader.py

 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
 
 
         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
 
 
     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
 
     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."""

File pyrepl/unix_console.py

                 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:
 
     if FIONREAD:
         def getpending(self):
-            e = Event('key', '', '')
+            e = Event('key', '', b'')
 
             while not self.event_queue.empty():
                 e2 = self.event_queue.get()
                 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()
                 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
 

File pyrepl/unix_eventqueue.py

     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)