Index: _dbus.py =================================================================== RCS file: /cvs/dbus/dbus/python/_dbus.py,v retrieving revision 1.3 diff -u -r1.3 _dbus.py --- _dbus.py 16 May 2005 21:27:04 -0000 1.3 +++ _dbus.py 23 May 2005 16:19:40 -0000 @@ -113,20 +113,22 @@ def add_signal_receiver(self, handler_function, signal_name=None, dbus_interface=None, named_service=None, path=None): match_rule = self._get_match_rule(signal_name, dbus_interface, named_service, path) - if (not self._match_rule_to_receivers.has_key(match_rule)): - self._match_rule_to_receivers[match_rule] = [handler_function] - else: - self._match_rule_to_receivers[match_rule].append(handler_function) - - dbus_bindings.bus_add_match(self._connection, match_rule) + receivers = self._match_rule_to_receivers.setdefault(match_rule, []) + # Only add the match if we've not already done so + if not receivers: + dbus_bindings.bus_add_match(self._connection, match_rule) + receivers.append(handler_function) def remove_signal_receiver(self, handler_function, signal_name=None, dbus_interface=None, named_service=None, path=None): match_rule = self._get_match_rule(signal_name, dbus_interface, named_service, path) + receivers = self._match_rule_to_receivers.get(match_rule, []) + + if handler_func in receivers + receivers.remove(handler_function) - if self._match_rule_to_receivers.has_key(match_rule): - if self._match_rule_to_receivers[match_rule].__contains__(handler_function): - self._match_rule_to_receivers[match_rule].pop(handler_function) - dbus_bindings.bus_remove_match(self._connection, match_rule) + # Only remove the match if there are no entries left + if not receivers: + dbus_bindings.bus_remove_match(self._connection, match_rule) def get_unix_user(self, named_service): """Get the unix user for the given named_service on this Bus""" @@ -160,12 +162,10 @@ match_rule = self._get_match_rule(signal_name, dbus_interface, named_service, path) - if (self._match_rule_to_receivers.has_key(match_rule)): - receivers = self._match_rule_to_receivers[match_rule] - - for receiver in receivers: - args = message.get_args_list() - receiver(*args) + receivers = self._match_rule_to_receivers.get(match_rule, []) + for receiver in receivers: + args = message.get_args_list() + receiver(*args) def start_service_by_name(self, named_service): return dbus_bindings.bus_start_service_by_name(self._connection, named_service)