summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@celebrin.pseudorandom.co.uk>2006-11-02 13:24:03 +0000
committerSimon McVittie <smcv@celebrin.pseudorandom.co.uk>2006-11-02 13:24:03 +0000
commit3ab7a818a7a7a92a15de50ef848318ca61a6d2df (patch)
tree90e3e09bfbdf25e8321fff14913313e201fd805b
parent263e3ad1cf99e7cd115e7051ed1ea3f2cc35c587 (diff)
Revert switch from Byte being an int subclass to a str subclass following discussion with J5.
Switching Byte to be a single-character string is arguably more Pythonic, but needlessly breaks API.
-rw-r--r--_dbus_bindings/bytes-impl.h154
-rw-r--r--_dbus_bindings/generic-impl.h20
-rw-r--r--_dbus_bindings/message-append-impl.h16
-rw-r--r--_dbus_bindings/message-get-args-impl.h6
-rw-r--r--_dbus_bindings/types-impl.h235
-rw-r--r--test/cross-test-client.py4
-rw-r--r--test/cross-test-server.py2
-rwxr-xr-xtest/test-standalone.py5
8 files changed, 313 insertions, 129 deletions
diff --git a/_dbus_bindings/bytes-impl.h b/_dbus_bindings/bytes-impl.h
index c9753a3..2983554 100644
--- a/_dbus_bindings/bytes-impl.h
+++ b/_dbus_bindings/bytes-impl.h
@@ -39,19 +39,15 @@ static inline int ByteArray_Check(PyObject *o)
PyDoc_STRVAR(Byte_tp_doc,
"Byte(integer or str of length 1)\n"
"\n"
-"Byte is a subtype of str, restricted to length exactly 1.\n"
+"Byte is a subtype of int, with range restricted to [0, 255].\n"
"\n"
-"A Byte b also supports the following operations:\n"
-"\n"
-"* int(b) == long(b) == float(b) == ord(b)\n"
-"\n"
-"* oct(b), hex(b)\n"
+"A Byte b may be converted to a str of length 1 via str(b) == chr(b).\n"
);
static inline unsigned char
Byte_as_uchar(PyObject *self)
{
- return (unsigned char) (PyString_AS_STRING (self)[0]);
+ return (unsigned char) (PyInt_AsLong (self));
}
PyObject *allocated_bytes[256] = {NULL};
@@ -62,13 +58,12 @@ Byte_from_uchar(unsigned char data)
PyObject *ret;
ret = allocated_bytes[data];
if (!ret) {
- char c[] = { (char)data, '\0' };
- PyObject *tuple = Py_BuildValue("(s#)", c, 1);
+ PyObject *tuple = Py_BuildValue("(i)", data);
DBG("Allocating a new Byte of value \\x%02x", data);
if (!tuple) return NULL;
- ret = PyString_Type.tp_new(&ByteType, tuple, NULL);
+ ret = PyInt_Type.tp_new(&ByteType, tuple, NULL);
Py_DECREF(tuple);
tuple = NULL;
@@ -88,8 +83,7 @@ Byte_from_uchar(unsigned char data)
static PyObject *
Byte_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
{
- PyObject *arg;
- PyObject *string;
+ PyObject *obj;
PyObject *tuple;
if (PyTuple_Size(args) != 1 || (kwargs && PyDict_Size(kwargs) != 0)) {
@@ -98,36 +92,31 @@ Byte_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
return NULL;
}
- /* arg is only a borrowed ref for the moment */
- arg = PyTuple_GetItem(args, 0);
+ /* obj is only a borrowed ref for the moment */
+ obj = PyTuple_GetItem(args, 0);
- if (PyString_Check(arg)) {
+ if (PyString_Check(obj)) {
/* string of length 1, we hope */
- if (PyString_GET_SIZE(arg) != 1) {
+ if (PyString_GET_SIZE(obj) != 1) {
goto bad_arg;
}
- if (arg->ob_type == &ByteType) {
- Py_INCREF(arg);
- return arg;
- }
+ /* here arg goes from a borrowed to owned reference */
+ obj = Byte_from_uchar((unsigned char)(PyString_AS_STRING(obj)[0]));
if (cls == &ByteType) {
- /* we know that the Byte type is the same as a string
- * internally, so fast-track it */
- return Byte_from_uchar((unsigned char)(PyString_AS_STRING(arg)[0]));
+ /* we know that the Byte type is the same as an int internally */
+ return obj;
}
- /* only a borrowed reference so far, take ownership */
- Py_INCREF(arg);
}
- else if (PyInt_Check(arg)) {
- long i = PyInt_AS_LONG(arg);
+ else if (PyInt_Check(obj)) {
+ long i = PyInt_AS_LONG(obj);
+ if (obj->ob_type == cls) {
+ Py_INCREF(obj);
+ return obj;
+ }
if (i < 0 || i > 255) goto bad_range;
- /* make a byte object, which is a length-1 string - now it's a new
- reference */
- arg = Byte_from_uchar((unsigned char)i);
- if (!arg) return NULL;
- /* if that's the type we wanted, there's nothing more to do */
- if (cls == &ByteType) return arg;
+ /* else make it a new reference */
+ Py_INCREF(obj);
}
else {
goto bad_arg;
@@ -136,17 +125,17 @@ Byte_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
/* so here's the complicated case: we're trying to instantiate a subclass
so we can't just allocate a Byte and go "it'll all be fine".
- By now, we do have a string-of-length-1 to use as an argument to the c'tor
+ By now, we do have an int (or Byte) to use as an argument to the c'tor.
*/
- tuple = Py_BuildValue("(O)", arg);
+ tuple = Py_BuildValue("(O)", obj);
if (!tuple) return NULL;
- Py_DECREF(arg);
- arg = NULL;
+ Py_DECREF(obj);
+ obj = NULL;
- string = PyString_Type.tp_new(cls, tuple, NULL);
+ obj = PyInt_Type.tp_new(cls, tuple, NULL);
Py_DECREF(tuple);
tuple = NULL;
- return string;
+ return obj;
bad_arg:
PyErr_SetString(PyExc_TypeError, "Expected a string of length 1, "
@@ -157,80 +146,13 @@ bad_range:
return NULL;
}
-static PyObject *Byte_nb_int (PyObject *self)
-{
- return PyInt_FromLong(Byte_as_uchar(self));
-}
-
-static PyObject *Byte_nb_float (PyObject *self)
-{
- return PyFloat_FromDouble(Byte_as_uchar(self));
-}
-
-static PyObject *Byte_nb_long (PyObject *self)
-{
- return PyLong_FromLong(Byte_as_uchar(self));
-}
-
-static PyObject *Byte_nb_oct (PyObject *self)
-{
- PyObject *i = PyInt_FromLong(Byte_as_uchar(self));
- if (!i) return NULL;
- PyObject *s = (i->ob_type->tp_as_number->nb_oct) (i);
- Py_XDECREF (i);
- return s;
-}
-
-static PyObject *Byte_nb_hex (PyObject *self)
+static PyObject *
+Byte_tp_str(PyObject *self)
{
- PyObject *i = PyInt_FromLong(Byte_as_uchar(self));
- if (!i) return NULL;
- PyObject *s = (i->ob_type->tp_as_number->nb_hex) (i);
- Py_XDECREF (i);
- return s;
+ char str[] = { (char)Byte_as_uchar(self), 0 };
+ return PyString_FromStringAndSize(str, 1);
}
-static PyNumberMethods Byte_tp_as_number = {
- 0, /* nb_add */
- 0, /* nb_subtract */
- 0, /* nb_multiply */
- 0, /* nb_divide */
- 0, /* nb_remainder */
- 0, /* nb_divmod */
- 0, /* nb_power */
- 0, /* nb_negative */
- 0, /* nb_positive */
- 0, /* nb_absolute */
- 0, /* nb_nonzero */
- 0, /* nb_invert */
- 0, /* nb_lshift */
- 0, /* nb_rshift */
- 0, /* nb_and */
- 0, /* nb_xor */
- 0, /* nb_or */
- 0, /* nb_coerce */
- (unaryfunc)Byte_nb_int, /* nb_int */
- (unaryfunc)Byte_nb_long, /* nb_long */
- (unaryfunc)Byte_nb_float, /* nb_float */
- (unaryfunc)Byte_nb_oct, /* nb_oct */
- (unaryfunc)Byte_nb_hex, /* nb_hex */
- 0, /* nb_inplace_add */
- 0, /* nb_inplace_subtract */
- 0, /* nb_inplace_multiply */
- 0, /* nb_inplace_divide */
- 0, /* nb_inplace_remainder */
- 0, /* nb_inplace_power */
- 0, /* nb_inplace_lshift */
- 0, /* nb_inplace_rshift */
- 0, /* nb_inplace_and */
- 0, /* nb_inplace_xor */
- 0, /* nb_inplace_or */
- 0, /* nb_floor_divide */
- 0, /* nb_true_divide */
- 0, /* nb_inplace_floor_divide */
- 0, /* nb_inplace_true_divide */
-};
-
static PyTypeObject ByteType = {
PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
0,
@@ -242,13 +164,13 @@ static PyTypeObject ByteType = {
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
- str_subclass_tp_repr, /* tp_repr */
- &Byte_tp_as_number,
+ int_subclass_tp_repr, /* tp_repr */
+ 0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
- 0, /* tp_str */
+ Byte_tp_str, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
@@ -263,7 +185,7 @@ static PyTypeObject ByteType = {
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
- DEFERRED_ADDRESS(&PyString_Type), /* tp_base */
+ DEFERRED_ADDRESS(&PyInt_Type), /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
@@ -391,10 +313,8 @@ static PyTypeObject ByteArrayType = {
static inline int
init_byte_types(void)
{
- ByteType.tp_base = &PyString_Type;
+ ByteType.tp_base = &PyInt_Type;
if (PyType_Ready(&ByteType) < 0) return 0;
- /* disable the tp_print copied from PyString_Type, so tp_repr gets called as
- desired */
ByteType.tp_print = NULL;
ByteArrayType.tp_base = &PyString_Type;
diff --git a/_dbus_bindings/generic-impl.h b/_dbus_bindings/generic-impl.h
index 71fbafe..d12f8f7 100644
--- a/_dbus_bindings/generic-impl.h
+++ b/_dbus_bindings/generic-impl.h
@@ -67,6 +67,26 @@ long_subclass_tp_repr(PyObject *self)
return my_repr;
}
+/* A generic repr() implementation for float subclasses, returning something
+ * like 'dbus.Double(123)'.
+ * Equivalent to the following Python:
+ * def __repr__(self):
+ * return '%s(%r)' % (self.__class__, float.__repr__(self))
+ */
+static PyObject *
+float_subclass_tp_repr(PyObject *self)
+{
+ PyObject *parent_repr = (PyFloat_Type.tp_repr)(self);
+ PyObject *my_repr;
+
+ if (!parent_repr) return NULL;
+ my_repr = PyString_FromFormat("%s(%s)", self->ob_type->tp_name,
+ PyString_AS_STRING(parent_repr));
+ /* whether my_repr is NULL or not: */
+ Py_DECREF(parent_repr);
+ return my_repr;
+}
+
/* A generic repr() implementation for str subclasses, returning something
* like "dbus.ObjectPath('/foo/bar')".
* Equivalent to the following Python:
diff --git a/_dbus_bindings/message-append-impl.h b/_dbus_bindings/message-append-impl.h
index d20caa5..9364255 100644
--- a/_dbus_bindings/message-append-impl.h
+++ b/_dbus_bindings/message-append-impl.h
@@ -63,7 +63,7 @@ PyDoc_STRVAR(Message_guess_signature__doc__,
"=============================== ===========================\n"
"Python D-Bus\n"
"=============================== ===========================\n"
-"bool boolean (y)\n"
+"bool or dbus.Boolean boolean (y)\n"
"dbus.Int16, etc. the corresponding type\n"
"any other int subclass int32 (i) (FIXME: make this error?)\n"
"long or a subclass int64 (x) (FIXME: make this error?)\n"
@@ -97,6 +97,8 @@ _signature_string_from_pyobject(PyObject *obj)
return PyString_FromString(DBUS_TYPE_INT32_AS_STRING);
else if (UInt16_Check(obj))
return PyString_FromString(DBUS_TYPE_UINT16_AS_STRING);
+ else if (Boolean_Check(obj))
+ return PyString_FromString(DBUS_TYPE_BOOLEAN_AS_STRING);
else
return PyString_FromString(DBUS_TYPE_INT32_AS_STRING);
}
@@ -112,8 +114,16 @@ _signature_string_from_pyobject(PyObject *obj)
}
else if (PyUnicode_Check(obj))
return PyString_FromString(DBUS_TYPE_STRING_AS_STRING);
- else if (PyFloat_Check(obj))
- return PyString_FromString(DBUS_TYPE_DOUBLE_AS_STRING);
+ else if (PyFloat_Check(obj)) {
+#ifdef WITH_DBUS_FLOAT32
+ if (Double_Check(obj))
+ return PyString_FromString(DBUS_TYPE_DOUBLE_AS_STRING);
+ else if (Float_Check(obj))
+ return PyString_FromString(DBUS_TYPE_FLOAT_AS_STRING);
+ else
+#endif
+ return PyString_FromString(DBUS_TYPE_DOUBLE_AS_STRING);
+ }
else if (Variant_Check(obj)) {
return PyString_FromString(DBUS_TYPE_VARIANT_AS_STRING);
}
diff --git a/_dbus_bindings/message-get-args-impl.h b/_dbus_bindings/message-get-args-impl.h
index 818c2be..184e0af 100644
--- a/_dbus_bindings/message-get-args-impl.h
+++ b/_dbus_bindings/message-get-args-impl.h
@@ -59,7 +59,7 @@ PyDoc_STRVAR(Message_get_args_list__doc__,
"D-Bus Python\n"
"=============== ===================================================\n"
"byte (y) Byte (int if integer_bytes set)\n"
-"bool (b) bool\n"
+"bool (b) Boolean (int subclass)\n"
"Signature (g) Signature (str subclass)\n"
"intNN, uintNN IntNN, UIntNN (int/long subclass)\n"
" (int/long if untyped_integers set)\n"
@@ -167,7 +167,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
case DBUS_TYPE_DOUBLE:
DBG("%s", "found a double");
dbus_message_iter_get_basic(iter, &u.d);
- return PyFloat_FromDouble(u.d);
+ return Double_from_double(u.d);
case DBUS_TYPE_INT16:
DBG("%s", "found an int16");
@@ -239,7 +239,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
case DBUS_TYPE_BOOLEAN:
DBG("%s", "found a bool");
dbus_message_iter_get_basic(iter, &u.b);
- return PyBool_FromLong(u.b);
+ return Boolean_from_long(u.b);
case DBUS_TYPE_ARRAY:
DBG("%s", "found an array...");
diff --git a/_dbus_bindings/types-impl.h b/_dbus_bindings/types-impl.h
index 8dea61a..b5f9b2d 100644
--- a/_dbus_bindings/types-impl.h
+++ b/_dbus_bindings/types-impl.h
@@ -28,7 +28,11 @@
static PyTypeObject Int16Type, Int32Type, Int64Type;
static PyTypeObject UInt16Type, UInt32Type, UInt64Type;
-static PyTypeObject ObjectPathType;
+static PyTypeObject ObjectPathType, BooleanType;
+static PyTypeObject DoubleType;
+#ifdef WITH_DBUS_FLOAT32
+static PyTypeObject FloatType;
+#endif
#define DEFINE_CHECK(type) \
static inline int type##_Check (PyObject *o) \
@@ -43,12 +47,20 @@ DEFINE_CHECK(UInt16)
DEFINE_CHECK(UInt32)
DEFINE_CHECK(UInt64)
DEFINE_CHECK(ObjectPath)
+DEFINE_CHECK(Double)
+DEFINE_CHECK(Boolean)
+#ifdef WITH_DBUS_FLOAT32
+DEFINE_CHECK(Float)
+#endif
#undef DEFINE_CHECK
/* The Int and UInt types are nice and simple.
FIXME: use Python int as base for UInt32 and Int64 on 64-bit platforms?
*/
+PyDoc_STRVAR(Boolean_tp_doc,
+"A boolean (a subtype of int).");
+
PyDoc_STRVAR(Int16_tp_doc,
"A signed 16-bit integer (a subtype of int).");
@@ -67,6 +79,90 @@ PyDoc_STRVAR(Int64_tp_doc,
PyDoc_STRVAR(UInt64_tp_doc,
"An unsigned 64-bit integer (a subtype of long).");
+PyDoc_STRVAR(Double_tp_doc,
+"A double-precision floating point number (a subtype of float).");
+
+#ifdef WITH_DBUS_FLOAT32
+PyDoc_STRVAR(Float_tp_doc,
+"A single-precision floating point number (a subtype of float).");
+#endif
+
+static PyObject *
+Boolean_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
+{
+ PyObject *tuple, *self;
+ int i;
+ static char *argnames[] = {"value", NULL};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i:__new__", argnames,
+ &i)) return NULL;
+ tuple = Py_BuildValue("(i)", i ? 1 : 0);
+ if (!tuple) return NULL;
+ self = (PyInt_Type.tp_new)(cls, tuple, NULL);
+ Py_DECREF(tuple);
+ return self;
+}
+
+static PyObject *
+Boolean_from_long(long b)
+{
+ PyObject *self;
+ PyObject *tuple = Py_BuildValue("(i)", b ? 1 : 0);
+ if (!tuple) return NULL;
+ self = (PyInt_Type.tp_new)(&BooleanType, tuple, NULL);
+ Py_DECREF(tuple);
+ return self;
+}
+
+static PyObject *
+Boolean_tp_repr (PyObject *self)
+{
+ return PyString_FromFormat("%s(%s)", self->ob_type->tp_name,
+ PyInt_AsLong(self) ? "True" : "False");
+}
+
+static PyTypeObject BooleanType = {
+ PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
+ 0,
+ "dbus.Boolean",
+ 0,
+ 0,
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ Boolean_tp_repr, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Boolean_tp_doc, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ DEFERRED_ADDRESS(&PyInt_Type), /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ Boolean_tp_new, /* tp_new */
+};
+
static dbus_int16_t
int16_range_check(PyObject *obj)
{
@@ -492,6 +588,116 @@ static PyTypeObject UInt64Type = {
#endif /* defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG) */
+/* Float types ====================================================== */
+
+static PyObject *
+Double_from_double(double d)
+{
+ PyObject *self;
+ PyObject *tuple = Py_BuildValue("(f)", d);
+ if (!tuple) return NULL;
+ self = (PyFloat_Type.tp_new)(&DoubleType, tuple, NULL);
+ Py_DECREF(tuple);
+ return self;
+}
+
+static PyTypeObject DoubleType = {
+ PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
+ 0,
+ "dbus.Double",
+ 0,
+ 0,
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ float_subclass_tp_repr, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Double_tp_doc, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ DEFERRED_ADDRESS(&PyFloat_Type), /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
+};
+
+#ifdef WITH_DBUS_FLOAT32
+static PyObject *
+Float_from_double(double d)
+{
+ PyObject *self;
+ PyObject *tuple = Py_BuildValue("(f)", d);
+ if (!tuple) return NULL;
+ self = (PyFloat_Type.tp_new)(&DoubleType, tuple, NULL);
+ Py_DECREF(tuple);
+ return self;
+}
+
+static PyTypeObject FloatType = {
+ PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
+ 0,
+ "dbus.Float",
+ 0,
+ 0,
+ 0, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ float_subclass_tp_repr, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Float_tp_doc, /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ DEFERRED_ADDRESS(&PyFloat_Type), /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
+};
+#endif /* defined(WITH_DBUS_FLOAT32) */
+
/* Object path ====================================================== */
PyDoc_STRVAR(ObjectPath_tp_doc,
@@ -600,6 +806,20 @@ init_types(void)
if (PyType_Ready(&ObjectPathType) < 0) return 0;
ObjectPathType.tp_print = NULL;
+ BooleanType.tp_base = &PyInt_Type;
+ if (PyType_Ready(&BooleanType) < 0) return 0;
+ BooleanType.tp_print = NULL;
+
+ DoubleType.tp_base = &PyFloat_Type;
+ if (PyType_Ready(&DoubleType) < 0) return 0;
+ DoubleType.tp_print = NULL;
+
+#ifdef WITH_DBUS_FLOAT32
+ FloatType.tp_base = &PyFloat_Type;
+ if (PyType_Ready(&FloatType) < 0) return 0;
+ FloatType.tp_print = NULL;
+#endif
+
return 1;
}
@@ -612,6 +832,11 @@ insert_types(PyObject *this_module)
Py_INCREF(&UInt32Type);
Py_INCREF(&Int64Type);
Py_INCREF(&UInt64Type);
+ Py_INCREF(&BooleanType);
+#ifdef WITH_DBUS_FLOAT32
+ Py_INCREF(&FloatType);
+#endif
+ Py_INCREF(&DoubleType);
if (PyModule_AddObject(this_module, "Int16",
(PyObject *)&Int16Type) < 0) return 0;
if (PyModule_AddObject(this_module, "UInt16",
@@ -624,6 +849,14 @@ insert_types(PyObject *this_module)
(PyObject *)&Int64Type) < 0) return 0;
if (PyModule_AddObject(this_module, "UInt64",
(PyObject *)&UInt64Type) < 0) return 0;
+ if (PyModule_AddObject(this_module, "Boolean",
+ (PyObject *)&BooleanType) < 0) return 0;
+#ifdef WITH_DBUS_FLOAT32
+ if (PyModule_AddObject(this_module, "Float",
+ (PyObject *)&FloatType) < 0) return 0;
+#endif
+ if (PyModule_AddObject(this_module, "Double",
+ (PyObject *)&DoubleType) < 0) return 0;
Py_INCREF(&ObjectPathType);
if (PyModule_AddObject(this_module, "ObjectPath",
diff --git a/test/cross-test-client.py b/test/cross-test-client.py
index 1bf21ec..7a92041 100644
--- a/test/cross-test-client.py
+++ b/test/cross-test-client.py
@@ -253,9 +253,9 @@ class Client(SignalTestsImpl):
self.assert_method_eq(INTERFACE_TESTS, [Variant(Int32(1)),Variant(Int32(2)),Variant(Int32(3))], 'IdentityArray', [Int32(1),Int32(2),Int32(3)])
self.assert_method_eq(INTERFACE_TESTS, [Variant(u'a'),Variant(u'b'),Variant(u'c')], 'IdentityArray', ['a','b','c'])
- self.assert_method_eq(INTERFACE_TESTS, ['\x01','\x02','\x03'], 'IdentityByteArray', ByteArray('\x01\x02\x03'))
+ self.assert_method_eq(INTERFACE_TESTS, [1,2,3], 'IdentityByteArray', ByteArray('\x01\x02\x03'))
if have_signatures:
- self.assert_method_eq(INTERFACE_TESTS, ['\x01','\x02','\x03'], 'IdentityByteArray', ['\x01', '\x02', '\x03'])
+ self.assert_method_eq(INTERFACE_TESTS, [1,2,3], 'IdentityByteArray', ['\x01', '\x02', '\x03'])
self.assert_method_eq(INTERFACE_TESTS, [False,True], 'IdentityBoolArray', [False,True])
if have_signatures:
self.assert_method_eq(INTERFACE_TESTS, [False,True,True], 'IdentityBoolArray', [0,1,2])
diff --git a/test/cross-test-server.py b/test/cross-test-server.py
index 2d0365a..474dd5f 100644
--- a/test/cross-test-server.py
+++ b/test/cross-test-server.py
@@ -88,7 +88,7 @@ class SingleTestsImpl(dbus.service.Object):
@dbus.service.method(INTERFACE_SINGLE_TESTS, 'ay', 'u')
def Sum(self, input):
tested_things.add(INTERFACE_SINGLE_TESTS + '.Sum')
- u = sum(map(ord, input))
+ u = sum(input)
logger.info('Sum of %r is %r', input, u)
return u
diff --git a/test/test-standalone.py b/test/test-standalone.py
index e447dde..2697cb3 100755
--- a/test/test-standalone.py
+++ b/test/test-standalone.py
@@ -158,8 +158,9 @@ class TestMessageMarshalling(unittest.TestCase):
aeq = self.assertEquals
s = _dbus_bindings.SignalMessage('/', 'foo.bar', 'baz')
s.append('b', 'bytes', -1, 1, 'str', 'var', signature='yayiusv')
- aeq(s.get_args_list(), ['b', ['b','y','t','e','s'], -1, 1,
- u'str', types.Variant(u'var', signature='s')])
+ aeq(s.get_args_list(), [ord('b'),
+ [ord('b'),ord('y'),ord('t'),ord('e'), ord('s')],
+ -1, 1, u'str', types.Variant(u'var', signature='s')])
byte, bytes, int32, uint32, string, variant = s.get_args_list()
aeq(byte.__class__, types.Byte)
aeq(bytes.__class__, types.Array)