dbus/python _dbus.py, 1.4, 1.5 decorators.py, 1.2, 1.3 matchrules.py, 1.1, 1.2

John Palmieri johnp at freedesktop.org
Tue May 24 09:30:53 PDT 2005


Update of /cvs/dbus/dbus/python
In directory gabe:/tmp/cvs-serv19043/python

Modified Files:
	_dbus.py decorators.py matchrules.py 
Log Message:
* python/decorators.py: add explicitly_pass_message decorator
  for passing in the dbus message as keyword for edge case signal
  handling

* python/matchrules.py (SignalMatchRule.__repr__): fix output
  to conform with what dbus expects for match rules
  (SignalMatchRule.execute): add the dbus message as a keyword
  if the signal handler has requested it

* python/examples/example/signal-recipient.py: added some more
  examples on how to hook up to signals

* python/proxies.py: minor formatting changes


Index: _dbus.py
===================================================================
RCS file: /cvs/dbus/dbus/python/_dbus.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- _dbus.py	24 May 2005 00:21:07 -0000	1.4
+++ _dbus.py	24 May 2005 16:30:50 -0000	1.5
@@ -150,9 +150,7 @@
 
         match_rule = SignalMatchRule(signal_name, dbus_interface, named_service, path)
 
-        args = message.get_args_list()
-
-        self._match_rule_tree.exec_matches(match_rule, *args)
+        self._match_rule_tree.exec_matches(match_rule, message)
 
     def start_service_by_name(self, named_service):
         return dbus_bindings.bus_start_service_by_name(self._connection, named_service)

Index: decorators.py
===================================================================
RCS file: /cvs/dbus/dbus/python/decorators.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- decorators.py	24 May 2005 00:21:07 -0000	1.2
+++ decorators.py	24 May 2005 16:30:50 -0000	1.3
@@ -1,7 +1,7 @@
 import _util 
 import inspect
 import dbus_bindings
-
+import new
 
 def method(dbus_interface):
     _util._validate_interface_or_name(dbus_interface)
@@ -37,3 +37,6 @@
 
     return decorator
 
+def explicitly_pass_message(func):
+    func._dbus_pass_message = True
+    return func

Index: matchrules.py
===================================================================
RCS file: /cvs/dbus/dbus/python/matchrules.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- matchrules.py	24 May 2005 00:21:07 -0000	1.1
+++ matchrules.py	24 May 2005 16:30:50 -0000	1.2
@@ -69,7 +69,7 @@
         path = signal.add(rule.signal_name)
         path.add(rule.path, leaf=rule)
        
-    def exec_matches(self, match_rule, *args):
+    def exec_matches(self, match_rule, message):
         sender_matches = self._tree.get_matches(match_rule.sender)
         for sender_node in sender_matches:
             interface_matches = sender_node.get_matches(match_rule.dbus_interface)
@@ -80,7 +80,7 @@
                     for path_node in path_matches:
                         if(path_node.rules):
                             for rule in path_node.rules:
-                                rule.execute(*args)
+                                rule.execute(message)
             
     def remove(self, rule):
         try:
@@ -122,9 +122,14 @@
         self.sender = sender
         self.path = path
 
-    def execute(self, *args):
+    def execute(self, message):
+        args = message.get_args_list()
         for handler in self.handler_functions:
-            handler(*args)
+            if getattr(handler, "_dbus_pass_message", False):
+                keywords = {"dbus_message": message}
+                handler(*args, **keywords)
+            else:
+                handler(*args)
 
     def add_handler(self, handler):
         self.handler_functions.append(handler)
@@ -149,22 +154,14 @@
         repr = "type='signal'"
         if (self.dbus_interface):
             repr = repr + ",interface='%s'" % (self.dbus_interface)
-        else:
-            repr = repr + ",interface='*'"
 
         if (self.sender):     
             repr = repr + ",sender='%s'" % (self.sender)
-        else:
-            repr = repr + ",sender='*'"
     
         if (self.path):
             repr = repr + ",path='%s'" % (self.path)
-        else:
-            repr = repr + ",path='*'" 
             
         if (self.signal_name):
             repr = repr + ",member='%s'" % (self.signal_name)
-        else:
-            repr = repr + ",member='*'"
     
         return repr



More information about the dbus-commit mailing list