diff -up dbus-python-0.83.0/_dbus_bindings/abstract.c.p2to3 dbus-python-0.83.0/_dbus_bindings/abstract.c --- dbus-python-0.83.0/_dbus_bindings/abstract.c.p2to3 2008-07-23 11:35:58.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/abstract.c 2010-02-03 17:42:25.000000000 -0500 @@ -30,6 +30,7 @@ #include "dbus_bindings-internal.h" #include "types-internal.h" +#include "python-2to3-macros.h" /* Dict indexed by object IDs, whose values are nonzero variant levels * for immutable variable-sized D-Bus data types (_LongBase, _StrBase, Struct). @@ -54,7 +55,7 @@ dbus_py_variant_level_get(PyObject *obj) if (!vl_obj) return 0; - return PyInt_AsLong(vl_obj); + return PyLong_AsLong(vl_obj); } dbus_bool_t @@ -76,7 +77,7 @@ dbus_py_variant_level_set(PyObject *obj, } } else { - PyObject *vl_obj = PyInt_FromLong(variant_level); + PyObject *vl_obj = PyLong_FromLong(variant_level); if (!vl_obj) { Py_DECREF(key); return FALSE; @@ -95,7 +96,7 @@ dbus_py_variant_level_getattro(PyObject { PyObject *key, *value; - if (PyString_Check(name)) { + if (PyBytes_Check(name)) { Py_INCREF(name); } else if (PyUnicode_Check(name)) { @@ -109,7 +110,7 @@ dbus_py_variant_level_getattro(PyObject return NULL; } - if (strcmp(PyString_AS_STRING(name), "variant_level")) { + if (strcmp(PyBytes_AS_STRING(name), "variant_level")) { value = PyObject_GenericGetAttr(obj, name); Py_DECREF(name); return value; @@ -127,7 +128,7 @@ dbus_py_variant_level_getattro(PyObject Py_DECREF(key); if (!value) - return PyInt_FromLong(0); + return PyLong_FromLong(0); Py_INCREF(value); return value; } @@ -184,7 +185,7 @@ DBusPythonInt_tp_new(PyTypeObject *cls, return NULL; } - self = (PyInt_Type.tp_new)(cls, args, NULL); + self = (PyLong_Type.tp_new)(cls, args, NULL); if (self) { ((DBusPyIntBase *)self)->variant_level = variantness; } @@ -194,20 +195,20 @@ DBusPythonInt_tp_new(PyTypeObject *cls, static PyObject * DBusPythonInt_tp_repr(PyObject *self) { - PyObject *parent_repr = (PyInt_Type.tp_repr)(self); + PyObject *parent_repr = (PyLong_Type.tp_repr)(self); long variant_level = ((DBusPyIntBase *)self)->variant_level; PyObject *my_repr; if (!parent_repr) return NULL; if (variant_level > 0) { - my_repr = PyString_FromFormat("%s(%s, variant_level=%ld)", + my_repr = PyUnicode_FromFormat("%s(%u, variant_level=%ld)", self->ob_type->tp_name, - PyString_AS_STRING(parent_repr), + parent_repr, variant_level); } else { - my_repr = PyString_FromFormat("%s(%s)", self->ob_type->tp_name, - PyString_AS_STRING(parent_repr)); + my_repr = PyUnicode_FromFormat("%s(%u)", self->ob_type->tp_name, + parent_repr); } /* whether my_repr is NULL or not: */ Py_DECREF(parent_repr); @@ -215,8 +216,7 @@ DBusPythonInt_tp_repr(PyObject *self) } PyTypeObject DBusPyIntBase_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "_dbus_bindings._IntBase", sizeof(DBusPyIntBase), 0, @@ -312,14 +312,14 @@ DBusPythonFloat_tp_repr(PyObject *self) if (!parent_repr) return NULL; if (variant_level > 0) { - my_repr = PyString_FromFormat("%s(%s, variant_level=%ld)", + my_repr = PyUnicode_FromFormat("%s(%s, variant_level=%ld)", self->ob_type->tp_name, - PyString_AS_STRING(parent_repr), + parent_repr, variant_level); } else { - my_repr = PyString_FromFormat("%s(%s)", self->ob_type->tp_name, - PyString_AS_STRING(parent_repr)); + my_repr = PyUnicode_FromFormat("%s(%u)", self->ob_type->tp_name, + parent_repr); } /* whether my_repr is NULL or not: */ Py_DECREF(parent_repr); @@ -327,8 +327,7 @@ DBusPythonFloat_tp_repr(PyObject *self) } PyTypeObject DBusPyFloatBase_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "_dbus_bindings._FloatBase", sizeof(DBusPyFloatBase), 0, @@ -396,7 +395,7 @@ DBusPythonString_tp_new(PyTypeObject *cl return NULL; } - self = (PyString_Type.tp_new)(cls, args, NULL); + self = (PyUnicode_Type.tp_new)(cls, args, NULL); if (self) { if (!dbus_py_variant_level_set(self, variantness)) { Py_DECREF(self); @@ -409,7 +408,7 @@ DBusPythonString_tp_new(PyTypeObject *cl static PyObject * DBusPythonString_tp_repr(PyObject *self) { - PyObject *parent_repr = (PyString_Type.tp_repr)(self); + PyObject *parent_repr = (PyUnicode_Type.tp_repr)(self); PyObject *vl_obj; PyObject *my_repr; long variant_level; @@ -420,17 +419,17 @@ DBusPythonString_tp_repr(PyObject *self) Py_DECREF(parent_repr); return NULL; } - variant_level = PyInt_AsLong(vl_obj); + variant_level = PyLong_AsLong(vl_obj); Py_DECREF(vl_obj); if (variant_level > 0) { - my_repr = PyString_FromFormat("%s(%s, variant_level=%ld)", + my_repr = PyUnicode_FromFormat("%s(%u, variant_level=%ld)", self->ob_type->tp_name, - PyString_AS_STRING(parent_repr), + parent_repr, variant_level); } else { - my_repr = PyString_FromFormat("%s(%s)", self->ob_type->tp_name, - PyString_AS_STRING(parent_repr)); + my_repr = PyUnicode_FromFormat("%s(%u)", self->ob_type->tp_name, + parent_repr); } /* whether my_repr is NULL or not: */ Py_DECREF(parent_repr); @@ -441,12 +440,11 @@ static void DBusPyStrBase_tp_dealloc(PyObject *self) { dbus_py_variant_level_clear(self); - (PyString_Type.tp_dealloc)(self); + (PyBytes_Type.tp_dealloc)(self); } PyTypeObject DBusPyStrBase_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "_dbus_bindings._StrBase", 0, 0, @@ -476,7 +474,7 @@ PyTypeObject DBusPyStrBase_Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&PyString_Type), /* tp_base */ + DEFERRED_ADDRESS(&PyBytes_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -538,17 +536,17 @@ DBusPythonLong_tp_repr(PyObject *self) Py_DECREF(parent_repr); return NULL; } - variant_level = PyInt_AsLong(vl_obj); + variant_level = PyLong_AsLong(vl_obj); Py_DECREF(vl_obj); if (variant_level) { - my_repr = PyString_FromFormat("%s(%s, variant_level=%ld)", + my_repr = PyUnicode_FromFormat("%s(%u, variant_level=%ld)", self->ob_type->tp_name, - PyString_AS_STRING(parent_repr), + parent_repr, variant_level); } else { - my_repr = PyString_FromFormat("%s(%s)", self->ob_type->tp_name, - PyString_AS_STRING(parent_repr)); + my_repr = PyUnicode_FromFormat("%s(%u)", self->ob_type->tp_name, + parent_repr); } /* whether my_repr is NULL or not: */ Py_DECREF(parent_repr); @@ -563,8 +561,7 @@ DBusPyLongBase_tp_dealloc(PyObject *self } PyTypeObject DBusPyLongBase_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "_dbus_bindings._LongBase", 0, 0, @@ -614,16 +611,16 @@ dbus_py_init_abstract(void) _dbus_py_variant_levels = PyDict_New(); if (!_dbus_py_variant_levels) return 0; - dbus_py__dbus_object_path__const = PyString_InternFromString("__dbus_object_path__"); + dbus_py__dbus_object_path__const = PyBytes_InternFromString("__dbus_object_path__"); if (!dbus_py__dbus_object_path__const) return 0; - dbus_py_variant_level_const = PyString_InternFromString("variant_level"); + dbus_py_variant_level_const = PyBytes_InternFromString("variant_level"); if (!dbus_py_variant_level_const) return 0; - dbus_py_signature_const = PyString_InternFromString("signature"); + dbus_py_signature_const = PyBytes_InternFromString("signature"); if (!dbus_py_signature_const) return 0; - DBusPyIntBase_Type.tp_base = &PyInt_Type; + DBusPyIntBase_Type.tp_base = &PyLong_Type; if (PyType_Ready(&DBusPyIntBase_Type) < 0) return 0; /* disable the tp_print copied from PyInt_Type, so tp_repr gets called as desired */ @@ -637,7 +634,8 @@ dbus_py_init_abstract(void) if (PyType_Ready(&DBusPyLongBase_Type) < 0) return 0; DBusPyLongBase_Type.tp_print = NULL; - DBusPyStrBase_Type.tp_base = &PyString_Type; + DBusPyStrBase_Type.tp_base = &PyBytes_Type; + if (PyType_Ready(&DBusPyStrBase_Type) < 0) return 0; DBusPyStrBase_Type.tp_print = NULL; diff -up dbus-python-0.83.0/_dbus_bindings/bus.c.p2to3 dbus-python-0.83.0/_dbus_bindings/bus.c --- dbus-python-0.83.0/_dbus_bindings/bus.c.p2to3 2008-07-17 08:07:24.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/bus.c 2010-02-03 17:42:25.000000000 -0500 @@ -62,7 +62,7 @@ DBusPyConnection_NewForBus(PyTypeObject return (PyObject *)self; } - else if (!first || PyInt_Check(first)) { + else if (!first || PyLong_Check(first)) { long type; PyObject *libdbusconn; PyObject *new_args; @@ -73,7 +73,7 @@ DBusPyConnection_NewForBus(PyTypeObject DBUS_BUS_SESSION. */ if (first) { - type = PyInt_AsLong(first); + type = PyLong_AsLong(first); if (type != DBUS_BUS_SESSION && type != DBUS_BUS_SYSTEM && type != DBUS_BUS_STARTER) { diff -up dbus-python-0.83.0/_dbus_bindings/bytes.c.p2to3 dbus-python-0.83.0/_dbus_bindings/bytes.c --- dbus-python-0.83.0/_dbus_bindings/bytes.c.p2to3 2008-07-23 11:35:58.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/bytes.c 2010-02-03 17:42:25.000000000 -0500 @@ -30,6 +30,7 @@ #include "dbus_bindings-internal.h" #include "types-internal.h" +#include "python-2to3-macros.h" PyDoc_STRVAR(Byte_tp_doc, "An unsigned byte: a subtype of int, with range restricted to [0, 255].\n" @@ -79,15 +80,15 @@ Byte_new(PyTypeObject *cls, PyObject *ar /* obj is only a borrowed ref for the moment */ obj = PyTuple_GetItem(args, 0); - if (PyString_Check(obj)) { + if (PyBytes_Check(obj)) { /* string of length 1, we hope */ - if (PyString_GET_SIZE(obj) != 1) { + if (PyBytes_GET_SIZE(obj) != 1) { goto bad_arg; } - obj = PyInt_FromLong((unsigned char)(PyString_AS_STRING(obj)[0])); + obj = PyLong_FromLong((unsigned char)(PyBytes_AS_STRING(obj)[0])); } - else if (PyInt_Check(obj)) { - long i = PyInt_AS_LONG(obj); + else if (PyLong_Check(obj)) { + long i = PyLong_AS_LONG(obj); if (obj->ob_type == cls && ((DBusPyIntBase *)obj)->variant_level == variantness) { @@ -124,13 +125,12 @@ bad_range: static PyObject * Byte_tp_str(PyObject *self) { - unsigned char str[2] = { (unsigned char)PyInt_AS_LONG(self), 0 }; - return PyString_FromStringAndSize((char *)str, 1); + unsigned char str[2] = { (unsigned char)PyLong_AS_LONG(self), 0 }; + return PyUnicode_FromStringAndSize((char *)str, 1); } PyTypeObject DBusPyByte_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.Byte", 0, 0, @@ -196,8 +196,7 @@ PyDoc_STRVAR(ByteArray_tp_doc, ); PyTypeObject DBusPyByteArray_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.ByteArray", 0, 0, diff -up dbus-python-0.83.0/_dbus_bindings/conn.c.p2to3 dbus-python-0.83.0/_dbus_bindings/conn.c --- dbus-python-0.83.0/_dbus_bindings/conn.c.p2to3 2008-07-17 08:07:24.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/conn.c 2010-02-03 17:42:25.000000000 -0500 @@ -26,6 +26,7 @@ #include "dbus_bindings-internal.h" #include "conn-internal.h" +#include "python-2to3-macros.h" /* Connection definition ============================================ */ @@ -99,7 +100,7 @@ DBusPyConnection_HandleMessage(Connectio return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } else { - long i = PyInt_AsLong(obj); + long i = PyLong_AsLong(obj); DBG("%p: handler %p returned %ld", conn, callable, i); Py_DECREF(obj); if (i == -1 && PyErr_Occurred()) { @@ -317,23 +318,42 @@ Connection_tp_new(PyTypeObject *cls, PyO conn = dbus_connection_ref (wrapper->conn); } - else if ((address = PyString_AsString(address_or_conn)) != NULL) { - dbus_error_init(&error); + else { + if (PyBytes_Check(address_or_conn)) { + Py_INCREF(address_or_conn); + } + else if (PyUnicode_Check(address_or_conn)) { + address_or_conn = PyUnicode_AsUTF8String(address_or_conn); + if (!address_or_conn) { + return NULL; + } + } + else { + PyErr_SetString(PyExc_TypeError, "address must be a string or connection"); + return NULL; + } - /* We always open a private connection (at the libdbus level). Sharing - * is done in Python, to keep things simple. */ - Py_BEGIN_ALLOW_THREADS - conn = dbus_connection_open_private(address, &error); - Py_END_ALLOW_THREADS + if ((address = PyBytes_AS_STRING(address_or_conn)) != NULL) { + dbus_error_init(&error); - if (!conn) { - DBusPyException_ConsumeError(&error); + /* We always open a private connection (at the libdbus level). Sharing + * is done in Python, to keep things simple. */ + Py_BEGIN_ALLOW_THREADS + conn = dbus_connection_open_private(address, &error); + Py_END_ALLOW_THREADS + + Py_DECREF(address_or_conn); + + if (!conn) { + DBusPyException_ConsumeError(&error); + return NULL; + } + } + else { + Py_DECREF(address_or_conn); return NULL; } } - else { - return NULL; - } self = DBusPyConnection_NewConsumingDBusConnection(cls, conn, mainloop); TRACE(self); @@ -389,14 +409,13 @@ static void Connection_tp_dealloc(Connec DBG("Connection at %p: freeing self", self); PyErr_Restore(et, ev, etb); - (self->ob_type->tp_free)((PyObject *)self); + (Py_TYPE(self)->tp_free)((PyObject *)self); } /* Connection type object =========================================== */ PyTypeObject DBusPyConnection_Type = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/ "_dbus_bindings.Connection", /*tp_name*/ sizeof(Connection), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -416,7 +435,7 @@ PyTypeObject DBusPyConnection_Type = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS | Py_TPFLAGS_BASETYPE, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, Connection_tp_doc, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ diff -up dbus-python-0.83.0/_dbus_bindings/containers.c.p2to3 dbus-python-0.83.0/_dbus_bindings/containers.c --- dbus-python-0.83.0/_dbus_bindings/containers.c.p2to3 2008-07-23 11:35:58.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/containers.c 2010-02-03 17:42:25.000000000 -0500 @@ -30,6 +30,7 @@ #include "dbus_bindings-internal.h" #include "types-internal.h" +#include "python-2to3-macros.h" /* Array ============================================================ */ @@ -93,18 +94,18 @@ Array_tp_repr(DBusPyArray *self) if (!parent_repr) goto finally; if (!sig_repr) goto finally; if (variant_level > 0) { - my_repr = PyString_FromFormat("%s(%s, signature=%s, " + my_repr = PyUnicode_FromFormat("%s(%u, signature=%s, " "variant_level=%ld)", - self->super.ob_type->tp_name, - PyString_AS_STRING(parent_repr), - PyString_AS_STRING(sig_repr), + Py_TYPE(self)->tp_name, + parent_repr, + PyBytes_AS_STRING(sig_repr), variant_level); } else { - my_repr = PyString_FromFormat("%s(%s, signature=%s)", - self->super.ob_type->tp_name, - PyString_AS_STRING(parent_repr), - PyString_AS_STRING(sig_repr)); + my_repr = PyUnicode_FromFormat("%s(%u, signature=%s)", + Py_TYPE(self)->tp_name, + parent_repr, + PyBytes_AS_STRING(sig_repr)); } finally: Py_XDECREF(parent_repr); @@ -128,7 +129,7 @@ Array_tp_new (PyTypeObject *cls, PyObjec variant_level = PyDict_GetItem(kwargs, dbus_py_variant_level_const); } if (variant_level) { - self->variant_level = PyInt_AsLong(variant_level); + self->variant_level = PyLong_AsLong(variant_level); if (PyErr_Occurred()) { Py_DECREF((PyObject *)self); return NULL; @@ -167,7 +168,7 @@ Array_tp_init (DBusPyArray *self, PyObje } if (signature != Py_None) { - const char *c_str = PyString_AS_STRING(signature); + const char *c_str = PyBytes_AS_STRING(signature); if (!dbus_signature_validate_single(c_str, NULL)) { Py_DECREF(signature); @@ -196,8 +197,7 @@ Array_tp_init (DBusPyArray *self, PyObje } PyTypeObject DBusPyArray_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.Array", sizeof(DBusPyArray), 0, @@ -302,18 +302,18 @@ Dict_tp_repr(DBusPyDict *self) if (!parent_repr) goto finally; if (!sig_repr) goto finally; if (variant_level > 0) { - my_repr = PyString_FromFormat("%s(%s, signature=%s, " + my_repr = PyUnincode_FromFormat("%s(%u, signature=%u, " "variant_level=%ld)", - self->super.ob_type->tp_name, - PyString_AS_STRING(parent_repr), - PyString_AS_STRING(sig_repr), + Py_TYPE(self)->tp_name, + parent_repr, + sig_repr, variant_level); } else { - my_repr = PyString_FromFormat("%s(%s, signature=%s)", - self->super.ob_type->tp_name, - PyString_AS_STRING(parent_repr), - PyString_AS_STRING(sig_repr)); + my_repr = PyUnicode_FromFormat("%s(%u, signature=%u)", + Py_TYPE(self)->tp_name, + parent_repr, + sig_repr); } finally: Py_XDECREF(parent_repr); @@ -337,7 +337,7 @@ Dict_tp_new(PyTypeObject *cls, PyObject variant_level = PyDict_GetItem(kwargs, dbus_py_variant_level_const); } if (variant_level) { - self->variant_level = PyInt_AsLong(variant_level); + self->variant_level = PyLong_AsLong(variant_level); if (PyErr_Occurred()) { Py_DECREF((PyObject *)self); return NULL; @@ -375,7 +375,7 @@ Dict_tp_init(DBusPyDict *self, PyObject } if (signature != Py_None) { - const char *c_str = PyString_AS_STRING(signature); + const char *c_str = PyBytes_AS_STRING(signature); switch (c_str[0]) { case DBUS_TYPE_BYTE: @@ -430,8 +430,7 @@ Dict_tp_init(DBusPyDict *self, PyObject } PyTypeObject DBusPyDict_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.Dictionary", sizeof(DBusPyDict), 0, @@ -522,18 +521,18 @@ Struct_tp_repr(PyObject *self) if (!sig_repr) goto finally; variant_level = dbus_py_variant_level_get(self); if (variant_level > 0) { - my_repr = PyString_FromFormat("%s(%s, signature=%s, " + my_repr = PyUnicode_FromFormat("%s(%u, signature=%u, " "variant_level=%ld)", self->ob_type->tp_name, - PyString_AS_STRING(parent_repr), - PyString_AS_STRING(sig_repr), + parent_repr, + sig_repr, variant_level); } else { - my_repr = PyString_FromFormat("%s(%s, signature=%s)", + my_repr = PyUnicode_FromFormat("%s(%u, signature=%u)", self->ob_type->tp_name, - PyString_AS_STRING(parent_repr), - PyString_AS_STRING(sig_repr)); + parent_repr, + sig_repr); } finally: @@ -647,11 +646,11 @@ Struct_tp_getattro(PyObject *obj, PyObje { PyObject *key, *value; - if (PyString_Check(name)) { + if (PyByte_Check(name)) { Py_INCREF(name); } else if (PyUnicode_Check(name)) { - name = PyUnicode_AsEncodedString(name, NULL, NULL); + name = PyUnicode_AsUTF8String(name); if (!name) { return NULL; } @@ -661,7 +660,7 @@ Struct_tp_getattro(PyObject *obj, PyObje return NULL; } - if (strcmp(PyString_AS_STRING(name), "signature")) { + if (strcmp(PyBytes_AS_STRING(name), "signature")) { value = dbus_py_variant_level_getattro(obj, name); Py_DECREF(name); return value; @@ -685,8 +684,7 @@ Struct_tp_getattro(PyObject *obj, PyObje } PyTypeObject DBusPyStruct_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.Struct", 0, 0, diff -up dbus-python-0.83.0/_dbus_bindings/float.c.p2to3 dbus-python-0.83.0/_dbus_bindings/float.c --- dbus-python-0.83.0/_dbus_bindings/float.c.p2to3 2008-07-23 11:35:59.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/float.c 2010-02-03 17:42:25.000000000 -0500 @@ -40,8 +40,7 @@ PyDoc_STRVAR(Float_tp_doc, #endif PyTypeObject DBusPyDouble_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.Double", 0, 0, @@ -84,8 +83,7 @@ PyTypeObject DBusPyDouble_Type = { #ifdef WITH_DBUS_FLOAT32 PyTypeObject DBusPyFloat_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.Float", 0, 0, diff -up dbus-python-0.83.0/_dbus_bindings/generic.c.p2to3 dbus-python-0.83.0/_dbus_bindings/generic.c --- dbus-python-0.83.0/_dbus_bindings/generic.c.p2to3 2007-09-27 08:58:03.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/generic.c 2010-02-03 17:42:25.000000000 -0500 @@ -38,9 +38,9 @@ dbus_py_tp_richcompare_by_pointer(PyObje { if (op == Py_EQ || op == Py_NE) { if (self == other) { - return PyInt_FromLong(op == Py_EQ); + return PyLong_FromLong(op == Py_EQ); } - return PyInt_FromLong(op == Py_NE); + return PyLong_FromLong(op == Py_NE); } PyErr_SetString(PyExc_TypeError, "Instances of this type are not ordered"); diff -up dbus-python-0.83.0/_dbus_bindings/int.c.p2to3 dbus-python-0.83.0/_dbus_bindings/int.c --- dbus-python-0.83.0/_dbus_bindings/int.c.p2to3 2008-07-23 11:35:59.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/int.c 2010-02-03 17:42:25.000000000 -0500 @@ -77,17 +77,16 @@ Boolean_tp_repr (PyObject *self) if (variant_level > 0) { return PyString_FromFormat("%s(%s, variant_level=%ld)", self->ob_type->tp_name, - PyInt_AsLong(self) ? "True" : "False", + PyLong_AsLong(self) ? "True" : "False", variant_level); } return PyString_FromFormat("%s(%s)", self->ob_type->tp_name, - PyInt_AsLong(self) ? "True" : "False"); + PyLong_AsLong(self) ? "True" : "False"); } PyTypeObject DBusPyBoolean_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.Boolean", 0, 0, @@ -153,7 +152,7 @@ PyDoc_STRVAR(Int16_tp_doc, dbus_int16_t dbus_py_int16_range_check(PyObject *obj) { - long i = PyInt_AsLong (obj); + long i = PyLong_AsLong(obj); if (i == -1 && PyErr_Occurred ()) return -1; if (i < -0x8000 || i > 0x7fff) { PyErr_Format(PyExc_OverflowError, "Value %d out of range for Int16", @@ -175,8 +174,7 @@ Int16_tp_new(PyTypeObject *cls, PyObject } PyTypeObject DBusPyInt16_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.Int16", 0, 0, @@ -242,7 +240,7 @@ PyDoc_STRVAR(UInt16_tp_doc, dbus_uint16_t dbus_py_uint16_range_check(PyObject *obj) { - long i = PyInt_AsLong(obj); + long i = PyLong_AsLong(obj); if (i == -1 && PyErr_Occurred()) return (dbus_uint16_t)(-1); if (i < 0 || i > 0xffff) { PyErr_Format(PyExc_OverflowError, "Value %d out of range for UInt16", @@ -265,8 +263,7 @@ UInt16_tp_new(PyTypeObject *cls, PyObjec } PyTypeObject DBusPyUInt16_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.UInt16", 0, 0, @@ -332,7 +329,7 @@ PyDoc_STRVAR(Int32_tp_doc, dbus_int32_t dbus_py_int32_range_check(PyObject *obj) { - long i = PyInt_AsLong(obj); + long i = PyLong_AsLong(obj); if (i == -1 && PyErr_Occurred()) return -1; if (i < INT32_MIN || i > INT32_MAX) { PyErr_Format(PyExc_OverflowError, "Value %d out of range for Int32", @@ -354,8 +351,7 @@ Int32_tp_new(PyTypeObject *cls, PyObject } PyTypeObject DBusPyInt32_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.Int32", 0, 0, @@ -456,8 +452,7 @@ UInt32_tp_new(PyTypeObject *cls, PyObjec } PyTypeObject DBusPyUInt32_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.UInt32", 0, 0, @@ -567,8 +562,7 @@ Int64_tp_new(PyTypeObject *cls, PyObject } PyTypeObject DBusPyInt64_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.Int64", 0, 0, @@ -674,8 +668,7 @@ UInt64_tp_new (PyTypeObject *cls, PyObje } PyTypeObject DBusPyUInt64_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.UInt64", 0, 0, diff -up dbus-python-0.83.0/_dbus_bindings/libdbusconn.c.p2to3 dbus-python-0.83.0/_dbus_bindings/libdbusconn.c --- dbus-python-0.83.0/_dbus_bindings/libdbusconn.c.p2to3 2008-07-17 08:07:24.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/libdbusconn.c 2010-02-03 17:42:25.000000000 -0500 @@ -73,12 +73,11 @@ DBusPyLibDBusConnection_tp_dealloc(Conne } PyErr_Restore(et, ev, etb); - (self->ob_type->tp_free)((PyObject *) self); + (Py_TYPE(self)->tp_free)((PyObject *) self); } PyTypeObject DBusPyLibDBusConnection_Type = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/ "_dbus_bindings._LibDBusConnection", sizeof(DBusPyLibDBusConnection), 0, /*tp_itemsize*/ diff -up dbus-python-0.83.0/_dbus_bindings/mainloop.c.p2to3 dbus-python-0.83.0/_dbus_bindings/mainloop.c --- dbus-python-0.83.0/_dbus_bindings/mainloop.c.p2to3 2008-07-17 08:07:24.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/mainloop.c 2010-02-03 17:42:25.000000000 -0500 @@ -59,8 +59,7 @@ static void NativeMainLoop_tp_dealloc(Na } static PyTypeObject NativeMainLoop_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.mainloop.NativeMainLoop", sizeof(NativeMainLoop), 0, diff -up dbus-python-0.83.0/_dbus_bindings/message-append.c.p2to3 dbus-python-0.83.0/_dbus_bindings/message-append.c --- dbus-python-0.83.0/_dbus_bindings/message-append.c.p2to3 2008-07-23 11:35:59.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/message-append.c 2010-02-03 17:42:25.000000000 -0500 @@ -27,6 +27,7 @@ #define DBG_IS_TOO_VERBOSE #include "types-internal.h" #include "message-internal.h" +#include "python-2to3-macros.h" /* Return the number of variants wrapping the given object. Return 0 * if the object is not a D-Bus type. @@ -139,7 +140,7 @@ get_object_path(PyObject *obj) PyObject *magic_attr = PyObject_GetAttr(obj, dbus_py__dbus_object_path__const); if (magic_attr) { - if (PyString_Check(magic_attr)) { + if (PyBytes_Check(magic_attr) || PyUnicode_Check(magic_attr)) { return magic_attr; } else { @@ -171,11 +172,11 @@ _signature_string_from_pyobject(PyObject *variant_level_ptr = variant_level; } else if (variant_level > 0) { - return PyString_FromString(DBUS_TYPE_VARIANT_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_VARIANT_AS_STRING); } if (obj == Py_True || obj == Py_False) { - return PyString_FromString(DBUS_TYPE_BOOLEAN_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_BOOLEAN_AS_STRING); } magic_attr = get_object_path(obj); @@ -183,57 +184,57 @@ _signature_string_from_pyobject(PyObject return NULL; if (magic_attr != Py_None) { Py_DECREF(magic_attr); - return PyString_FromString(DBUS_TYPE_OBJECT_PATH_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_OBJECT_PATH_AS_STRING); } Py_DECREF(magic_attr); /* Ordering is important: some of these are subclasses of each other. */ - if (PyInt_Check(obj)) { + if (PyLong_Check(obj)) { if (DBusPyInt16_Check(obj)) - return PyString_FromString(DBUS_TYPE_INT16_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_INT16_AS_STRING); else if (DBusPyInt32_Check(obj)) - return PyString_FromString(DBUS_TYPE_INT32_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_INT32_AS_STRING); else if (DBusPyByte_Check(obj)) - return PyString_FromString(DBUS_TYPE_BYTE_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_BYTE_AS_STRING); else if (DBusPyUInt16_Check(obj)) - return PyString_FromString(DBUS_TYPE_UINT16_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_UINT16_AS_STRING); else if (DBusPyBoolean_Check(obj)) - return PyString_FromString(DBUS_TYPE_BOOLEAN_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_BOOLEAN_AS_STRING); else - return PyString_FromString(DBUS_TYPE_INT32_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_INT32_AS_STRING); } else if (PyLong_Check(obj)) { if (DBusPyInt64_Check(obj)) - return PyString_FromString(DBUS_TYPE_INT64_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_INT64_AS_STRING); else if (DBusPyUInt32_Check(obj)) - return PyString_FromString(DBUS_TYPE_UINT32_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_UINT32_AS_STRING); else if (DBusPyUInt64_Check(obj)) - return PyString_FromString(DBUS_TYPE_UINT64_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_UINT64_AS_STRING); else - return PyString_FromString(DBUS_TYPE_INT64_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_INT64_AS_STRING); } else if (PyUnicode_Check(obj)) - return PyString_FromString(DBUS_TYPE_STRING_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_STRING_AS_STRING); else if (PyFloat_Check(obj)) { #ifdef WITH_DBUS_FLOAT32 if (DBusPyDouble_Check(obj)) - return PyString_FromString(DBUS_TYPE_DOUBLE_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_DOUBLE_AS_STRING); else if (DBusPyFloat_Check(obj)) - return PyString_FromString(DBUS_TYPE_FLOAT_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_FLOAT_AS_STRING); else #endif - return PyString_FromString(DBUS_TYPE_DOUBLE_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_DOUBLE_AS_STRING); } - else if (PyString_Check(obj)) { + else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) { if (DBusPyObjectPath_Check(obj)) - return PyString_FromString(DBUS_TYPE_OBJECT_PATH_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_OBJECT_PATH_AS_STRING); else if (DBusPySignature_Check(obj)) - return PyString_FromString(DBUS_TYPE_SIGNATURE_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_SIGNATURE_AS_STRING); else if (DBusPyByteArray_Check(obj)) - return PyString_FromString(DBUS_TYPE_ARRAY_AS_STRING + return PyBytes_FromString(DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING); else - return PyString_FromString(DBUS_TYPE_STRING_AS_STRING); + return PyBytes_FromString(DBUS_TYPE_STRING_AS_STRING); } else if (PyTuple_Check(obj)) { Py_ssize_t len = PyTuple_GET_SIZE(obj); @@ -250,12 +251,12 @@ _signature_string_from_pyobject(PyObject return NULL; } /* Set the first and last elements of list to be the parentheses */ - item = PyString_FromString(DBUS_STRUCT_BEGIN_CHAR_AS_STRING); + item = PyBytes_FromString(DBUS_STRUCT_BEGIN_CHAR_AS_STRING); if (PyList_SetItem(list, 0, item) < 0) { Py_DECREF(list); return NULL; } - item = PyString_FromString(DBUS_STRUCT_END_CHAR_AS_STRING); + item = PyBytes_FromString(DBUS_STRUCT_END_CHAR_AS_STRING); if (PyList_SetItem(list, len + 1, item) < 0) { Py_DECREF(list); return NULL; @@ -283,7 +284,7 @@ _signature_string_from_pyobject(PyObject } item = NULL; } - empty_str = PyString_FromString(""); + empty_str = PyBytes_FromString(""); if (!empty_str) { /* really shouldn't happen */ Py_DECREF(list); @@ -297,10 +298,10 @@ _signature_string_from_pyobject(PyObject } else if (PyList_Check(obj)) { PyObject *tmp; - PyObject *ret = PyString_FromString(DBUS_TYPE_ARRAY_AS_STRING); + PyObject *ret = PyBytes_FromString(DBUS_TYPE_ARRAY_AS_STRING); if (!ret) return NULL; - if (DBusPyArray_Check(obj) && PyString_Check(((DBusPyArray *)obj)->signature)) { - PyString_Concat(&ret, ((DBusPyArray *)obj)->signature); + if (DBusPyArray_Check(obj) && PyBytes_Check(((DBusPyArray *)obj)->signature)) { + PyBytes_Concat(&ret, PyUnicode_AsUTF8String(((DBusPyArray *)obj)->signature)); return ret; } if (PyList_GET_SIZE(obj) == 0) { @@ -312,7 +313,7 @@ _signature_string_from_pyobject(PyObject tmp = PyList_GetItem(obj, 0); tmp = _signature_string_from_pyobject(tmp, NULL); if (!tmp) return NULL; - PyString_ConcatAndDel(&ret, tmp); + PyBytes_ConcatAndDel(&ret, tmp); return ret; } else if (PyDict_Check(obj)) { @@ -320,10 +321,10 @@ _signature_string_from_pyobject(PyObject Py_ssize_t pos = 0; PyObject *ret = NULL; - if (DBusPyDict_Check(obj) && PyString_Check(((DBusPyDict *)obj)->signature)) { - const char *sig = PyString_AS_STRING(((DBusPyDict *)obj)->signature); + if (DBusPyDict_Check(obj) && PyUnicode_Check(((DBusPyDict *)obj)->signature)) { + const char *sig = PyBytes_AS_STRING(((DBusPyDict *)obj)->signature); - return PyString_FromFormat((DBUS_TYPE_ARRAY_AS_STRING + return PyBytes_FromFormat((DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING "%s" DBUS_DICT_ENTRY_END_CHAR_AS_STRING), @@ -338,12 +339,12 @@ _signature_string_from_pyobject(PyObject keysig = _signature_string_from_pyobject(key, NULL); valuesig = _signature_string_from_pyobject(value, NULL); if (keysig && valuesig) { - ret = PyString_FromFormat((DBUS_TYPE_ARRAY_AS_STRING + ret = PyBytes_FromFormat((DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING "%s%s" DBUS_DICT_ENTRY_END_CHAR_AS_STRING), - PyString_AS_STRING(keysig), - PyString_AS_STRING(valuesig)); + PyBytes_AS_STRING(keysig), + PyBytes_AS_STRING(valuesig)); } Py_XDECREF(keysig); Py_XDECREF(valuesig); @@ -395,7 +396,7 @@ dbus_py_Message_guess_signature(PyObject DBG("%s", "Message_guess_signature: failed"); return NULL; } - if (!PyString_Check(tmp) || PyString_GET_SIZE(tmp) < 2) { + if (!PyBytes_Check(tmp) || PyBytes_GET_SIZE(tmp) < 2) { PyErr_SetString(PyExc_RuntimeError, "Internal error: " "_signature_string_from_pyobject returned " "a bad result"); @@ -403,10 +404,10 @@ dbus_py_Message_guess_signature(PyObject return NULL; } ret = PyObject_CallFunction((PyObject *)&DBusPySignature_Type, "(s#)", - PyString_AS_STRING(tmp) + 1, - PyString_GET_SIZE(tmp) - 2); + PyBytes_AS_STRING(tmp) + 1, + PyBytes_GET_SIZE(tmp) - 2); DBG("Message_guess_signature: returning Signature at %p \"%s\"", ret, - ret ? PyString_AS_STRING(ret) : "(NULL)"); + ret ? PyBytes_AS_STRING(ret) : "(NULL)"); Py_DECREF(tmp); return ret; } @@ -442,13 +443,13 @@ _message_iter_append_string(DBusMessageI } } - if (PyString_Check(obj)) { + if (PyBytes_Check(obj)) { PyObject *unicode; /* Raise TypeError if the string has embedded NULs */ - if (PyString_AsStringAndSize(obj, &s, NULL) < 0) return -1; + if (PyBytes_AsStringAndSize(obj, &s, NULL) < 0) return -1; /* Surely there's a faster stdlib way to validate UTF-8... */ - unicode = PyUnicode_DecodeUTF8(s, PyString_GET_SIZE(obj), NULL); + unicode = PyUnicode_DecodeUTF8(s, PyBytes_GET_SIZE(obj), NULL); if (!unicode) { PyErr_SetString(PyExc_UnicodeError, "String parameters " "to be sent over D-Bus must be valid UTF-8"); @@ -468,7 +469,7 @@ _message_iter_append_string(DBusMessageI PyObject *utf8 = PyUnicode_AsUTF8String(obj); if (!utf8) return -1; /* Raise TypeError if the string has embedded NULs */ - if (PyString_AsStringAndSize(utf8, &s, NULL) < 0) return -1; + if (PyBytes_AsStringAndSize(utf8, &s, NULL) < 0) return -1; DBG("Performing actual append: string (from unicode) %s", s); if (!dbus_message_iter_append_basic(appender, sig_type, &s)) { PyErr_NoMemory(); @@ -489,17 +490,31 @@ _message_iter_append_byte(DBusMessageIte { unsigned char y; - if (PyString_Check(obj)) { - if (PyString_GET_SIZE(obj) != 1) { + if (PyBytes_Check(obj)) { + Py_INCREF(obj); + if (PyBytes_GET_SIZE(obj) != 1) { PyErr_Format(PyExc_ValueError, "Expected a string of " "length 1 byte, but found %d bytes", - PyString_GET_SIZE(obj)); + PyBytes_GET_SIZE(obj)); return -1; } - y = *(unsigned char *)PyString_AS_STRING(obj); - } + y = *(unsigned char *)PyBytes_AS_STRING(obj); + } + else if (PyUnicode_Check(obj)) { + if (PyUnicode_GET_SIZE(obj) != 1) { + PyErr_Format(PyExc_ValueError, "Expected a string of " + "length 1 byte, but found %d bytes", + PyUnicode_GET_SIZE(obj)); + return -1; + } + + obj = PyUnicode_AsUTF8String(obj); + + y = *(unsigned char *)PyBytes_AS_STRING(obj); + } else { - long i = PyInt_AsLong(obj); + long i = PyLong_AsLong(obj); + Py_INCREF(obj); if (i == -1 && PyErr_Occurred()) return -1; if (i < 0 || i > 0xff) { @@ -514,6 +529,8 @@ _message_iter_append_byte(DBusMessageIte PyErr_NoMemory(); return -1; } + + Py_DECREF(obj); return 0; } @@ -711,12 +728,23 @@ _message_iter_append_string_as_byte_arra PyObject *obj) { /* a bit of a faster path for byte arrays that are strings */ - Py_ssize_t len = PyString_GET_SIZE(obj); + + Py_ssize_t len = 0; + const char *s; DBusMessageIter sub; int ret; - s = PyString_AS_STRING(obj); + if (PyBytes_Check(obj)) { + Py_INCREF(obj); + } + else if (PyUnicode_Check(obj)) { + obj = PyUnicode_AsUTF8String(obj); + } + + len = PyBytes_GET_SIZE(obj); + s = PyBytes_AS_STRING(obj); + DBG("%s", "Opening ARRAY container"); if (!dbus_message_iter_open_container(appender, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &sub)) { @@ -736,6 +764,8 @@ _message_iter_append_string_as_byte_arra PyErr_NoMemory(); return -1; } + + Py_DECREF(obj); return ret; } @@ -755,7 +785,7 @@ _message_iter_append_variant(DBusMessage obj_sig = _signature_string_from_pyobject(obj, &variant_level); if (!obj_sig) return -1; - obj_sig_str = PyString_AsString(obj_sig); + obj_sig_str = PyBytes_AsString(obj_sig); if (!obj_sig_str) return -1; if (variant_level < 1) { @@ -973,7 +1003,7 @@ _message_iter_append_pyobject(DBusMessag if (sig_type == DBUS_TYPE_DICT_ENTRY) ret = _message_iter_append_multi(appender, sig_iter, DBUS_TYPE_DICT_ENTRY, obj); - else if (sig_type == DBUS_TYPE_BYTE && PyString_Check(obj)) + else if (sig_type == DBUS_TYPE_BYTE && PyBytes_Check(obj)) ret = _message_iter_append_string_as_byte_array(appender, obj); else ret = _message_iter_append_multi(appender, sig_iter, @@ -1047,7 +1077,7 @@ dbus_py_Message_append(Message *self, Py DBG("%s", "No signature for message, guessing..."); signature_obj = dbus_py_Message_guess_signature(NULL, args); if (!signature_obj) return NULL; - signature = PyString_AS_STRING(signature_obj); + signature = PyBytes_AS_STRING(signature_obj); } /* from here onwards, you have to do a goto rather than returning NULL to make sure signature_obj gets freed */ diff -up dbus-python-0.83.0/_dbus_bindings/message.c.p2to3 dbus-python-0.83.0/_dbus_bindings/message.c --- dbus-python-0.83.0/_dbus_bindings/message.c.p2to3 2008-07-23 11:35:59.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/message.c 2010-02-03 17:42:25.000000000 -0500 @@ -53,7 +53,7 @@ static void Message_tp_dealloc(Message * if (self->msg) { dbus_message_unref(self->msg); } - self->ob_type->tp_free((PyObject *)self); + Py_TYPE(self)->tp_free((PyObject *)self); } static PyObject * @@ -810,8 +810,7 @@ static PyMethodDef Message_tp_methods[] }; static PyTypeObject MessageType = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/ "dbus.lowlevel.Message", /*tp_name*/ sizeof(Message), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -852,8 +851,7 @@ static PyTypeObject MessageType = { }; static PyTypeObject MethodCallMessageType = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/ "dbus.lowlevel.MethodCallMessage", /*tp_name*/ 0, /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -894,8 +892,7 @@ static PyTypeObject MethodCallMessageTyp }; static PyTypeObject MethodReturnMessageType = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/ "dbus.lowlevel.MethodReturnMessage", /*tp_name*/ 0, /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -936,8 +933,7 @@ static PyTypeObject MethodReturnMessageT }; static PyTypeObject SignalMessageType = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/ "dbus.lowlevel.SignalMessage", /*tp_name*/ 0, /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -978,8 +974,7 @@ static PyTypeObject SignalMessageType = }; static PyTypeObject ErrorMessageType = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/ "dbus.lowlevel.ErrorMessage", /*tp_name*/ 0, /*tp_basicsize*/ 0, /*tp_itemsize*/ diff -up dbus-python-0.83.0/_dbus_bindings/module.c.p2to3 dbus-python-0.83.0/_dbus_bindings/module.c --- dbus-python-0.83.0/_dbus_bindings/module.c.p2to3 2008-07-23 11:35:59.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/module.c 2010-02-03 17:42:25.000000000 -0500 @@ -233,10 +233,26 @@ static PyMethodDef module_functions[] = {NULL, NULL, 0, NULL} }; +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "_dbus_bindings",/* m_name */ + module_doc,/* m_doc */ + 0,/* m_size */ + module_functions,/* m_methods */ + NULL,/* m_reload */ + NULL,/* m_traverse */ + NULL,/* m_clear */ + NULL,/* m_free */ +}; +#define MOD_ERROR_VAL NULL +#else +#endif + PyMODINIT_FUNC init_dbus_bindings(void) { - PyObject *this_module, *c_api; + PyObject *this_module=NULL, *c_api=NULL; static const int API_count = DBUS_BINDINGS_API_COUNT; static _dbus_py_func_ptr dbus_bindings_API[DBUS_BINDINGS_API_COUNT]; @@ -256,63 +272,300 @@ init_dbus_bindings(void) PyEval_InitThreads(); } - if (!dbus_py_init_generic()) return; - if (!dbus_py_init_abstract()) return; - if (!dbus_py_init_signature()) return; - if (!dbus_py_init_int_types()) return; - if (!dbus_py_init_string_types()) return; - if (!dbus_py_init_float_types()) return; - if (!dbus_py_init_container_types()) return; - if (!dbus_py_init_byte_types()) return; - if (!dbus_py_init_message_types()) return; - if (!dbus_py_init_pending_call()) return; - if (!dbus_py_init_mainloop()) return; - if (!dbus_py_init_libdbus_conn_types()) return; - if (!dbus_py_init_conn_types()) return; - if (!dbus_py_init_server_types()) return; - + if (!dbus_py_init_generic()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_abstract()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_signature()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_int_types()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_string_types()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_float_types()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_container_types()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_byte_types()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_message_types()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_pending_call()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_mainloop()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_libdbus_conn_types()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_conn_types()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_init_server_types()) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + +#if PY_MAJOR_VERSION >= 3 + this_module = PyModule_Create(&moduledef); +#else this_module = Py_InitModule3("_dbus_bindings", module_functions, module_doc); - if (!this_module) return; +#endif + + if (!this_module) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + - if (!dbus_py_insert_abstract_types(this_module)) return; - if (!dbus_py_insert_signature(this_module)) return; - if (!dbus_py_insert_int_types(this_module)) return; - if (!dbus_py_insert_string_types(this_module)) return; - if (!dbus_py_insert_float_types(this_module)) return; - if (!dbus_py_insert_container_types(this_module)) return; - if (!dbus_py_insert_byte_types(this_module)) return; - if (!dbus_py_insert_message_types(this_module)) return; - if (!dbus_py_insert_pending_call(this_module)) return; - if (!dbus_py_insert_mainloop_types(this_module)) return; - if (!dbus_py_insert_libdbus_conn_types(this_module)) return; - if (!dbus_py_insert_conn_types(this_module)) return; - if (!dbus_py_insert_server_types(this_module)) return; + if (!dbus_py_insert_abstract_types(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_signature(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_int_types(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_string_types(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_float_types(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_container_types(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_byte_types(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_message_types(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_pending_call(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_mainloop_types(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_libdbus_conn_types(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_conn_types(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + + if (!dbus_py_insert_server_types(this_module)) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "BUS_DAEMON_NAME", - DBUS_SERVICE_DBUS) < 0) return; + DBUS_SERVICE_DBUS) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "BUS_DAEMON_PATH", - DBUS_PATH_DBUS) < 0) return; + DBUS_PATH_DBUS) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "BUS_DAEMON_IFACE", - DBUS_INTERFACE_DBUS) < 0) return; + DBUS_INTERFACE_DBUS) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "LOCAL_PATH", - DBUS_PATH_LOCAL) < 0) return; + DBUS_PATH_LOCAL) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "LOCAL_IFACE", - DBUS_INTERFACE_LOCAL) < 0) return; + DBUS_INTERFACE_LOCAL) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "INTROSPECTABLE_IFACE", - DBUS_INTERFACE_INTROSPECTABLE) < 0) return; + DBUS_INTERFACE_INTROSPECTABLE) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "PEER_IFACE", - DBUS_INTERFACE_PEER) < 0) return; + DBUS_INTERFACE_PEER) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "PROPERTIES_IFACE", - DBUS_INTERFACE_PROPERTIES) < 0) return; + DBUS_INTERFACE_PROPERTIES) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER", - DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER) < 0) return; + DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "DBUS_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER", - DBUS_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER) < 0) return; + DBUS_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE", - DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE) < 0) return; + DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif #define ADD_CONST_VAL(x, v) \ if (PyModule_AddIntConstant(this_module, x, v) < 0) return; @@ -379,19 +632,48 @@ init_dbus_bindings(void) ADD_CONST_PREFIXED(WATCH_ERROR) if (PyModule_AddStringConstant(this_module, "__docformat__", - "restructuredtext") < 0) return; + "restructuredtext") < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddStringConstant(this_module, "__version__", - PACKAGE_VERSION) < 0) return; + PACKAGE_VERSION) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + if (PyModule_AddIntConstant(this_module, "_python_version", - PY_VERSION_HEX) < 0) return; + PY_VERSION_HEX) < 0) + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else + return; + #endif + c_api = PyCObject_FromVoidPtr ((void *)dbus_bindings_API, NULL); if (!c_api) { + #if PY_MAJOR_VERSION >= 3 + return this_module; + #else return; + #endif + } PyModule_AddObject(this_module, "_C_API", c_api); +#if PY_MAJOR_VERSION >= 3 + return this_module; +#else + return; +#endif + } /* vim:set ft=c cino< sw=4 sts=4 et: */ diff -up dbus-python-0.83.0/_dbus_bindings/pending-call.c.p2to3 dbus-python-0.83.0/_dbus_bindings/pending-call.c --- dbus-python-0.83.0/_dbus_bindings/pending-call.c.p2to3 2007-09-27 08:58:03.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/pending-call.c 2010-02-03 17:42:25.000000000 -0500 @@ -233,8 +233,7 @@ static PyMethodDef PendingCall_tp_method }; static PyTypeObject PendingCallType = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.lowlevel.PendingCall", sizeof(PendingCall), 0, diff -up dbus-python-0.83.0/_dbus_bindings/python-2to3-macros.h.p2to3 dbus-python-0.83.0/_dbus_bindings/python-2to3-macros.h --- dbus-python-0.83.0/_dbus_bindings/python-2to3-macros.h.p2to3 2010-02-03 17:42:25.000000000 -0500 +++ dbus-python-0.83.0/_dbus_bindings/python-2to3-macros.h 2010-02-03 17:43:17.000000000 -0500 @@ -0,0 +1,16 @@ +#ifndef DBUS_BINDINGS_TYPES_INTERNAL_H +#define DBUS_BINDINGS_TYPES_INTERNAL_H + +#if PY_MAJOR_VERSION < 3 +#define PyBytes_Check PyString_Check +#define PyBytes_FromFormat PyString_FromFormat +#define PyBytes_GET_SIZE PyString_GET_SIZE +#define PyBytes_AS_STRING PyString_AS_STRING +#define PyBytes_FromString PyString_FromString +#define PyBytes_Concat PyString_Concat +#define PyBytes_ConcatAndDel PyString_ConcatAndDel +#define PyBytes_AsStringAndSize PyString_AsStringAndSize +#define PyBytes_InternFromString PyString_InternFromString +#endif + +#endif diff -up dbus-python-0.83.0/_dbus_bindings/server.c.p2to3 dbus-python-0.83.0/_dbus_bindings/server.c --- dbus-python-0.83.0/_dbus_bindings/server.c.p2to3 2008-07-17 08:07:24.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/server.c 2010-02-03 17:42:25.000000000 -0500 @@ -26,6 +26,7 @@ */ #include "dbus_bindings-internal.h" +#include "python-2to3-macros.h" /* Server definition ================================================ */ @@ -40,7 +41,7 @@ typedef struct { PyObject *weaklist; PyObject *mainloop; -} Server; +}Server; PyDoc_STRVAR(Server_tp_doc, "A D-Bus server.\n" @@ -107,7 +108,21 @@ DBusPyServer_set_auth_mechanisms(Server am = PySequence_Fast_GET_ITEM(auth_mechanisms, i); /* this supports either str or unicode, raising TypeError * on failure */ - list[i] = PyString_AsString(am); + if (PyBytes_Check(am)) { + Py_INCREF(am); + } + else if (PyUnicode_Check(am)) { + am = PyUnicode_AsUTF8String(am); + if (!am) { + return FALSE; + } + } + else { + PyErr_SetString(PyExc_TypeError, "auth mechanisms must be strings"); + return FALSE; + } + + list[i] = PyBytes_AS_STRING(am); if (!list[i]) return FALSE; @@ -429,7 +444,7 @@ static void Server_tp_dealloc(Server *se DBG("Server at %p: freeing self", self); PyErr_Restore(et, ev, etb); - (self->ob_type->tp_free)((PyObject *)self); + (Py_TYPE(self)->tp_free)((PyObject *)self); } PyDoc_STRVAR(Server_disconnect__doc__, @@ -462,7 +477,7 @@ Server_get_address(Server *self, PyObjec address = dbus_server_get_address(self->server); Py_END_ALLOW_THREADS - return PyString_FromString(address); + return PyBytes_FromString(address); } PyDoc_STRVAR(Server_get_id__doc__, @@ -479,7 +494,7 @@ Server_get_id(Server *self, PyObject *ar id = dbus_server_get_id(self->server); Py_END_ALLOW_THREADS - return PyString_FromString(id); + return PyBytes_FromString(id); } PyDoc_STRVAR(Server_get_is_connected__doc__, @@ -511,8 +526,7 @@ struct PyMethodDef DBusPyServer_tp_metho }; PyTypeObject DBusPyServer_Type = { - PyObject_HEAD_INIT(NULL) - 0, /*ob_size*/ + PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/ "_dbus_bindings._Server",/*tp_name*/ sizeof(Server), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -532,7 +546,7 @@ PyTypeObject DBusPyServer_Type = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS | Py_TPFLAGS_BASETYPE, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, Server_tp_doc, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ diff -up dbus-python-0.83.0/_dbus_bindings/signature.c.p2to3 dbus-python-0.83.0/_dbus_bindings/signature.c --- dbus-python-0.83.0/_dbus_bindings/signature.c.p2to3 2008-07-23 11:35:59.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/signature.c 2010-02-03 17:42:25.000000000 -0500 @@ -30,6 +30,7 @@ #include "dbus_bindings-internal.h" #include "types-internal.h" +#include "python-2to3-macros.h" PyDoc_STRVAR(Signature_tp_doc, "A string subclass whose values are restricted to valid D-Bus\n" @@ -99,8 +100,7 @@ SignatureIter_tp_iter(PyObject *self) } static PyTypeObject SignatureIterType = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "_dbus_bindings._SignatureIter", sizeof(SignatureIter), 0, @@ -148,10 +148,9 @@ Signature_tp_iter (PyObject *self) SignatureIter *iter = PyObject_New(SignatureIter, &SignatureIterType); if (!iter) return NULL; - if (PyString_AS_STRING (self)[0]) { - Py_INCREF(self); - iter->string = self; - dbus_signature_iter_init(&(iter->iter), PyString_AS_STRING(self)); + if (PyUnicode_GET_SIZE (self)) { + iter->string = PyUnicode_AsUTF8String(self); + dbus_signature_iter_init(&(iter->iter), PyBytes_AS_STRING(self)); } else { /* this is a null string, make a null iterator */ @@ -177,8 +176,7 @@ Signature_tp_new (PyTypeObject *cls, PyO } PyTypeObject DBusPySignature_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.Signature", 0, 0, diff -up dbus-python-0.83.0/_dbus_bindings/string.c.p2to3 dbus-python-0.83.0/_dbus_bindings/string.c --- dbus-python-0.83.0/_dbus_bindings/string.c.p2to3 2008-07-23 11:35:59.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/string.c 2010-02-03 17:42:25.000000000 -0500 @@ -82,8 +82,7 @@ UTF8String_tp_new(PyTypeObject *cls, PyO } PyTypeObject DBusPyUTF8String_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.UTF8String", 0, 0, @@ -161,8 +160,7 @@ ObjectPath_tp_new(PyTypeObject *cls, PyO } PyTypeObject DBusPyObjectPath_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.ObjectPath", 0, 0, @@ -290,8 +288,7 @@ String_tp_repr(PyObject *self) } PyTypeObject DBusPyString_Type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "dbus.String", sizeof(DBusPyString), 0, diff -up dbus-python-0.83.0/_dbus_bindings/types-internal.h.p2to3 dbus-python-0.83.0/_dbus_bindings/types-internal.h --- dbus-python-0.83.0/_dbus_bindings/types-internal.h.p2to3 2008-07-23 11:35:59.000000000 -0400 +++ dbus-python-0.83.0/_dbus_bindings/types-internal.h 2010-02-03 17:42:25.000000000 -0500 @@ -35,7 +35,7 @@ extern PyTypeObject DBusPyIntBase_Type; DEFINE_CHECK(DBusPyIntBase) typedef struct { - PyIntObject base; + PyLongObject base; long variant_level; } DBusPyIntBase;