diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2007-05-30 15:19:46 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2007-05-30 15:19:46 +0100 |
commit | c87b55c6ab30542d5d17f2e2041e4c87b3df712d (patch) | |
tree | 056e9cb9a6830147b684c8b9dc5b38d78b703305 /dbus/service.py | |
parent | 030b68b4e6d64dc25904618852917839892de1be (diff) |
dbus.service: Make it possible to unexport objects (fd.o#10457)
Diffstat (limited to 'dbus/service.py')
-rw-r--r-- | dbus/service.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/dbus/service.py b/dbus/service.py index be30b9b..65af3ff 100644 --- a/dbus/service.py +++ b/dbus/service.py @@ -380,7 +380,7 @@ class Object(Interface): is also required. :Parameters: - `conn` : dbus.Connection + `conn` : dbus.connection.Connection The connection on which to export this object. If None, use the Bus associated with the given ``bus_name``, @@ -426,6 +426,37 @@ class Object(Interface): __dbus_object_path__ = property(lambda self: self._object_path, None, None, "The D-Bus object path of this object") + def unexport(self, connection=None, path=None): + """Unexport this object. It will no longer be accessible via D-Bus. + + It's not currently possible to export an object on more than one + connection or with more than one object-path, but this will be + supported in future. + + :Parameters: + `connection` : dbus.connection.Connection or None + Only unexport the object from this Connection. If None, + unexport from all Connections. + `path` : dbus.ObjectPath or other str, or None + Only unexport the object from this object path. If None, + unexport from all object paths. + :Raises LookupError: + if the object was not exported on the requested connection + or path, or (if both are None) was not exported at all. + """ + if self._object_path is None or self._connection is None: + raise LookupError('%r is not exported' % self) + if path is not None and self._object_path != path: + raise LookupError('%r is not exported at path %r' % (self, path)) + if connection is not None and self._connection != connection: + raise LookupError('%r is not exported on %r' % (self, connection)) + + try: + self._connection._unregister_object_path(self._object_path) + finally: + self._connection = None + self._object_path = None + def _unregister_cb(self, connection): _logger.info('Unregistering exported object %r', self) |