Author: Armin Rigo <[email protected]>
Branch:
Changeset: r64860:0c8571de8df4
Date: 2013-06-12 10:19 +0200
http://bitbucket.org/pypy/pypy/changeset/0c8571de8df4/
Log: Check the type of the text arguments, and cast unicodes to strings
in the default encoding (as CPython). Fix for issue 1513.
diff --git a/lib_pypy/_curses.py b/lib_pypy/_curses.py
--- a/lib_pypy/_curses.py
+++ b/lib_pypy/_curses.py
@@ -476,6 +476,15 @@
def _chtype(ch):
return int(ffi.cast("chtype", ch))
+def _texttype(text):
+ if isinstance(text, str):
+ return text
+ elif isinstance(text, unicode):
+ return str(text) # default encoding
+ else:
+ raise TypeError("str or unicode expected, got a '%s' object"
+ % (type(text).__name__,))
+
def _extract_yx(args):
if len(args) >= 2:
@@ -589,6 +598,7 @@
@_argspec(1, 1, 2)
def addstr(self, y, x, text, attr=None):
+ text = _texttype(text)
if attr is not None:
attr_old = lib.getattrs(self._win)
lib.wattrset(self._win, attr)
@@ -602,6 +612,7 @@
@_argspec(2, 1, 2)
def addnstr(self, y, x, text, n, attr=None):
+ text = _texttype(text)
if attr is not None:
attr_old = lib.getattrs(self._win)
lib.wattrset(self._win, attr)
@@ -780,6 +791,7 @@
@_argspec(1, 1, 2)
def insstr(self, y, x, text, attr=None):
+ text = _texttype(text)
if attr is not None:
attr_old = lib.getattrs(self._win)
lib.wattrset(self._win, attr)
@@ -793,6 +805,7 @@
@_argspec(2, 1, 2)
def insnstr(self, y, x, text, n, attr=None):
+ text = _texttype(text)
if attr is not None:
attr_old = lib.getattrs(self._win)
lib.wattrset(self._win, attr)
@@ -1197,6 +1210,7 @@
def putp(text):
+ text = _texttype(text)
return _check_ERR(lib.putp(text), "putp")
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit