dbus/python dbus_bindings.pyx.in,1.3,1.4

David Zeuthen david@pdx.freedesktop.org
Tue, 28 Oct 2003 16:06:09 -0800


Update of /cvs/dbus/dbus/python
In directory pdx:/tmp/cvs-serv3011/python

Modified Files:
	dbus_bindings.pyx.in 
Log Message:
2003-10-28  David Zeuthen  <david@fubar.dk>
 
        * python/dbus_bindings.pyx.in: add get_dict to handle dictionaries
        return types. Fixup TYPE_* to reflect changes in dbus/dbus-protocol.h



Index: dbus_bindings.pyx.in
===================================================================
RCS file: /cvs/dbus/dbus/python/dbus_bindings.pyx.in,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dbus_bindings.pyx.in	15 Oct 2003 21:25:13 -0000	1.3
+++ dbus_bindings.pyx.in	29 Oct 2003 00:06:07 -0000	1.4
@@ -428,10 +428,33 @@
                 retval = self.get_boolean_array()
             else:
                 raise TypeError, "Unknown array type %d in MessageIter" % (array_type)
+        elif arg_type == TYPE_DICT:
+            retval = self.get_dict()
         else:
             raise TypeError, 'Unknown arg type %d in MessageIter' % (arg_type)
 
         return retval
+
+    def get_dict(self):
+        cdef DBusMessageIter dict_iter
+        cdef DBusMessageIter* old_iter
+
+        dict = {}
+        dbus_message_iter_init_dict_iterator(self.iter, &dict_iter)
+        # FIXME: nasty hack so we can use existing self.get() method
+        old_iter = self.iter
+        self.iter = &dict_iter
+
+        while True:
+            key = self.get_dict_key()
+            value = self.get()
+            dict[key] = value
+            if not self.has_next():
+                break
+            self.next()
+
+        self.iter = old_iter
+        return dict
     
     def get_arg_type(self):
         return dbus_message_iter_get_arg_type(self.iter)
@@ -569,7 +592,7 @@
 
     
 (MESSAGE_TYPE_INVALID, MESSAGE_TYPE_METHOD_CALL, MESSAGE_TYPE_METHOD_RETURN, MESSAGE_TYPE_ERROR, MESSAGE_TYPE_SIGNAL) = range(5)
-(TYPE_INVALID, TYPE_NIL, TYPE_BYTE, TYPE_BOOLEAN, TYPE_INT32, TYPE_UINT32, TYPE_INT64, TYPE_UINT64, TYPE_DOUBLE, TYPE_STRING, TYPE_NAMED, TYPE_ARRAY, TYPE_DICT, TYPE_OBJECT_PATH) = (0, 118, 121, 98, 105, 117, 120, 116, 100, 115, 110, 97, 99, 111)
+(TYPE_INVALID, TYPE_NIL, TYPE_BYTE, TYPE_BOOLEAN, TYPE_INT32, TYPE_UINT32, TYPE_INT64, TYPE_UINT64, TYPE_DOUBLE, TYPE_STRING, TYPE_CUSTOM, TYPE_ARRAY, TYPE_DICT, TYPE_OBJECT_PATH) = (0, ord('v'), ord('y'), ord('b'), ord('i'), ord('u'), ord('x'), ord('t'), ord('d'), ord('s'), ord('c'), ord('a'), ord('m'), ord('o'))
     
 cdef class Message:
     cdef DBusMessage *msg