dbus/python _dbus.py, 1.15, 1.16 dbus_bindings.pyx, 1.20, 1.21 matchrules.py, 1.5, 1.6

Robert McQueen robot101 at freedesktop.org
Wed Feb 15 15:45:52 PST 2006


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

Modified Files:
	_dbus.py dbus_bindings.pyx matchrules.py 
Log Message:
2006-02-16  Robert McQueen  <robot101 at debian.org>

	* glib/dbus-gmain.c: Make the previous commit compile.

	* python/_dbus.py, python/matchrules.py: Patch from Ole Andre
	Ravnaas <ole.andre.ravnaas at collabora.co.uk> to allow you to
	specify sender_keyword="foo", path_keyword="bar" when adding
	a signal listener, so that you can bind to signals generically
	but still do something useful in your callback.

	* python/dbus_bindings.pyx: Demarshal the byte type as unsigned
	chars so that they're not cast to chars and made negative. Thanks
	to Jakub Stachowski for reporting this and testing the fix.

Index: _dbus.py
===================================================================
RCS file: /cvs/dbus/dbus/python/_dbus.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- _dbus.py	7 Nov 2005 12:14:53 -0000	1.15
+++ _dbus.py	15 Feb 2006 23:45:50 -0000	1.16
@@ -158,6 +158,8 @@
                     args_dict[num] = value
                 except ValueError:
                     raise TypeError("Invalid arg index %s"%snum)
+            elif key in ("sender_keyword", "path_keyword"):
+                pass
             else:
                 raise TypeError("Unknown keyword %s"%(key)) 
 
@@ -178,6 +180,12 @@
         
         match_rule = SignalMatchRule(signal_name, dbus_interface, named_service, path)
 
+        for kw in ("sender_keyword", "path_keyword"):
+            if kw in keywords:
+                setattr(match_rule, kw, keywords[kw])
+            else:
+                setattr(match_rule, kw, None)
+
         if args_dict:
             match_rule.add_args_match(args_dict)
 

Index: dbus_bindings.pyx
===================================================================
RCS file: /cvs/dbus/dbus/python/dbus_bindings.pyx,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- dbus_bindings.pyx	27 Nov 2005 17:44:19 -0000	1.20
+++ dbus_bindings.pyx	15 Feb 2006 23:45:50 -0000	1.21
@@ -741,10 +741,10 @@
         return dbus_message_iter_get_element_type(self.iter)
 
     def get_byte(self):
-        cdef char c_val
-        dbus_message_iter_get_basic(self.iter, <char *>&c_val)
+        cdef unsigned char c_val
+        dbus_message_iter_get_basic(self.iter, <unsigned char *>&c_val)
         return c_val
-        
+
     def get_boolean(self):
         cdef dbus_bool_t c_val
         dbus_message_iter_get_basic(self.iter, <dbus_bool_t *>&c_val)

Index: matchrules.py
===================================================================
RCS file: /cvs/dbus/dbus/python/matchrules.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- matchrules.py	18 Aug 2005 04:04:57 -0000	1.5
+++ matchrules.py	15 Feb 2006 23:45:50 -0000	1.6
@@ -130,16 +130,25 @@
         self.args = args
 
     def execute(self, message, args=None):
-        #optimization just in case we already extarcted the args
+        keywords = {}
+
+        if self.sender_keyword is not None:
+            keywords[self.sender_keyword] = message.get_sender()
+        if self.path_keyword is not None:
+            keywords[self.path_keyword] = message.get_path()
+
+        # optimization just in case we already extracted the args
         if not args:
            args = message.get_args_list()
            
         for handler in self.handler_functions:
             if getattr(handler, "_dbus_pass_message", False):
-                keywords = {"dbus_message": message}
-                handler(*args, **keywords)
-            else:
+                keywords["dbus_message"] = message
+
+            if len(keywords) == 0:
                 handler(*args)
+            else:
+                handler(*args, **keywords)
 
     def add_handler(self, handler):
         self.handler_functions.append(handler)



More information about the dbus-commit mailing list