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: sunau bytes / str TypeError in Py3k
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: tjollans, vstinner
Priority: normal Keywords: patch

Created on 2010-06-04 17:34 by tjollans, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sunau-bytes.diff tjollans, 2010-06-07 10:16 fix / patch
sunau-test.diff tjollans, 2010-06-07 17:14 patch adding test_sunau.py
Messages (5)
msg107081 - (view) Author: Thomas Jollans (tjollans) Date: 2010-06-04 17:34
The sunau module, essentially, "doesn't work". This looks like a problem with the bytes/unicode transition of "str" in Python 3.x vs Python 2:

Python 3.1.2 (r312:79147, Apr 15 2010, 15:35:48) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sunau
>>> aufile = sunau.open('test.au', 'w')
>>> aufile.setsampwidth(2)
>>> aufile.setframerate(44100)
>>> aufile.setnchannels(1)
>>> aufile.writeframes(b'aabbccdd')
Exception wave.Error: Error('# channels not specified',) in <bound method Wave_write.__del__ of <wave.Wave_write object at 0x1fa8ed0>> ignored
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.1/sunau.py", line 393, in writeframes
    self.writeframesraw(data)
  File "/usr/lib/python3.1/sunau.py", line 383, in writeframesraw
    self._ensure_header_written()
  File "/usr/lib/python3.1/sunau.py", line 418, in _ensure_header_written
    self._write_header()
  File "/usr/lib/python3.1/sunau.py", line 452, in _write_header
    self._file.write(self._info)
TypeError: must be bytes or buffer, not str
>>> 

The wave and aifc modules work as expected when used like this, as does the above code in Python 2.6. Au_read.readframes correctly returns a bytes.

I haven't tested this on a development version of Python.
msg107262 - (view) Author: Thomas Jollans (tjollans) Date: 2010-06-07 10:16
Attached is a patch against the current py3k trunk that fixes this. (as far as I can tell)
msg107263 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-06-07 11:20
Can you add a test?
msg107271 - (view) Author: Thomas Jollans (tjollans) Date: 2010-06-07 17:14
test case for sunau, as requested. Loosely based on test_wave.
msg107277 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-06-07 20:26
> test case for sunau, as requested. Loosely based on test_wave.

Ok great. Commited to py3k (r81809) and 3.1 (r81810).
History
Date User Action Args
2022-04-11 14:57:01adminsetgithub: 53143
2010-06-07 20:26:55vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg107277
2010-06-07 17:14:24tjollanssetfiles: + sunau-test.diff

messages: + msg107271
2010-06-07 11:20:59vstinnersetnosy: + vstinner
messages: + msg107263
2010-06-07 10:16:53tjollanssetfiles: + sunau-bytes.diff
keywords: + patch
messages: + msg107262
2010-06-04 17:34:54tjollanscreate