dbus/python decorators.py, 1.6, 1.7 introspect_parser.py, 1.2, 1.3 service.py, 1.16, 1.17

Robert McQueen robot101 at freedesktop.org
Mon Nov 7 07:31:32 PST 2005


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

Modified Files:
	decorators.py introspect_parser.py service.py 
Log Message:
2005-11-07  Robert McQueen  <robot101 at debian.org>

	* python/decorators.py: Change emit_signal function to use the
	signature annotation of the signal when marhsalling the arguments from
	the service. Fix a bug where the code checking signature length
	against argument length referenced the wrong variable.

	* python/introspect_parser.py: Avoid adding the type signature of
	signal arguments to any methods which occur after them in the
	introspection data (!) by making the parser a little more careful
	about its current state.

	* python/service.py: Remove debug prints from last commit (again :D).

	* test/python/test-client.py, test/python/test-service.py: Add test
	signals with signature decorators to test the strict marshalling code
	gives errors at the right time. Could do with checking the signals
	actually get emitted too, given that the test does nothing with
	signals at the moment...

Index: decorators.py
===================================================================
RCS file: /cvs/dbus/dbus/python/decorators.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- decorators.py	4 Nov 2005 12:17:55 -0000	1.6
+++ decorators.py	7 Nov 2005 15:31:30 -0000	1.7
@@ -39,20 +39,25 @@
     _util._validate_interface_or_name(dbus_interface)
     def decorator(func):
         def emit_signal(self, *args, **keywords):
-            func(self, *args, **keywords)           
+            func(self, *args, **keywords)
             message = dbus_bindings.Signal(self._object_path, dbus_interface, func.__name__)
             iter = message.get_iter(True)
-           
-            for arg in args:
-                iter.append(arg)
-      
+
+            if emit_signal._dbus_signature:
+                signature = tuple(dbus_bindings.Signature(emit_signal._dbus_signature))
+                for (arg, sig) in zip(args, signature):
+                    iter.append_strict(arg, sig)
+            else:
+                for arg in args:
+                    iter.append(arg)
+
             self._connection.send(message)
 
         args = inspect.getargspec(func)[0]
         args.pop(0)
 
         if signature:
-            sig = tuple(dbus_bindings.Signature(func._dbus_signature))
+            sig = tuple(dbus_bindings.Signature(signature))
 
             if len(sig) > len(args):
                 raise ValueError, 'signal signature is longer than the number of arguments provided'

Index: introspect_parser.py
===================================================================
RCS file: /cvs/dbus/dbus/python/introspect_parser.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- introspect_parser.py	24 Oct 2005 18:29:50 -0000	1.2
+++ introspect_parser.py	7 Nov 2005 15:31:30 -0000	1.3
@@ -13,35 +13,36 @@
     reader = input_source.newTextReader("urn:introspect")
 
     ret = reader.Read()
-    current_iface=''
-    current_method=''
+    current_iface = None
+    current_method = None
     current_sigstr = ''
-    
+
     while ret == 1:
         name = reader.LocalName()
         if reader.NodeType() == XMLREADER_START_ELEMENT_NODE_TYPE:
-            if name == 'interface':
+            if (not current_iface and not current_method and name == 'interface'):
                 current_iface = reader.GetAttribute('name')
-            elif name == 'method':
+            elif (current_iface and not current_method and name == 'method'):
                 current_method = reader.GetAttribute('name')
                 if reader.IsEmptyElement():
-                    method_map[current_iface + '.' + current_method] = '' 
-                    current_method = ''
+                    method_map[current_iface + '.' + current_method] = ''
+                    current_method = None
                     current_sigstr = ''
-                    
-            elif name == 'arg':
+
+            elif (current_iface and current_method and name == 'arg'):
                 direction = reader.GetAttribute('direction')
 
                 if not direction or direction == 'in':
                     current_sigstr = current_sigstr + reader.GetAttribute('type')
 
         elif reader.NodeType() == XMLREADER_END_ELEMENT_NODE_TYPE:
-            if name == 'method':
-                method_map[current_iface + '.' + current_method] = current_sigstr 
-                current_method = ''
+            if (current_iface and not current_method and name == 'interface'):
+                current_iface = None
+            if (current_iface and current_method and name == 'method'):
+                method_map[current_iface + '.' + current_method] = current_sigstr
+                current_method = None
                 current_sigstr = ''
 
-         
         ret = reader.Read()
 
     if ret != 0:

Index: service.py
===================================================================
RCS file: /cvs/dbus/dbus/python/service.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- service.py	7 Nov 2005 12:14:53 -0000	1.16
+++ service.py	7 Nov 2005 15:31:30 -0000	1.17
@@ -20,21 +20,19 @@
 
         # otherwise register the name
         retval = dbus_bindings.bus_request_name(bus.get_connection(), name)
-        print retval
+
         # TODO: more intelligent tracking of bus name states?
         if retval == dbus_bindings.REQUEST_NAME_REPLY_PRIMARY_OWNER:
             pass
         elif retval == dbus_bindings.REQUEST_NAME_REPLY_IN_QUEUE:
             # you can't arrive at this state via the high-level bindings
             # because you can't put flags in, but... who knows?
-            print "joined queue for %s" % name
             pass
         elif retval == dbus_bindings.REQUEST_NAME_REPLY_EXISTS:
             raise dbus_bindings.DBusException('requested name %s already exists' % name)
         elif retval == dbus_bindings.REQUEST_NAME_REPLY_ALREADY_OWNER:
             # if this is a shared bus which is being used by someone
             # else in this process, this can happen legitimately
-            print "already owner of %s" % name
             pass
         else:
             raise dbus_bindings.DBusException('requesting name %s returned unexpected value %s' % (name, retval))



More information about the dbus-commit mailing list