Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
1e908af3
Kaydet (Commit)
1e908af3
authored
Eki 23, 2010
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#6518: enable context manager protocol for ossaudiodev types.
üst
1cae8b58
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
4 deletions
+42
-4
ossaudiodev.rst
Doc/library/ossaudiodev.rst
+9
-0
test_ossaudiodev.py
Lib/test/test_ossaudiodev.py
+6
-4
NEWS
Misc/NEWS
+2
-0
ossaudiodev.c
Modules/ossaudiodev.c
+25
-0
No files found.
Doc/library/ossaudiodev.rst
Dosyayı görüntüle @
1e908af3
...
...
@@ -159,6 +159,11 @@ and (read-only) attributes:
is only useful in non-blocking mode. Has no return value, since the amount of
data written is always equal to the amount of data supplied.
.. versionchanged:: 3.2
Audio device objects also support the context manager protocol, i.e. they can
be used in a :keyword:`with` statement.
The following methods each map to exactly one :func:`ioctl` system call. The
correspondence is obvious: for example, :meth:`setfmt` corresponds to the
``SNDCTL_DSP_SETFMT`` ioctl, and :meth:`sync` to ``SNDCTL_DSP_SYNC`` (this can
...
...
@@ -346,6 +351,10 @@ The mixer object provides two file-like methods:
Returns the file handle number of the open mixer device file.
.. versionchanged:: 3.2
Mixer objects also support the context manager protocol.
The remaining methods are specific to audio mixing:
...
...
Lib/test/test_ossaudiodev.py
Dosyayı görüntüle @
1e908af3
...
...
@@ -162,11 +162,13 @@ class OSSAudioDevTests(unittest.TestCase):
def
test_mixer_methods
(
self
):
# Issue #8139: ossaudiodev didn't initialize its types properly,
# therefore some methods were unavailable.
mixer
=
ossaudiodev
.
openmixer
()
try
:
with
ossaudiodev
.
openmixer
()
as
mixer
:
self
.
assertGreaterEqual
(
mixer
.
fileno
(),
0
)
finally
:
mixer
.
close
()
def
test_with
(
self
):
with
ossaudiodev
.
open
(
'w'
)
as
dsp
:
pass
self
.
assertTrue
(
dsp
.
closed
)
def
test_main
():
...
...
Misc/NEWS
Dosyayı görüntüle @
1e908af3
...
...
@@ -126,6 +126,8 @@ Library
Extensions
----------
- Issue #6518: Support context manager protcol for ossaudiodev types.
- Issue #678250: Make mmap flush a noop on ACCESS_READ and ACCESS_COPY.
- Issue #9054: Fix a crash occurring when using the pyexpat module
...
...
Modules/ossaudiodev.c
Dosyayı görüntüle @
1e908af3
...
...
@@ -469,6 +469,23 @@ oss_close(oss_audio_t *self, PyObject *unused)
return
Py_None
;
}
static
PyObject
*
oss_self
(
PyObject
*
self
)
{
Py_INCREF
(
self
);
return
self
;
}
static
PyObject
*
oss_exit
(
PyObject
*
self
,
PyObject
*
unused
)
{
PyObject
*
ret
=
PyObject_CallMethod
(
self
,
"close"
,
NULL
);
if
(
!
ret
)
return
NULL
;
Py_DECREF
(
ret
);
Py_RETURN_NONE
;
}
static
PyObject
*
oss_fileno
(
oss_audio_t
*
self
,
PyObject
*
unused
)
{
...
...
@@ -782,6 +799,10 @@ static PyMethodDef oss_methods[] = {
/* Aliases for backwards compatibility */
{
"flush"
,
(
PyCFunction
)
oss_sync
,
METH_VARARGS
},
/* Support for the context manager protocol */
{
"__enter__"
,
oss_self
,
METH_NOARGS
},
{
"__exit__"
,
oss_exit
,
METH_VARARGS
},
{
NULL
,
NULL
}
/* sentinel */
};
...
...
@@ -790,6 +811,10 @@ static PyMethodDef oss_mixer_methods[] = {
{
"close"
,
(
PyCFunction
)
oss_mixer_close
,
METH_NOARGS
},
{
"fileno"
,
(
PyCFunction
)
oss_mixer_fileno
,
METH_NOARGS
},
/* Support for the context manager protocol */
{
"__enter__"
,
oss_self
,
METH_NOARGS
},
{
"__exit__"
,
oss_exit
,
METH_VARARGS
},
/* Simple ioctl wrappers */
{
"controls"
,
(
PyCFunction
)
oss_mixer_controls
,
METH_VARARGS
},
{
"stereocontrols"
,
(
PyCFunction
)
oss_mixer_stereocontrols
,
METH_VARARGS
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment