Author: Marius Gedminas <mar...@gedmin.as> Branch: py3k Changeset: r77994:d07170655326 Date: 2015-04-02 11:07 +0300 http://bitbucket.org/pypy/pypy/changeset/d07170655326/
Log: Make curses.tigetstr/tigetnum/tigetflag handle Unicode strings Fixes https://bitbucket.org/pypy/pypy/issue/1997/pypy3 -cursestigetstr-raises-ctype and https://bitbucket.org/pypy/pypy/issue/2016/pypy3-cursestigetnum- raises-ctype All credit belongs to Thomas Ballinger for creating the original fix for tigetstr() that I copied and pasted to fix tigetnum() and tigetflag() as well. diff --git a/lib_pypy/_curses.py b/lib_pypy/_curses.py --- a/lib_pypy/_curses.py +++ b/lib_pypy/_curses.py @@ -1347,16 +1347,22 @@ def tigetflag(capname): _ensure_initialised_setupterm() + if isinstance(capname, str): + capname = capname.encode('utf-8') return lib.tigetflag(capname) def tigetnum(capname): _ensure_initialised_setupterm() + if isinstance(capname, str): + capname = capname.encode('utf-8') return lib.tigetnum(capname) def tigetstr(capname): _ensure_initialised_setupterm() + if isinstance(capname, str): + capname = capname.encode('utf-8') val = lib.tigetstr(capname) if int(ffi.cast("intptr_t", val)) in (0, -1): return None @@ -1365,6 +1371,13 @@ def tparm(fmt, i1=0, i2=0, i3=0, i4=0, i5=0, i6=0, i7=0, i8=0, i9=0): args = [ffi.cast("int", i) for i in (i1, i2, i3, i4, i5, i6, i7, i8, i9)] + # fmt is expected to be a byte string; CPython 3.x complains + # "TypeError: 'str' does not support the buffer interface", but we + # can do better. + if isinstance(fmt, str): + # error message modeled on "TypeError: must be str, not bytes" + # that you get if you call curses.tigetstr(b'...') on CPython 3.x + raise TypeError('must be bytes, not str') result = lib.tparm(fmt, *args) if result == ffi.NULL: raise error("tparm() returned NULL") _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit