Added 'get_wait_callback()' function.

This commit is contained in:
Daniele Varrazzo 2010-04-04 00:14:48 +01:00
parent a7c41a0388
commit 8ba0f00d21
4 changed files with 29 additions and 2 deletions

View File

@ -61,7 +61,7 @@ from _psycopg import ISQLQuote
from _psycopg import QueryCanceledError, TransactionRollbackError
try:
from _psycopg import set_wait_callback
from _psycopg import set_wait_callback, get_wait_callback
except ImportError:
pass

View File

@ -56,6 +56,25 @@ psyco_set_wait_callback(PyObject *self, PyObject *obj)
}
/* Return the currently registered wait callback function.
*
* The function is exported by the _psycopg module.
*/
PyObject *
psyco_get_wait_callback(PyObject *self, PyObject *obj)
{
PyObject *ret;
ret = wait_callback;
if (!ret) {
ret = Py_None;
}
Py_INCREF(ret);
return ret;
}
/* Return nonzero if a wait callback should be called. */
int
psyco_green()

View File

@ -47,8 +47,14 @@ extern "C" {
"\n" \
"See `~psycopg2.extras.wait_select()` for an example of a wait callback\n" \
"implementation.\n"
HIDDEN PyObject *psyco_set_wait_callback(PyObject *self, PyObject *obj);
#define psyco_get_wait_callback_doc \
"get_wait_callback() -- Return the currently registered wait callback.\n" \
"\n" \
"Return `None` if no callback is currently registered.\n"
HIDDEN PyObject *psyco_get_wait_callback(PyObject *self, PyObject *obj);
HIDDEN int psyco_green(void);
HIDDEN PyObject *psyco_wait(PyObject *conn, PyObject *curs);
HIDDEN PGresult *psyco_exec_green(connectionObject *conn, const char *command);

View File

@ -697,6 +697,8 @@ static PyMethodDef psycopgMethods[] = {
#ifdef PSYCOPG_EXTENSIONS
{"set_wait_callback", (PyCFunction)psyco_set_wait_callback,
METH_O, psyco_set_wait_callback_doc},
{"get_wait_callback", (PyCFunction)psyco_get_wait_callback,
METH_NOARGS, psyco_get_wait_callback_doc},
#endif
{NULL, NULL, 0, NULL} /* Sentinel */