[pypy-commit] pypy py3k: Fix the _curses module to work with Python3.

amauryfa noreply at buildbot.pypy.org
Thu Apr 23 23:26:55 CEST 2015


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r76908:105de1f4b6b3
Date: 2015-04-23 23:24 +0200
http://bitbucket.org/pypy/pypy/changeset/105de1f4b6b3/

Log:	Fix the _curses module to work with Python3.

	Also fix test_curses which is still in CPython3.2... Apply fix from
	CPython issue20358.

diff --git a/lib-python/3/test/test_curses.py b/lib-python/3/test/test_curses.py
--- a/lib-python/3/test/test_curses.py
+++ b/lib-python/3/test/test_curses.py
@@ -115,8 +115,8 @@
     stdscr.notimeout(1)
     win2.overlay(win)
     win2.overwrite(win)
-    win2.overlay(win, 1, 2, 3, 3, 2, 1)
-    win2.overwrite(win, 1, 2, 3, 3, 2, 1)
+    win2.overlay(win, 1, 2, 2, 1, 3, 3)
+    win2.overwrite(win, 1, 2, 2, 1, 3, 3)
     stdscr.redrawln(1,2)
 
     stdscr.scrollok(1)
diff --git a/lib_pypy/_curses.py b/lib_pypy/_curses.py
--- a/lib_pypy/_curses.py
+++ b/lib_pypy/_curses.py
@@ -484,13 +484,13 @@
 def _chtype(ch):
     return int(ffi.cast("chtype", ch))
 
-def _texttype(text):
-    if isinstance(text, str):
+def _bytestype(text):
+    if isinstance(text, bytes):
         return text
-    elif isinstance(text, unicode):
-        return str(text)   # default encoding
+    elif isinstance(text, str):
+        return text.encode()
     else:
-        raise TypeError("str or unicode expected, got a '%s' object"
+        raise TypeError("bytes or str expected, got a '%s' object"
                         % (type(text).__name__,))
 
 
@@ -606,7 +606,7 @@
 
     @_argspec(1, 1, 2)
     def addstr(self, y, x, text, attr=None):
-        text = _texttype(text)
+        text = _bytestype(text)
         if attr is not None:
             attr_old = lib.getattrs(self._win)
             lib.wattrset(self._win, attr)
@@ -620,7 +620,7 @@
 
     @_argspec(2, 1, 2)
     def addnstr(self, y, x, text, n, attr=None):
-        text = _texttype(text)
+        text = _bytestype(text)
         if attr is not None:
             attr_old = lib.getattrs(self._win)
             lib.wattrset(self._win, attr)
@@ -799,7 +799,7 @@
 
     @_argspec(1, 1, 2)
     def insstr(self, y, x, text, attr=None):
-        text = _texttype(text)
+        text = _bytestype(text)
         if attr is not None:
             attr_old = lib.getattrs(self._win)
             lib.wattrset(self._win, attr)
@@ -813,7 +813,7 @@
 
     @_argspec(2, 1, 2)
     def insnstr(self, y, x, text, n, attr=None):
-        text = _texttype(text)
+        text = _bytestype(text)
         if attr is not None:
             attr_old = lib.getattrs(self._win)
             lib.wattrset(self._win, attr)
@@ -1221,7 +1221,7 @@
 
 
 def putp(text):
-    text = _texttype(text)
+    text = _bytestype(text)
     return _check_ERR(lib.putp(text), "putp")
 
 
@@ -1347,17 +1347,17 @@
 
 def tigetflag(capname):
     _ensure_initialised_setupterm()
-    return lib.tigetflag(capname)
+    return lib.tigetflag(capname.encode())
 
 
 def tigetnum(capname):
     _ensure_initialised_setupterm()
-    return lib.tigetnum(capname)
+    return lib.tigetnum(capname.encode())
 
 
 def tigetstr(capname):
     _ensure_initialised_setupterm()
-    val = lib.tigetstr(capname)
+    val = lib.tigetstr(capname.encode())
     if int(ffi.cast("intptr_t", val)) in (0, -1):
         return None
     return ffi.string(val)


More information about the pypy-commit mailing list