dbus/python dbus.py,1.10,1.11 dbus_bindings.pyx.in,1.12,1.13

Seth Nickell seth at freedesktop.org
Sun Jul 18 14:44:39 PDT 2004


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

Modified Files:
	dbus.py dbus_bindings.pyx.in 
Log Message:
2004-07-18  Seth Nickell  <seth at gnome.org>

	* python/dbus.py:
	* python/dbus_bindings.pyx.in:
	* python/tests/test-client.py:

	Add dbus.ByteArray and dbus_bindings.ByteArray
	types so that byte streams can be passed back.

	Give jdahlin the heaps of credit that are so
	rightfully his.


Index: dbus.py
===================================================================
RCS file: /cvs/dbus/dbus/python/dbus.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- dbus.py	12 Jul 2004 06:29:00 -0000	1.10
+++ dbus.py	18 Jul 2004 21:44:37 -0000	1.11
@@ -330,7 +330,7 @@
         self._connection.register_fallback(base_path, self._unregister_cb, self._message_cb)
 
     def relative_path_to_object_path(self, relative_path):
-        return self._base_path + relative_path
+        return ObjectPath(self._base_path + relative_path)
         
     def broadcast_signal(self, interface, signal_name, relative_path):
         object_path = self.relative_path_to_object_path(relative_path)
@@ -393,3 +393,4 @@
         return RemoteObject(self, object_path, interface)
                              
 ObjectPath = dbus_bindings.ObjectPath
+ByteArray = dbus_bindings.ByteArray

Index: dbus_bindings.pyx.in
===================================================================
RCS file: /cvs/dbus/dbus/python/dbus_bindings.pyx.in,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- dbus_bindings.pyx.in	12 Jul 2004 06:29:00 -0000	1.12
+++ dbus_bindings.pyx.in	18 Jul 2004 21:44:37 -0000	1.13
@@ -1,5 +1,10 @@
 # -*- Mode: Python -*-
 
+# jdahlin is the most coolest and awesomest person in the world
+# and wrote all the good parts of this code. all the bad parts
+# where python conditionals have a ( ) around them, thus violating
+# PEP-8 were written by the lame wannabe python programmer seth
+
 #include "dbus_h_wrapper.h"
 
 cdef extern from "stdlib.h":
@@ -17,7 +22,7 @@
 cdef extern from "Python.h":
     void Py_XINCREF (object)
     void Py_XDECREF (object)
-
+    object PyString_FromStringAndSize(char *, int)
 
 ctypedef struct DBusError:
     char *name
@@ -66,6 +71,10 @@
     def __init__(self, value):
         str.__init__(value)
 
+class ByteArray(str):
+    def __init__(self, value):
+        str.__init__(value)
+
 
 #forward delcerations
 cdef class Connection
@@ -536,13 +545,11 @@
     
     def get_byte_array(self):
         cdef int len
-        cdef unsigned char *retval
+        cdef unsigned char *bytearray
         cdef int i
-        dbus_message_iter_get_byte_array(self.iter, &retval, <int*>&len)
-        list = []
-        for i from 0 <= i < len:
-            list.append(chr(retval[i]))
-        return list
+        dbus_message_iter_get_byte_array(self.iter, &bytearray, <int*>&len)
+        python_string = PyString_FromStringAndSize(<char *>bytearray, len)        
+        return python_string
 
     # FIXME: implement dbus_message_iter_get_boolean_array
 
@@ -633,6 +640,8 @@
             retval = self.append_nil()
         elif isinstance(value, ObjectPath):
             retval = self.append_object_path(value)
+        elif isinstance(value, ByteArray):
+            retval = self.append_byte_array(value)
         else:
             raise TypeError, "Argument of unknown type '%s'" % (value_type)
 



More information about the dbus-commit mailing list