[patch] [python] When running without a main loop don't make
introspection fail.
Simon McVittie
simon.mcvittie at collabora.co.uk
Tue Jan 16 11:49:53 PST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
- From f0deb687acad02173c20a0dc644323774b24dc0e Mon Sep 17 00:00:00 2001
From: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Tue, 16 Jan 2007 19:38:00 +0000
Subject: [PATCH] When running without a main loop, don't make introspection fail.
Also change send_message_with_reply() to not demand a main loop by default
(since you can call block() on the returned object, like blocking introspection
does).
- ---
_dbus_bindings/conn-methods.c | 24 +++++++++++++++++-------
dbus/proxies.py | 2 +-
2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/_dbus_bindings/conn-methods.c b/_dbus_bindings/conn-methods.c
index f9c8554..16a0102 100644
- --- a/_dbus_bindings/conn-methods.c
+++ b/_dbus_bindings/conn-methods.c
@@ -338,8 +338,8 @@ Connection_send_message(Connection *self, PyObject *args)
/* The timeout is in seconds here, since that's conventional in Python. */
PyDoc_STRVAR(Connection_send_message_with_reply__doc__,
- -"send_message_with_reply(msg, reply_handler, timeout_s=-1)"
- -" -> dbus.lowlevel.PendingCall\n\n"
+"send_message_with_reply(msg, reply_handler, timeout_s=-1, "
+"require_main_loop=False) -> dbus.lowlevel.PendingCall\n\n"
"Queue the message for sending; expect a reply via the returned PendingCall,\n"
"which can also be used to cancel the pending call.\n"
"\n"
@@ -353,10 +353,14 @@ PyDoc_STRVAR(Connection_send_message_with_reply__doc__,
" If the reply takes more than this many seconds, a timeout error\n"
" will be created locally and raised instead. If this timeout is\n"
" negative (default), a sane default (supplied by libdbus) is used.\n"
+" `require_main_loop` : bool\n"
+" If True, raise RuntimeError if this Connection does not have a main\n"
+" loop configured. If False (default) and there is no main loop, you are\n"
+" responsible for calling block() on the PendingCall.\n"
"\n"
);
static PyObject *
- -Connection_send_message_with_reply(Connection *self, PyObject *args)
+Connection_send_message_with_reply(Connection *self, PyObject *args, PyObject *kw)
{
dbus_bool_t ok;
double timeout_s = -1.0;
@@ -364,14 +368,20 @@ Connection_send_message_with_reply(Connection *self, PyObject *args)
PyObject *obj, *callable;
DBusMessage *msg;
DBusPendingCall *pending;
+ int require_main_loop = 0;
+ static char *argnames[] = {"msg", "reply_handler", "timeout_s",
+ "require_main_loop", NULL};
TRACE(self);
DBUS_PY_RAISE_VIA_NULL_IF_FAIL(self->conn);
- - if (!Connection__require_main_loop(self, NULL)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kw,
+ "OO|fi:send_message_with_reply",
+ argnames,
+ &obj, &callable, &timeout_s,
+ &require_main_loop)) {
return NULL;
}
- - if (!PyArg_ParseTuple(args, "OO|f:send_message_with_reply", &obj, &callable,
- - &timeout_s)) {
+ if (require_main_loop && !Connection__require_main_loop(self, NULL)) {
return NULL;
}
@@ -917,7 +927,7 @@ struct PyMethodDef DBusPyConnection_tp_methods[] = {
ENTRY(_register_object_path, METH_VARARGS|METH_KEYWORDS),
ENTRY(remove_message_filter, METH_O),
ENTRY(send_message, METH_VARARGS),
- - ENTRY(send_message_with_reply, METH_VARARGS),
+ ENTRY(send_message_with_reply, METH_VARARGS|METH_KEYWORDS),
ENTRY(send_message_with_reply_and_block, METH_VARARGS),
ENTRY(_unregister_object_path, METH_VARARGS|METH_KEYWORDS),
{NULL},
diff --git a/dbus/proxies.py b/dbus/proxies.py
index d2309ca..66dc9a9 100644
- --- a/dbus/proxies.py
+++ b/dbus/proxies.py
@@ -160,7 +160,7 @@ class ProxyMethod:
self._connection.send_message(message)
return None
elif reply_handler:
- - result = self._connection.send_message_with_reply(message, _ReplyHandler(reply_handler, error_handler, **get_args_options), timeout/1000.0)
+ self._connection.send_message_with_reply(message, _ReplyHandler(reply_handler, error_handler, **get_args_options), timeout/1000.0, require_main_loop=1)
return None
else:
reply_message = self._connection.send_message_with_reply_and_block(message, timeout)
- --
1.4.4.4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: OpenPGP key: http://www.pseudorandom.co.uk/2003/contact/ or pgp.net
iD8DBQFFrSxgWSc8zVUw7HYRAjkhAJ0VoKiq2NIQMqxsLHCt+r2d5ETmDQCfQ9OF
OoTcYaFP+zvuxjUddpT0a4Y=
=MIE3
-----END PGP SIGNATURE-----
More information about the dbus
mailing list