ref: f1f2e7ec62cdda1f0acc3ad929b76574b7d04066
parent: cc469dd6c9b7fb66eabb4cde0929270bb54a4f7d
author: Paul Brossier <piem@piem.org>
date: Sun Feb 26 18:47:19 EST 2017
python/ext/py-source.c: add with interface (PEP 343)
--- a/python/ext/py-source.c
+++ b/python/ext/py-source.c
@@ -272,6 +272,18 @@
Py_RETURN_NONE;
}
+static char Pyaubio_source_enter_doc[] = "";
+static PyObject* Pyaubio_source_enter(Py_source *self, PyObject *unused) {
+ Py_INCREF(self);
+ return (PyObject*)self;
+}
+
+static char Pyaubio_source_exit_doc[] = "";
+static PyObject* Pyaubio_source_exit(Py_source *self, PyObject *unused) {
+ Pyaubio_source_close(self, unused);
+ return Pyaubio_source_close(self, unused);
+}
+
static PyMethodDef Py_source_methods[] = {
{"get_samplerate", (PyCFunction) Pyaubio_source_get_samplerate,
METH_NOARGS, Py_source_get_samplerate_doc},
@@ -285,6 +297,10 @@
METH_NOARGS, Py_source_close_doc},
{"seek", (PyCFunction) Pyaubio_source_seek,
METH_VARARGS, Py_source_seek_doc},
+ {"__enter__", (PyCFunction)Pyaubio_source_enter, METH_NOARGS,
+ Pyaubio_source_enter_doc},
+ {"__exit__", (PyCFunction)Pyaubio_source_exit, METH_VARARGS,
+ Pyaubio_source_exit_doc},
{NULL} /* sentinel */
};