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: Enable 'with' statement in ossaudiodev module
Type: enhancement Stage:
Components: Extension Modules Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: agillesp, georg.brandl, jackdied, jjalocha, terry.reedy, vstinner
Priority: normal Keywords: easy, patch

Created on 2009-07-19 01:07 by jjalocha, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue6518.diff agillesp, 2009-08-22 00:30 Patch for Modules/ossaudiodev.c and Lib/test/test_ossaudiodev.py
Messages (7)
msg90697 - (view) Author: Jerzy Jalocha N (jjalocha) Date: 2009-07-19 01:07
Actually, it is not possible to use the 'with' statement in the
ossaudiodev module:

>>> import ossaudiodev
>>> with ossaudiodev.open('/dev/dsp', 'r') as device:
...     pass
...
Traceback (most recent call last):
  File "<stdin>", line 1 in <module>
AttributeError: 'ossaudodev.oss_audio_device' object has no attribute
'__exit__'

In order to provide a similar interface as standard Python files, and
encourage safe coding practices, the 'with' statement should be
supported in the ossaudiodev module.

Thanks.
msg90893 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-07-24 19:58
Seems like a sensible idea.
Note: 3.0 is no longer maintained.
Marking 'easy' because I expect that copying and adapting __exit__ from
regular open should be.
msg91850 - (view) Author: Art Gillespie (agillesp) Date: 2009-08-22 00:30
Diff attached

* Added the __enter__ and __exit__ methods to the ossaudio object.
* Updated tests so they pass (attempt to access ossaudio.closed throws
AttributeError instead of TypeError)

My first patch.  Please let me know if I did anything terrifically
stupid. :-)
msg91984 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-08-26 22:22
@agillesp: a Python function should never return NULL without setting an
error. oss_self() have to call a PyErr_(...) function to set an error.
And I would prefer the name "oss_enter" than the unusual name "oss_self".
msg91988 - (view) Author: Art Gillespie (agillesp) Date: 2009-08-26 22:55
Hi Victor,

I copied both the return NULL behavior in oss_exit and the oss_self
naming from Objects/fileobject.c:

http://paste.pocoo.org/show/136451/

Should they be changed there as well?
msg99936 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2010-02-23 17:18
+1, the C patch looks good to me.  The test file needs a new test that checks the 'with' behavior.  Also, what changed so that the test now needs to ignore AttributeErrors in play_sound_file()?
msg119451 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-23 17:31
Applied (with new test, and docs) in r85807.  I also removed the AttributeError catch.
History
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50767
2010-10-23 17:31:58georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg119451

resolution: fixed
2010-02-23 17:18:33jackdiedsetnosy: + jackdied
messages: + msg99936
2009-08-26 22:55:23agillespsetmessages: + msg91988
2009-08-26 22:22:22vstinnersetnosy: + vstinner
messages: + msg91984
2009-08-22 00:30:33agillespsetfiles: + issue6518.diff

nosy: + agillesp
messages: + msg91850

keywords: + patch
2009-07-25 15:03:34benjamin.petersonsetversions: - Python 2.6, Python 3.1
2009-07-24 19:58:35terry.reedysetversions: - Python 3.0
nosy: + terry.reedy

messages: + msg90893

keywords: + easy
2009-07-19 01:07:44jjalochacreate