This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: curses.tigetstr() returns bytes, but curses.tparm() expects a string
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, jwilk, klausman, nadeem.vawda, petri.lehtinen, python-dev, vstinner
Priority: normal Keywords: needs review, patch

Created on 2010-11-28 23:38 by jwilk, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue10570.patch petri.lehtinen, 2011-11-02 20:10
Messages (13)
msg122746 - (view) Author: Jakub Wilk (jwilk) Date: 2010-11-28 23:38
$ python3 --version
Python 3.1.3

$ python3 setup.py bdist upload --sign
[snip]
Traceback (most recent call last):
  File "setup.py", line 71, in <module>
    cmdclass = dict(build_py=build_py)
  File "/usr/local/lib/python3.1/distutils/core.py", line 149, in setup
    dist.run_commands()
  File "/usr/local/lib/python3.1/distutils/dist.py", line 919, in run_commands
    self.run_command(cmd)
  File "/usr/local/lib/python3.1/distutils/dist.py", line 938, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python3.1/distutils/command/upload.py", line 66, in run
    self.upload_file(command, pyversion, filename)
  File "/usr/local/lib/python3.1/distutils/command/upload.py", line 155, in upload_file
    body.write(value)
TypeError: 'str' does not support the buffer interface


Without --sign it works just fine.
msg122781 - (view) Author: Jakub Wilk (jwilk) Date: 2010-11-29 08:44
Ugh. Please disregard the first message. What I wanted to write is:

In Python 3.1.3, curses.tigetstr() returns bytes (which makes sense), but
curses.tparm() expects a Unicode string as first argument. As a consequence
even the example given in the documentation doesn't work:

>>> from curses import *
>>> setupterm()
>>> tparm(tigetstr("cup"), 5, 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be string, not bytes
msg141657 - (view) Author: Tobias Klausmann (klausman) Date: 2011-08-05 12:23
This bug is still not fixed and basically makes the curses module unusable except for very narrow use cases. Unfortunately, my C-fu is very weak, otherwise I'd try to make a patch.
msg141770 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-08-08 11:21
See also #12567.
msg146873 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-11-02 20:10
I'm not a curses expert, but after digging a while, I believe that I now understand what these functions are doing. tigetstr() returns a "format string" (bytes) and tparm() does substitutions and returns a command string (bytes) for the terminal.

I don't believe that the first parameter to tparm() (the format string) is ever constructed by hand, because it's terminal specific. The value is obtained from the terminfo database by calling tigetstr() instead. Furthermore, tigetstr() returns binary data, for which bytes is the only sane representation, and therefore tparm() should expect bytes instead of str.

Attached a patch that fixes this.
msg146879 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-02 22:46
New changeset e41663970ca5 by Victor Stinner in branch '3.2':
Issue #10570: curses.tigetstr() is now expecting a byte string, instead of a
http://hg.python.org/cpython/rev/e41663970ca5

New changeset ab11a6a73683 by Victor Stinner in branch 'default':
(Merge 3.2) Issue #10570: curses.tigetstr() is now expecting a byte string,
http://hg.python.org/cpython/rev/ab11a6a73683
msg146880 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-11-02 22:48
"I don't believe that the first parameter to tparm() (the format string) is ever constructed by hand, because it's terminal specific. The value is obtained from the terminfo database by calling tigetstr() instead. Furthermore, tigetstr() returns binary data, for which bytes is the only sane representation, and therefore tparm() should expect bytes instead of str."

Ok, it sounds to be fair. I wrote a patch based on yours (except that Python crashes with your patch :-)).
msg146913 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2011-11-03 09:53
It seems that putp() should also accept only bytes, because it's used to output terminal commands. It's currently expecting a str.
msg146963 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-03 19:35
New changeset 38f4a251608f by Victor Stinner in branch '3.2':
Issue #10570: curses.putp() is now expecting a byte string, instead of a
http://hg.python.org/cpython/rev/38f4a251608f

New changeset 08f44eb760a6 by Victor Stinner in branch 'default':
(Merge 3.2) Issue #10570: curses.putp() is now expecting a byte string, instead
http://hg.python.org/cpython/rev/08f44eb760a6
msg146964 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-11-03 19:36
> It seems that putp() should also accept only bytes,
> because it's used to output terminal commands.

Ok, here is another fix for Python 3.2 and 3.3. I'm closing the issue again.
msg147136 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-11-06 03:18
The entry in Misc/NEWS mentions the change in curses.tigetstr(), but actually curses.tparm() has been changed. Please fix that entry to avoid confusion.
(curses.tigetstr() still expects a unicode string and returns a bytes string.)
msg147145 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-11-06 07:31
New changeset 3a0a94797ac5 by Petri Lehtinen in branch '3.2':
curses.tparm() is expecting a byte string, not curses.tigetstr()
http://hg.python.org/cpython/rev/3a0a94797ac5

New changeset 626c6c7f3af6 by Petri Lehtinen in branch 'default':
curses.tparm() is expecting a byte string, not curses.tigetstr()
http://hg.python.org/cpython/rev/626c6c7f3af6
msg147158 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-11-06 13:55
> The entry in Misc/NEWS mentions the change in curses.tigetstr(),
> but actually curses.tparm() has been changed

Woops, thanks for fixing the NEWS file :-)
History
Date User Action Args
2022-04-11 14:57:09adminsetgithub: 54779
2011-11-06 13:55:42vstinnersetmessages: + msg147158
2011-11-06 07:40:28Arfreversetstatus: open -> closed
resolution: fixed
2011-11-06 07:31:09python-devsetmessages: + msg147145
2011-11-06 03:18:32Arfreversetstatus: closed -> open

nosy: + Arfrever
messages: + msg147136

resolution: fixed -> (no value)
2011-11-03 19:36:18vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg146964
2011-11-03 19:35:38python-devsetmessages: + msg146963
2011-11-03 09:53:50petri.lehtinensetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg146913

stage: patch review -> resolved
2011-11-02 22:48:09vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg146880
2011-11-02 22:46:41python-devsetnosy: + python-dev
messages: + msg146879
2011-11-02 20:10:06petri.lehtinensetkeywords: + patch, needs review
files: + issue10570.patch
messages: + msg146873

stage: test needed -> patch review
2011-10-28 08:55:08petri.lehtinensetnosy: + petri.lehtinen
stage: test needed

versions: + Python 3.2, Python 3.3, - Python 3.1
2011-08-08 11:35:06nadeem.vawdasetnosy: + nadeem.vawda
2011-08-08 11:21:53vstinnersetmessages: + msg141770
2011-08-05 21:20:57ned.deilysetnosy: + vstinner
2011-08-05 12:23:08klausmansetnosy: + klausman
messages: + msg141657
2010-11-29 08:44:04jwilksetmessages: + msg122781
2010-11-28 23:38:53jwilkcreate