[PATCH][python] _dbus_bindings/conn-methods.c: add list_exported_child_objects().

John (J5) Palmieri johnp at redhat.com
Wed May 30 12:51:31 PDT 2007


Looks good

On Tue, 2007-05-29 at 15:34 +0100, Simon McVittie wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> This is equivalent to dbus_connection_list_registered() in libdbus.
> - ---
>  _dbus_bindings/conn-methods.c |   62 +++++++++++++++++++++++++++++++++++++++++
>  test/test-client.py           |    3 ++
>  test/test-service.py          |    8 +++++
>  3 files changed, 73 insertions(+), 0 deletions(-)
> 
> diff --git a/_dbus_bindings/conn-methods.c b/_dbus_bindings/conn-methods.c
> index 1b41c46..23e7d64 100644
> - --- a/_dbus_bindings/conn-methods.c
> +++ b/_dbus_bindings/conn-methods.c
> @@ -901,6 +901,67 @@ Connection__unregister_object_path(Connection *self, PyObject *args,
>      }
>  }
>  
> +PyDoc_STRVAR(Connection_list_exported_child_objects__doc__,
> +"list_exported_child_objects(path: str) -> list of str\n\n"
> +"Return a list of the names of objects exported on this Connection as\n"
> +"direct children of the given object path.\n"
> +"\n"
> +"Each name returned may be converted to a valid object path using\n"
> +"``dbus.ObjectPath('%s%s%s' % (path, (path != '/' and '/' or ''), name))``.\n"
> +"For the purposes of this function, every parent or ancestor of an exported\n"
> +"object is considered to be an exported object, even if it's only an object\n"
> +"synthesized by the library to support introspection.\n");
> +static PyObject *
> +Connection_list_exported_child_objects (Connection *self, PyObject *args,
> +                                        PyObject *kwargs)
> +{
> +    const char *path;
> +    char **kids, **kid_ptr;
> +    dbus_bool_t ok;
> +    PyObject *ret;
> +    static char *argnames[] = {"path", NULL};
> +
> +    DBUS_PY_RAISE_VIA_NULL_IF_FAIL(self->conn);
> +    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", argnames, &path)) {
> +        return NULL;
> +    }
> +
> +    if (!dbus_py_validate_object_path(path)) {
> +        return NULL;
> +    }
> +
> +    Py_BEGIN_ALLOW_THREADS
> +    ok = dbus_connection_list_registered(self->conn, path, &kids);
> +    Py_END_ALLOW_THREADS
> +
> +    if (!ok) {
> +        return PyErr_NoMemory();
> +    }
> +
> +    ret = PyList_New(0);
> +    if (!ret) {
> +        return NULL;
> +    }
> +    for (kid_ptr = kids; *kid_ptr; kid_ptr++) {
> +        PyObject *tmp = PyString_FromString(*kid_ptr);
> +
> +        if (!tmp) {
> +            Py_DECREF(ret);
> +            return NULL;
> +        }
> +        if (PyList_Append(ret, tmp) < 0) {
> +            Py_DECREF(tmp);
> +            Py_DECREF(ret);
> +            return NULL;
> +        }
> +        Py_DECREF(tmp);
> +    }
> +
> +    dbus_free_string_array(kids);
> +
> +    return ret;
> +}
> +
>      /* dbus_connection_get_object_path_data - not useful to Python,
>       * the object path data is just a PyString containing the path */
>      /* dbus_connection_list_registered could be useful, though */
> @@ -955,6 +1016,7 @@ struct PyMethodDef DBusPyConnection_tp_methods[] = {
>      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),
> +    ENTRY(list_exported_child_objects, METH_VARARGS|METH_KEYWORDS),
>      {"_new_for_bus", (PyCFunction)DBusPyConnection_NewForBus,
>          METH_CLASS|METH_VARARGS|METH_KEYWORDS,
>          new_for_bus__doc__},
> diff --git a/test/test-client.py b/test/test-client.py
> index 49c4261..2de34fb 100755
> - --- a/test/test-client.py
> +++ b/test/test-client.py
> @@ -385,6 +385,9 @@ class TestDBusBindings(unittest.TestCase):
>          self.assert_(not isinstance(ret, dbus.Struct), repr(ret))
>          self.assertEquals(ret, ('abc', 123))
>  
> +    def testListExportedChildObjects(self):
> +        self.assert_(self.iface.TestListExportedChildObjects())
> +
>  """ Remove this for now
>  class TestDBusPythonToGLibBindings(unittest.TestCase):
>      def setUp(self):
> diff --git a/test/test-service.py b/test/test-service.py
> index 2ef1e22..c27c55f 100755
> - --- a/test/test-service.py
> +++ b/test/test-service.py
> @@ -182,6 +182,14 @@ class TestObject(dbus.service.Object, TestInterface):
>      def CheckInheritance(self):
>          return True
>  
> +    @dbus.service.method(IFACE, in_signature='', out_signature='b')
> +    def TestListExportedChildObjects(self):
> +        objs_root = session_bus.list_exported_child_objects('/')
> +        assert objs_root == ['org'], objs_root
> +        objs_org = session_bus.list_exported_child_objects('/org')
> +        assert objs_org == ['freedesktop'], objs_org
> +        return True
> +
>      @dbus.service.method(IFACE, in_signature='bbv', out_signature='v', async_callbacks=('return_cb', 'error_cb'))
>      def AsynchronousMethod(self, async, fail, variant, return_cb, error_cb):
>          try:
> - -- 
> 1.5.2-rc3.GIT
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: OpenPGP key: http://www.pseudorandom.co.uk/2003/contact/ or pgp.net
> 
> iD8DBQFGXDoRWSc8zVUw7HYRAn5YAJ9nvRkamRZmvG9RsGYGuCUjOaIC8gCgrz/k
> BqP+EhNOp24sXHIJLRegjyo=
> =LjjB
> -----END PGP SIGNATURE-----
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus



More information about the dbus mailing list