classification
Title: os.write accepts unicode strings
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, christian.heimes, gvanrossum, pitrou
Priority: high Keywords: patch

Created on 2008-09-04 22:41 by pitrou, last changed 2008-09-15 23:03 by pitrou. This issue is now closed.

Files
File name Uploaded Description Edit
oswrite.patch pitrou, 2008-09-15 16:51
Messages (6)
msg72537 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-09-04 22:41
I'm a bit puzzled that both str and bytes are accepted by os.write() in
py3k:

>>> os.write(1, "foo\n")
foo
4
>>> os.write(1, b"foo\n")
foo
4
msg72775 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-09-08 13:15
posix_write() uses s* 

s* (string, Unicode, or any buffer compatible object) [Py_buffer *]
http://docs.python.org/dev/3.0/c-api/arg.html

IMHO os.write should not accept unicode and convert it to default
encoding. The low level os functions are all about bytes.
msg72783 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-09-08 17:11
Agreed.  But we need to tread carefully -- fixing this might break other
stuff that has silently relied on it.  Better try it ASAP.
msg73268 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-09-15 16:51
Here is a patch. I've covered all direct uses of os.write() in the
standard library, but perhaps there are indirect uses. Please review.
msg73283 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-09-15 22:21
Assuming you've run the test suite, go ahead and apply.
msg73285 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-09-15 23:03
Thanks, committed in r66469.
History
Date User Action Args
2008-09-15 23:03:49pitrousetstatus: open -> closed
resolution: fixed
messages: + msg73285
2008-09-15 22:21:11benjamin.petersonsetkeywords: - needs review
nosy: + benjamin.peterson
messages: + msg73283
2008-09-15 16:51:36pitrousetkeywords: + patch, needs review
files: + oswrite.patch
messages: + msg73268
2008-09-08 17:11:05gvanrossumsetnosy: + gvanrossum
messages: + msg72783
2008-09-08 13:15:05christian.heimessetnosy: + christian.heimes
messages: + msg72775
2008-09-04 22:41:34pitroucreate