diff options
Diffstat (limited to 'dbus_bindings')
-rw-r--r-- | dbus_bindings/abstract.c | 204 | ||||
-rw-r--r-- | dbus_bindings/bus.c | 12 | ||||
-rw-r--r-- | dbus_bindings/bytes.c | 38 | ||||
-rw-r--r-- | dbus_bindings/conn-methods.c | 4 | ||||
-rw-r--r-- | dbus_bindings/conn.c | 4 | ||||
-rw-r--r-- | dbus_bindings/containers.c | 52 | ||||
-rw-r--r-- | dbus_bindings/dbus_bindings-internal.h | 26 | ||||
-rw-r--r-- | dbus_bindings/exceptions.c | 4 | ||||
-rw-r--r-- | dbus_bindings/float.c | 6 | ||||
-rw-r--r-- | dbus_bindings/int.c | 71 | ||||
-rw-r--r-- | dbus_bindings/message-append.c | 127 | ||||
-rw-r--r-- | dbus_bindings/message-get-args.c | 54 | ||||
-rw-r--r-- | dbus_bindings/message.c | 14 | ||||
-rw-r--r-- | dbus_bindings/module.c | 20 | ||||
-rw-r--r-- | dbus_bindings/server.c | 8 | ||||
-rw-r--r-- | dbus_bindings/signature.c | 8 | ||||
-rw-r--r-- | dbus_bindings/string.c | 114 | ||||
-rw-r--r-- | dbus_bindings/types-internal.h | 17 | ||||
-rw-r--r-- | dbus_bindings/unixfd.c | 2 |
19 files changed, 96 insertions, 689 deletions
diff --git a/dbus_bindings/abstract.c b/dbus_bindings/abstract.c index 4eca52a..64ac9fb 100644 --- a/dbus_bindings/abstract.c +++ b/dbus_bindings/abstract.c @@ -62,7 +62,7 @@ dbus_py_variant_level_get(PyObject *obj) */ return 0; } - variant_level = NATIVEINT_ASLONG(vl_obj); + variant_level = PyLong_AsLong(vl_obj); if (variant_level == -1 && PyErr_Occurred()) { /* variant_level < 0 can never be inserted into the dictionary; see * dbus_py_variant_level_set() below. The semantics of setting @@ -93,7 +93,7 @@ dbus_py_variant_level_set(PyObject *obj, long variant_level) } } else { - PyObject *vl_obj = NATIVEINT_FROMLONG(variant_level); + PyObject *vl_obj = PyLong_FromLong(variant_level); if (!vl_obj) { Py_CLEAR(key); return FALSE; @@ -114,32 +114,8 @@ dbus_py_variant_level_getattro(PyObject *obj, PyObject *name) { PyObject *key, *value; -#ifdef PY3 if (PyUnicode_CompareWithASCIIString(name, "variant_level")) return PyObject_GenericGetAttr(obj, name); -#else - if (PyBytes_Check(name)) { - Py_INCREF(name); - } - else if (PyUnicode_Check(name)) { - name = PyUnicode_AsEncodedString(name, NULL, NULL); - if (!name) { - return NULL; - } - } - else { - PyErr_SetString(PyExc_TypeError, "attribute name must be string"); - return NULL; - } - - if (strcmp(PyBytes_AS_STRING(name), "variant_level")) { - value = PyObject_GenericGetAttr(obj, name); - Py_CLEAR(name); - return value; - } - - Py_CLEAR(name); -#endif /* PY3 */ key = PyLong_FromVoidPtr(obj); @@ -151,7 +127,7 @@ dbus_py_variant_level_getattro(PyObject *obj, PyObject *name) Py_CLEAR(key); if (!value) - return NATIVEINT_FROMLONG(0); + return PyLong_FromLong(0); Py_INCREF(value); return value; } @@ -172,122 +148,11 @@ dbus_py_variant_level_clear(PyObject *self) PyErr_Restore(et, ev, etb); } -#ifndef PY3 -/* Support code for int subclasses. ================================== */ - -PyDoc_STRVAR(DBusPythonInt_tp_doc,\ -"Base class for int subclasses with a ``variant_level`` attribute.\n" -"Do not rely on the existence of this class outside dbus-python.\n" -); - -static PyMemberDef DBusPythonInt_tp_members[] = { - {"variant_level", T_LONG, offsetof(DBusPyIntBase, variant_level), - READONLY, - "The number of nested variants wrapping the real data. " - "0 if not in a variant."}, - {NULL}, -}; - -static PyObject * -DBusPythonInt_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) -{ - PyObject *self; - long variantness = 0; - static char *argnames[] = {"variant_level", NULL}; - - if (PyTuple_Size(args) > 1) { - PyErr_SetString(PyExc_TypeError, - "__new__ takes at most one positional parameter"); - return NULL; - } - if (!PyArg_ParseTupleAndKeywords(dbus_py_empty_tuple, kwargs, - "|l:__new__", argnames, - &variantness)) return NULL; - if (variantness < 0) { - PyErr_SetString(PyExc_ValueError, - "variant_level must be non-negative"); - return NULL; - } - - self = (PyInt_Type.tp_new)(cls, args, NULL); - if (self) { - ((DBusPyIntBase *)self)->variant_level = variantness; - } - return self; -} - -static PyObject * -DBusPythonInt_tp_repr(PyObject *self) -{ - PyObject *parent_repr = (PyInt_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 = PyUnicode_FromFormat("%s(%V, variant_level=%ld)", - Py_TYPE(self)->tp_name, - REPRV(parent_repr), - variant_level); - } - else { - my_repr = PyUnicode_FromFormat("%s(%V)", Py_TYPE(self)->tp_name, - REPRV(parent_repr)); - } - /* whether my_repr is NULL or not: */ - Py_CLEAR(parent_repr); - return my_repr; -} - -PyTypeObject DBusPyIntBase_Type = { - PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) - "_dbus_bindings._IntBase", - sizeof(DBusPyIntBase), - 0, - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - DBusPythonInt_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 */ - DBusPythonInt_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 */ - DBusPythonInt_tp_members, /* 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 */ - PyType_GenericAlloc, /* tp_alloc */ - DBusPythonInt_tp_new, /* tp_new */ - PyObject_Del, /* tp_free */ -}; -#endif /* !PY3 */ - /* Support code for float subclasses. ================================ */ /* There's only one subclass at the moment (Double) but these are factored out to make room for Float later. (Float is implemented and #if'd out) */ -#ifdef PY3 /* In Python >= 3.8 the tp_str for subclasses of built-in types prints * the subclass repr(), which does not match dbus-python's historical * behaviour. */ @@ -296,9 +161,6 @@ DBusPythonFloat_tp_str(PyObject *self) { return (PyFloat_Type.tp_repr)(self); } -#else -#define DBusPythonFloat_tp_str 0 -#endif PyDoc_STRVAR(DBusPythonFloat_tp_doc,\ "Base class for float subclasses with a ``variant_level`` attribute.\n" @@ -405,7 +267,6 @@ PyTypeObject DBusPyFloatBase_Type = { DBusPythonFloat_tp_new, /* tp_new */ }; -#ifdef PY3 /* Support code for bytes subclasses ================================== */ PyDoc_STRVAR(DBusPythonBytes_tp_doc,\ @@ -460,7 +321,7 @@ DBusPythonBytes_tp_repr(PyObject *self) Py_CLEAR(parent_repr); return NULL; } - variant_level = NATIVEINT_ASLONG(vl_obj); + variant_level = PyLong_AsLong(vl_obj); Py_CLEAR(vl_obj); if (variant_level == -1 && PyErr_Occurred()) { Py_CLEAR(parent_repr); @@ -528,7 +389,6 @@ PyTypeObject DBusPyBytesBase_Type = { 0, /* tp_alloc */ DBusPythonBytes_tp_new, /* tp_new */ }; -#endif /* PY3 */ /* Support code for str subclasses ================================== */ @@ -558,7 +418,7 @@ DBusPythonString_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) return NULL; } - self = (NATIVESTR_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_CLEAR(self); @@ -571,7 +431,7 @@ DBusPythonString_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) static PyObject * DBusPythonString_tp_repr(PyObject *self) { - PyObject *parent_repr = (NATIVESTR_TYPE.tp_repr)(self); + PyObject *parent_repr = (PyUnicode_Type.tp_repr)(self); PyObject *vl_obj; PyObject *my_repr; long variant_level; @@ -582,7 +442,7 @@ DBusPythonString_tp_repr(PyObject *self) Py_CLEAR(parent_repr); return NULL; } - variant_level = NATIVEINT_ASLONG(vl_obj); + variant_level = PyLong_AsLong(vl_obj); Py_CLEAR(vl_obj); if (variant_level == -1 && PyErr_Occurred()) { Py_CLEAR(parent_repr); @@ -608,7 +468,7 @@ static void DBusPyStrBase_tp_dealloc(PyObject *self) { dbus_py_variant_level_clear(self); - (NATIVESTR_TYPE.tp_dealloc)(self); + (PyUnicode_Type.tp_dealloc)(self); } PyTypeObject DBusPyStrBase_Type = { @@ -642,7 +502,7 @@ PyTypeObject DBusPyStrBase_Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&NATIVESTR_TYPE), /* tp_base */ + DEFERRED_ADDRESS(&PyUnicode_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -704,7 +564,7 @@ DBusPythonLong_tp_repr(PyObject *self) Py_CLEAR(parent_repr); return NULL; } - variant_level = NATIVEINT_ASLONG(vl_obj); + variant_level = PyLong_AsLong(vl_obj); Py_CLEAR(vl_obj); if (variant_level < 0 && PyErr_Occurred()) { Py_CLEAR(parent_repr); @@ -726,7 +586,6 @@ DBusPythonLong_tp_repr(PyObject *self) return my_repr; } -#ifdef PY3 /* In Python >= 3.8 the tp_str for subclasses of built-in types prints * the subclass repr(), which does not match dbus-python's historical * behaviour. */ @@ -735,9 +594,6 @@ DBusPythonLong_tp_str(PyObject *self) { return (PyLong_Type.tp_repr)(self); } -#else -#define DBusPythonLong_tp_str 0 -#endif static void DBusPyLongBase_tp_dealloc(PyObject *self) @@ -791,58 +647,32 @@ PyObject *dbus_py_variant_level_const = NULL; PyObject *dbus_py_signature_const = NULL; PyObject *dbus_py__dbus_object_path__const = NULL; -#ifdef PY3 -#define INTERN (PyUnicode_InternFromString) -#else -/* Neither Python 2.6 nor 2.7 define the expected PyBytes_InternFromString - * alias in bytesobject.h. - */ -#define INTERN (PyString_InternFromString) -#endif - dbus_bool_t dbus_py_init_abstract(void) { _dbus_py_variant_levels = PyDict_New(); if (!_dbus_py_variant_levels) return 0; - dbus_py__dbus_object_path__const = INTERN("__dbus_object_path__"); + dbus_py__dbus_object_path__const = PyUnicode_InternFromString("__dbus_object_path__"); if (!dbus_py__dbus_object_path__const) return 0; - dbus_py_variant_level_const = INTERN("variant_level"); + dbus_py_variant_level_const = PyUnicode_InternFromString("variant_level"); if (!dbus_py_variant_level_const) return 0; - dbus_py_signature_const = INTERN("signature"); + dbus_py_signature_const = PyUnicode_InternFromString("signature"); if (!dbus_py_signature_const) return 0; -#ifdef PY3 DBusPyBytesBase_Type.tp_base = &PyBytes_Type; if (PyType_Ready(&DBusPyBytesBase_Type) < 0) return 0; -#else - DBusPyIntBase_Type.tp_base = &PyInt_Type; - if (PyType_Ready(&DBusPyIntBase_Type) < 0) return 0; - /* disable the tp_print copied from PyInt_Type, so tp_repr gets called as - desired */ - DBusPyIntBase_Type.tp_print = NULL; -#endif DBusPyFloatBase_Type.tp_base = &PyFloat_Type; if (PyType_Ready(&DBusPyFloatBase_Type) < 0) return 0; -#ifndef PY3 - DBusPyFloatBase_Type.tp_print = NULL; -#endif DBusPyLongBase_Type.tp_base = &PyLong_Type; if (PyType_Ready(&DBusPyLongBase_Type) < 0) return 0; -#ifndef PY3 - DBusPyLongBase_Type.tp_print = NULL; -#endif - DBusPyStrBase_Type.tp_base = &NATIVESTR_TYPE; + DBusPyStrBase_Type.tp_base = &PyUnicode_Type; if (PyType_Ready(&DBusPyStrBase_Type) < 0) return 0; -#ifndef PY3 - DBusPyStrBase_Type.tp_print = NULL; -#endif return 1; } @@ -851,15 +681,9 @@ dbus_bool_t dbus_py_insert_abstract_types(PyObject *this_module) { /* PyModule_AddObject steals a ref */ -#ifdef PY3 Py_INCREF(&DBusPyBytesBase_Type); if (PyModule_AddObject(this_module, "_BytesBase", (PyObject *)&DBusPyBytesBase_Type) < 0) return 0; -#else - Py_INCREF(&DBusPyIntBase_Type); - if (PyModule_AddObject(this_module, "_IntBase", - (PyObject *)&DBusPyIntBase_Type) < 0) return 0; -#endif Py_INCREF(&DBusPyLongBase_Type); Py_INCREF(&DBusPyStrBase_Type); Py_INCREF(&DBusPyFloatBase_Type); diff --git a/dbus_bindings/bus.c b/dbus_bindings/bus.c index 2c79cc0..ab1d4eb 100644 --- a/dbus_bindings/bus.c +++ b/dbus_bindings/bus.c @@ -45,13 +45,7 @@ DBusPyConnection_NewForBus(PyTypeObject *cls, PyObject *args, PyObject *kwargs) dbus_error_init(&error); - if (first && -#ifdef PY3 - PyUnicode_Check(first) -#else - PyBytes_Check(first) -#endif - ) + if (first && PyUnicode_Check(first)) { dbus_bool_t ret; @@ -72,7 +66,7 @@ DBusPyConnection_NewForBus(PyTypeObject *cls, PyObject *args, PyObject *kwargs) return (PyObject *)self; } - else if (!first || INTORLONG_CHECK(first)) + else if (!first || PyLong_Check(first)) { long type; PyObject *libdbusconn; @@ -156,7 +150,7 @@ DBusPyConnection_GetUniqueName(Connection *self, PyObject *args UNUSED) return DBusPyException_SetString("This connection has no unique name " "yet"); } - return NATIVESTR_FROMSTR(name); + return PyUnicode_FromString(name); } PyObject * diff --git a/dbus_bindings/bytes.c b/dbus_bindings/bytes.c index 611d239..1d5f652 100644 --- a/dbus_bindings/bytes.c +++ b/dbus_bindings/bytes.c @@ -32,12 +32,6 @@ #include "types-internal.h" -#ifdef PY3 -#define DBUS_PY_BYTE_BASE (DBusPyLongBase_Type) -#else -#define DBUS_PY_BYTE_BASE (DBusPyIntBase_Type) -#endif - PyDoc_STRVAR(Byte_tp_doc, "dbus.Byte(integer or bytes of length 1[, variant_level])\n" "\n" @@ -93,11 +87,11 @@ Byte_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) if (PyBytes_GET_SIZE(obj) != 1) { goto bad_arg; } - obj = NATIVEINT_FROMLONG((unsigned char)(PyBytes_AS_STRING(obj)[0])); + obj = PyLong_FromLong((unsigned char)(PyBytes_AS_STRING(obj)[0])); if (!obj) goto bad_arg; } - else if (INTORLONG_CHECK(obj)) { + else if (PyLong_Check(obj)) { /* on Python 2 this accepts either int or long */ long i = PyLong_AsLong(obj); long my_variant_level; @@ -105,13 +99,9 @@ Byte_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) if (i == -1 && PyErr_Occurred()) goto bad_arg; -#ifdef PY3 my_variant_level = dbus_py_variant_level_get(obj); if (my_variant_level < 0) return NULL; -#else - my_variant_level = ((DBusPyIntBase *)obj)->variant_level; -#endif if (Py_TYPE(obj) == cls && my_variant_level == variantness) { Py_INCREF(obj); return obj; @@ -128,7 +118,7 @@ Byte_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) tuple = Py_BuildValue("(N)", obj); if (!tuple) return NULL; - obj = DBUS_PY_BYTE_BASE.tp_new(cls, tuple, kwargs); + obj = DBusPyLongBase_Type.tp_new(cls, tuple, kwargs); Py_CLEAR(tuple); return obj; @@ -144,7 +134,7 @@ bad_range: static PyObject * Byte_tp_str(PyObject *self) { - long i = NATIVEINT_ASLONG(self); + long i = PyLong_AsLong(self); unsigned char str[2] = { 0, 0 }; if (i == -1 && PyErr_Occurred()) @@ -189,7 +179,7 @@ PyTypeObject DBusPyByte_Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBUS_PY_BYTE_BASE), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -199,12 +189,6 @@ PyTypeObject DBusPyByte_Type = { Byte_new, /* tp_new */ }; -#ifdef PY3 -#define DBUS_PY_BYTEARRAY_BASE (DBusPyBytesBase_Type) -#else -#define DBUS_PY_BYTEARRAY_BASE (DBusPyStrBase_Type) -#endif - PyDoc_STRVAR(ByteArray_tp_doc, "ByteArray(str)\n" "\n" @@ -265,7 +249,7 @@ PyTypeObject DBusPyByteArray_Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBUS_PY_BYTEARRAY_BASE), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyBytesBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -278,17 +262,11 @@ PyTypeObject DBusPyByteArray_Type = { dbus_bool_t dbus_py_init_byte_types(void) { - DBusPyByte_Type.tp_base = &DBUS_PY_BYTE_BASE; + DBusPyByte_Type.tp_base = &DBusPyLongBase_Type; if (PyType_Ready(&DBusPyByte_Type) < 0) return 0; -#ifndef PY3 - DBusPyByte_Type.tp_print = NULL; -#endif - DBusPyByteArray_Type.tp_base = &DBUS_PY_BYTEARRAY_BASE; + DBusPyByteArray_Type.tp_base = &DBusPyBytesBase_Type; if (PyType_Ready(&DBusPyByteArray_Type) < 0) return 0; -#ifndef PY3 - DBusPyByteArray_Type.tp_print = NULL; -#endif return 1; } diff --git a/dbus_bindings/conn-methods.c b/dbus_bindings/conn-methods.c index 62bdf86..f6ffc5b 100644 --- a/dbus_bindings/conn-methods.c +++ b/dbus_bindings/conn-methods.c @@ -567,7 +567,7 @@ Connection_get_unix_fd (Connection *self, PyObject *unused UNUSED) ok = dbus_connection_get_unix_fd (self->conn, &fd); Py_END_ALLOW_THREADS if (!ok) Py_RETURN_NONE; - return NATIVEINT_FROMLONG(fd); + return PyLong_FromLong(fd); } PyDoc_STRVAR(Connection_get_peer_unix_user__doc__, @@ -979,7 +979,7 @@ Connection_list_exported_child_objects (Connection *self, PyObject *args, return NULL; } for (kid_ptr = kids; *kid_ptr; kid_ptr++) { - PyObject *tmp = NATIVESTR_FROMSTR(*kid_ptr); + PyObject *tmp = PyUnicode_FromString(*kid_ptr); if (!tmp) { Py_CLEAR(ret); diff --git a/dbus_bindings/conn.c b/dbus_bindings/conn.c index 01c326b..59c3b36 100644 --- a/dbus_bindings/conn.c +++ b/dbus_bindings/conn.c @@ -450,11 +450,7 @@ PyTypeObject DBusPyConnection_Type = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ -#ifdef PY3 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, -#else - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS | Py_TPFLAGS_BASETYPE, -#endif Connection_tp_doc, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ diff --git a/dbus_bindings/containers.c b/dbus_bindings/containers.c index 7994d1f..1477752 100644 --- a/dbus_bindings/containers.c +++ b/dbus_bindings/containers.c @@ -165,27 +165,16 @@ Array_tp_init (DBusPyArray *self, PyObject *args, PyObject *kwargs) const char *c_str; PyObject *signature_as_bytes; - if ( -#ifdef PY3 - !PyUnicode_Check(signature) -#else - !PyBytes_Check(signature) -#endif - ) + if (!PyUnicode_Check(signature)) { PyErr_SetString(PyExc_TypeError, "str expected"); Py_CLEAR(signature); return -1; } -#ifdef PY3 if (!(signature_as_bytes = PyUnicode_AsUTF8String(signature))) { Py_CLEAR(signature); return -1; } -#else - signature_as_bytes = signature; - Py_INCREF(signature_as_bytes); -#endif c_str = PyBytes_AS_STRING(signature_as_bytes); @@ -394,20 +383,15 @@ Dict_tp_init(DBusPyDict *self, PyObject *args, PyObject *kwargs) const char *c_str; PyObject *signature_as_bytes; - if (!NATIVESTR_CHECK(signature)) { + if (!PyUnicode_Check(signature)) { PyErr_SetString(PyExc_TypeError, "str expected"); Py_CLEAR(signature); return -1; } -#ifdef PY3 if (!(signature_as_bytes = PyUnicode_AsUTF8String(signature))) { Py_CLEAR(signature); return -1; } -#else - signature_as_bytes = signature; - Py_INCREF(signature_as_bytes); -#endif c_str = PyBytes_AS_STRING(signature_as_bytes); switch (c_str[0]) { @@ -687,31 +671,8 @@ Struct_tp_getattro(PyObject *obj, PyObject *name) { PyObject *key, *value; -#ifdef PY3 if (PyUnicode_CompareWithASCIIString(name, "signature")) return dbus_py_variant_level_getattro(obj, name); -#else - if (PyBytes_Check(name)) { - Py_INCREF(name); - } - else if (PyUnicode_Check(name)) { - name = PyUnicode_AsEncodedString(name, NULL, NULL); - if (!name) { - return NULL; - } - } - else { - PyErr_SetString(PyExc_TypeError, "attribute name must be string"); - return NULL; - } - - if (strcmp(PyBytes_AS_STRING(name), "signature")) { - value = dbus_py_variant_level_getattro(obj, name); - Py_CLEAR(name); - return value; - } - Py_CLEAR(name); -#endif /* PY3 */ key = PyLong_FromVoidPtr(obj); @@ -777,21 +738,12 @@ dbus_py_init_container_types(void) DBusPyArray_Type.tp_base = &PyList_Type; if (PyType_Ready(&DBusPyArray_Type) < 0) return 0; -#ifndef PY3 - DBusPyArray_Type.tp_print = NULL; -#endif DBusPyDict_Type.tp_base = &PyDict_Type; if (PyType_Ready(&DBusPyDict_Type) < 0) return 0; -#ifndef PY3 - DBusPyDict_Type.tp_print = NULL; -#endif DBusPyStruct_Type.tp_base = &PyTuple_Type; if (PyType_Ready(&DBusPyStruct_Type) < 0) return 0; -#ifndef PY3 - DBusPyStruct_Type.tp_print = NULL; -#endif return 1; } diff --git a/dbus_bindings/dbus_bindings-internal.h b/dbus_bindings/dbus_bindings-internal.h index 7b1ca1e..eb48897 100644 --- a/dbus_bindings/dbus_bindings-internal.h +++ b/dbus_bindings/dbus_bindings-internal.h @@ -92,29 +92,7 @@ static inline int type##_CheckExact (PyObject *o) \ (PyUnicode_Check(obj) ? (obj) : NULL), \ (PyUnicode_Check(obj) ? NULL : PyBytes_AS_STRING(obj)) -#ifdef PY3 -#define NATIVEINT_TYPE (PyLong_Type) -#define NATIVEINT_FROMLONG(x) (PyLong_FromLong(x)) -#define NATIVEINT_ASLONG(x) (PyLong_AsLong(x)) -#define INTORLONG_CHECK(obj) (PyLong_Check(obj)) -#define NATIVESTR_TYPE (PyUnicode_Type) -#define NATIVESTR_CHECK(obj) (PyUnicode_Check(obj)) -#define NATIVESTR_FROMSTR(obj) (PyUnicode_FromString(obj)) -#else -#define NATIVEINT_TYPE (PyInt_Type) -#define NATIVEINT_FROMLONG(x) (PyInt_FromLong(x)) -#define NATIVEINT_ASLONG(x) (PyInt_AsLong(x)) -#define INTORLONG_CHECK(obj) (PyLong_Check(obj) || PyInt_Check(obj)) -#define NATIVESTR_TYPE (PyBytes_Type) -#define NATIVESTR_CHECK(obj) (PyBytes_Check(obj)) -#define NATIVESTR_FROMSTR(obj) (PyBytes_FromString(obj)) -#endif - -#ifdef PY3 PyMODINIT_FUNC PyInit__dbus_bindings(void); -#else -PyMODINIT_FUNC init_dbus_bindings(void); -#endif /* conn.c */ extern PyTypeObject DBusPyConnection_Type; @@ -154,10 +132,6 @@ DEFINE_CHECK(DBusPyByteArray) DEFINE_CHECK(DBusPyByte) extern PyTypeObject DBusPyString_Type; DEFINE_CHECK(DBusPyString) -#ifndef PY3 -extern PyTypeObject DBusPyUTF8String_Type; -DEFINE_CHECK(DBusPyUTF8String) -#endif extern PyTypeObject DBusPyDouble_Type; DEFINE_CHECK(DBusPyDouble) extern PyTypeObject DBusPyInt16_Type, DBusPyUInt16_Type; diff --git a/dbus_bindings/exceptions.c b/dbus_bindings/exceptions.c index 508537a..2940c2b 100644 --- a/dbus_bindings/exceptions.c +++ b/dbus_bindings/exceptions.c @@ -39,7 +39,7 @@ import_exception(void) return TRUE; } - name = NATIVESTR_FROMSTR("dbus.exceptions"); + name = PyUnicode_FromString("dbus.exceptions"); if (name == NULL) { return FALSE; } @@ -83,7 +83,7 @@ DBusPyException_ConsumeError(DBusError *error) } if (error->name) { - PyObject *name = NATIVESTR_FROMSTR(error->name); + PyObject *name = PyUnicode_FromString(error->name); int ret; if (!name) diff --git a/dbus_bindings/float.c b/dbus_bindings/float.c index eeabd5b..3ec1c13 100644 --- a/dbus_bindings/float.c +++ b/dbus_bindings/float.c @@ -130,16 +130,10 @@ dbus_py_init_float_types(void) { DBusPyDouble_Type.tp_base = &DBusPyFloatBase_Type; if (PyType_Ready(&DBusPyDouble_Type) < 0) return 0; -#ifndef PY3 - DBusPyDouble_Type.tp_print = NULL; -#endif #ifdef WITH_DBUS_FLOAT32 DBusPyFloat_Type.tp_base = &DBusPyFloatBase_Type; if (PyType_Ready(&DBusPyFloat_Type) < 0) return 0; -#ifndef PY3 - DBusPyFloat_Type.tp_print = NULL; -#endif #endif return 1; diff --git a/dbus_bindings/int.c b/dbus_bindings/int.c index 5944314..47d8404 100644 --- a/dbus_bindings/int.c +++ b/dbus_bindings/int.c @@ -29,14 +29,6 @@ #include "types-internal.h" -#ifdef PY3 -#define INTBASE (DBusPyLongBase_Type) -#define LONG_TYPE_NAME "int" -#else -#define INTBASE (DBusPyIntBase_Type) -#define LONG_TYPE_NAME "long" -#endif - /* Specific types =================================================== */ /* Boolean, a subclass of DBusPythonInt ============================= */ @@ -75,7 +67,7 @@ Boolean_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) } tuple = Py_BuildValue("(i)", PyObject_IsTrue(value) ? 1 : 0); if (!tuple) return NULL; - self = (INTBASE.tp_new)(cls, tuple, kwargs); + self = (DBusPyLongBase_Type.tp_new)(cls, tuple, kwargs); Py_CLEAR(tuple); return self; } @@ -90,13 +82,9 @@ static PyObject * Boolean_tp_repr(PyObject *self) { int is_true = PyObject_IsTrue(self); -#ifdef PY3 long variant_level = dbus_py_variant_level_get(self); if (variant_level < 0) return NULL; -#else - long variant_level = ((DBusPyIntBase *)self)->variant_level; -#endif if (is_true == -1) return NULL; @@ -143,7 +131,7 @@ PyTypeObject DBusPyBoolean_Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&INTBASE), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -192,7 +180,7 @@ dbus_py_int16_range_check(PyObject *obj) static PyObject * Int16_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { - PyObject *self = (INTBASE.tp_new)(cls, args, kwargs); + PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs); if (self && dbus_py_int16_range_check(self) == -1 && PyErr_Occurred()) { Py_CLEAR(self); return NULL; @@ -231,7 +219,7 @@ PyTypeObject DBusPyInt16_Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&INTBASE), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -280,7 +268,7 @@ dbus_py_uint16_range_check(PyObject *obj) static PyObject * UInt16_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { - PyObject *self = (INTBASE.tp_new)(cls, args, kwargs); + PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs); if (self && dbus_py_uint16_range_check(self) == (dbus_uint16_t)(-1) && PyErr_Occurred()) { @@ -321,7 +309,7 @@ PyTypeObject DBusPyUInt16_Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&INTBASE), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -370,7 +358,7 @@ dbus_py_int32_range_check(PyObject *obj) static PyObject * Int32_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { - PyObject *self = (INTBASE.tp_new)(cls, args, kwargs); + PyObject *self = (DBusPyLongBase_Type.tp_new)(cls, args, kwargs); if (self && dbus_py_int32_range_check(self) == -1 && PyErr_Occurred()) { Py_CLEAR(self); return NULL; @@ -409,7 +397,7 @@ PyTypeObject DBusPyInt32_Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&INTBASE), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -422,7 +410,7 @@ PyTypeObject DBusPyInt32_Type = { /* UInt32 =========================================================== */ PyDoc_STRVAR(UInt32_tp_doc, -"dbus.UInt32(value: " LONG_TYPE_NAME "[, variant_level: int])\n" +"dbus.UInt32(value: int[, variant_level: int])\n" "\n" "An unsigned 32-bit integer between 0 and 0xFFFF FFFF, represented as a\n" "subtype of ``long`` in Python 2 or ``int`` in Python 3.\n" @@ -505,7 +493,7 @@ PyTypeObject DBusPyUInt32_Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -518,7 +506,7 @@ PyTypeObject DBusPyUInt32_Type = { /* Int64 =========================================================== */ PyDoc_STRVAR(Int64_tp_doc, -"dbus.Int64(value: " LONG_TYPE_NAME "[, variant_level: int])\n" +"dbus.Int64(value: int[, variant_level: int])\n" "\n" "A signed 64-bit integer between -0x8000 0000 0000 0000 and\n" "+0x7FFF FFFF FFFF FFFF, represented as a\n" @@ -611,7 +599,7 @@ PyTypeObject DBusPyInt64_Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -624,7 +612,7 @@ PyTypeObject DBusPyInt64_Type = { /* UInt64 =========================================================== */ PyDoc_STRVAR(UInt64_tp_doc, -"dbus.UInt64(value: " LONG_TYPE_NAME "[, variant_level: int])\n" +"dbus.UInt64(value: int[, variant_level: int])\n" "\n" "An unsigned 64-bit integer between 0 and 0xFFFF FFFF FFFF FFFF,\n" "subtype of ``long`` in Python 2 or ``int`` in Python 3.\n" @@ -712,7 +700,7 @@ PyTypeObject DBusPyUInt64_Type = { 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ + DEFERRED_ADDRESS(&DBusPyLongBase_Type), /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -725,51 +713,28 @@ PyTypeObject DBusPyUInt64_Type = { dbus_bool_t dbus_py_init_int_types(void) { - DBusPyInt16_Type.tp_base = &INTBASE; + DBusPyInt16_Type.tp_base = &DBusPyLongBase_Type; if (PyType_Ready(&DBusPyInt16_Type) < 0) return 0; -#ifndef PY3 - /* disable the tp_print copied from PyInt_Type, so tp_repr gets called as - desired */ - DBusPyInt16_Type.tp_print = NULL; -#endif - DBusPyUInt16_Type.tp_base = &INTBASE; + DBusPyUInt16_Type.tp_base = &DBusPyLongBase_Type; if (PyType_Ready(&DBusPyUInt16_Type) < 0) return 0; -#ifndef PY3 - DBusPyUInt16_Type.tp_print = NULL; -#endif - DBusPyInt32_Type.tp_base = &INTBASE; + DBusPyInt32_Type.tp_base = &DBusPyLongBase_Type; if (PyType_Ready(&DBusPyInt32_Type) < 0) return 0; -#ifndef PY3 - DBusPyInt32_Type.tp_print = NULL; -#endif DBusPyUInt32_Type.tp_base = &DBusPyLongBase_Type; if (PyType_Ready(&DBusPyUInt32_Type) < 0) return 0; -#ifndef PY3 - DBusPyUInt32_Type.tp_print = NULL; -#endif #if defined(DBUS_HAVE_INT64) && defined(HAVE_LONG_LONG) DBusPyInt64_Type.tp_base = &DBusPyLongBase_Type; if (PyType_Ready(&DBusPyInt64_Type) < 0) return 0; -#ifndef PY3 - DBusPyInt64_Type.tp_print = NULL; -#endif DBusPyUInt64_Type.tp_base = &DBusPyLongBase_Type; if (PyType_Ready(&DBusPyUInt64_Type) < 0) return 0; -#ifndef PY3 - DBusPyUInt64_Type.tp_print = NULL; -#endif #endif - DBusPyBoolean_Type.tp_base = &INTBASE; + DBusPyBoolean_Type.tp_base = &DBusPyLongBase_Type; if (PyType_Ready(&DBusPyBoolean_Type) < 0) return 0; -#ifndef PY3 - DBusPyBoolean_Type.tp_print = NULL; -#endif return 1; } diff --git a/dbus_bindings/message-append.c b/dbus_bindings/message-append.c index 3257405..9c6b5f7 100644 --- a/dbus_bindings/message-append.c +++ b/dbus_bindings/message-append.c @@ -44,11 +44,6 @@ get_variant_level(PyObject *obj) if (DBusPyString_Check(obj)) { return ((DBusPyString *)obj)->variant_level; } -#ifndef PY3 - else if (DBusPyIntBase_Check(obj)) { - return ((DBusPyIntBase *)obj)->variant_level; - } -#endif else if (DBusPyFloatBase_Check(obj)) { return ((DBusPyFloatBase *)obj)->variant_level; } @@ -59,9 +54,7 @@ get_variant_level(PyObject *obj) return ((DBusPyDict *)obj)->variant_level; } else if (DBusPyLongBase_Check(obj) || -#ifdef PY3 DBusPyBytesBase_Check(obj) || -#endif DBusPyStrBase_Check(obj) || DBusPyStruct_Check(obj)) { return dbus_py_variant_level_get(obj); @@ -188,11 +181,11 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) *variant_level_ptr = variant_level; } else if (variant_level > 0) { - return NATIVESTR_FROMSTR(DBUS_TYPE_VARIANT_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_VARIANT_AS_STRING); } if (obj == Py_True || obj == Py_False) { - return NATIVESTR_FROMSTR(DBUS_TYPE_BOOLEAN_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_BOOLEAN_AS_STRING); } magic_attr = get_object_path(obj); @@ -200,94 +193,67 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) return NULL; if (magic_attr != Py_None) { Py_CLEAR(magic_attr); - return NATIVESTR_FROMSTR(DBUS_TYPE_OBJECT_PATH_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_OBJECT_PATH_AS_STRING); } Py_CLEAR(magic_attr); /* Ordering is important: some of these are subclasses of each other. */ -#ifdef PY3 if (PyLong_Check(obj)) { if (DBusPyUInt64_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_UINT64_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_UINT64_AS_STRING); else if (DBusPyInt64_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_INT64_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_INT64_AS_STRING); else if (DBusPyUInt32_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_UINT32_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_UINT32_AS_STRING); else if (DBusPyInt32_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_INT32_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_INT32_AS_STRING); else if (DBusPyUInt16_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_UINT16_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_UINT16_AS_STRING); else if (DBusPyInt16_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_INT16_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_INT16_AS_STRING); else if (DBusPyByte_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_BYTE_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_BYTE_AS_STRING); else if (DBusPyBoolean_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_BOOLEAN_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_BOOLEAN_AS_STRING); else - return NATIVESTR_FROMSTR(DBUS_TYPE_INT32_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_INT32_AS_STRING); } -#else /* !PY3 */ - if (PyInt_Check(obj)) { - if (DBusPyInt16_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_INT16_AS_STRING); - else if (DBusPyInt32_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_INT32_AS_STRING); - else if (DBusPyByte_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_BYTE_AS_STRING); - else if (DBusPyUInt16_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_UINT16_AS_STRING); - else if (DBusPyBoolean_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_BOOLEAN_AS_STRING); - else - return NATIVESTR_FROMSTR(DBUS_TYPE_INT32_AS_STRING); - } - else if (PyLong_Check(obj)) { - if (DBusPyInt64_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_INT64_AS_STRING); - else if (DBusPyUInt32_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_UINT32_AS_STRING); - else if (DBusPyUInt64_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_UINT64_AS_STRING); - else - return NATIVESTR_FROMSTR(DBUS_TYPE_INT64_AS_STRING); - } -#endif /* PY3 */ else if (PyUnicode_Check(obj)) { /* Object paths and signatures are unicode subtypes in Python 3 * (the first two cases will never be true in Python 2) */ if (DBusPyObjectPath_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_OBJECT_PATH_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_OBJECT_PATH_AS_STRING); else if (DBusPySignature_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_SIGNATURE_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_SIGNATURE_AS_STRING); else - return NATIVESTR_FROMSTR(DBUS_TYPE_STRING_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_STRING_AS_STRING); } #if defined(DBUS_TYPE_UNIX_FD) else if (DBusPyUnixFd_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_UNIX_FD_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_UNIX_FD_AS_STRING); #endif else if (PyFloat_Check(obj)) { #ifdef WITH_DBUS_FLOAT32 if (DBusPyDouble_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_DOUBLE_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_DOUBLE_AS_STRING); else if (DBusPyFloat_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_FLOAT_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_FLOAT_AS_STRING); else #endif - return NATIVESTR_FROMSTR(DBUS_TYPE_DOUBLE_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_DOUBLE_AS_STRING); } else if (PyBytes_Check(obj)) { /* Object paths and signatures are bytes subtypes in Python 2 * (the first two cases will never be true in Python 3) */ if (DBusPyObjectPath_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_OBJECT_PATH_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_OBJECT_PATH_AS_STRING); else if (DBusPySignature_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_SIGNATURE_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_SIGNATURE_AS_STRING); else if (DBusPyByteArray_Check(obj)) - return NATIVESTR_FROMSTR(DBUS_TYPE_ARRAY_AS_STRING + return PyUnicode_FromString(DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING); else - return NATIVESTR_FROMSTR(DBUS_TYPE_STRING_AS_STRING); + return PyUnicode_FromString(DBUS_TYPE_STRING_AS_STRING); } else if (PyTuple_Check(obj)) { Py_ssize_t len = PyTuple_GET_SIZE(obj); @@ -304,12 +270,12 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) return NULL; } /* Set the first and last elements of list to be the parentheses */ - item = NATIVESTR_FROMSTR(DBUS_STRUCT_BEGIN_CHAR_AS_STRING); + item = PyUnicode_FromString(DBUS_STRUCT_BEGIN_CHAR_AS_STRING); if (PyList_SetItem(list, 0, item) < 0) { Py_CLEAR(list); return NULL; } - item = NATIVESTR_FROMSTR(DBUS_STRUCT_END_CHAR_AS_STRING); + item = PyUnicode_FromString(DBUS_STRUCT_END_CHAR_AS_STRING); if (PyList_SetItem(list, len + 1, item) < 0) { Py_CLEAR(list); return NULL; @@ -337,7 +303,7 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) } item = NULL; } - empty_str = NATIVESTR_FROMSTR(""); + empty_str = PyUnicode_FromString(""); if (!empty_str) { /* really shouldn't happen */ Py_CLEAR(list); @@ -351,9 +317,8 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) } else if (PyList_Check(obj)) { PyObject *tmp; - PyObject *ret = NATIVESTR_FROMSTR(DBUS_TYPE_ARRAY_AS_STRING); + PyObject *ret = PyUnicode_FromString(DBUS_TYPE_ARRAY_AS_STRING); if (!ret) return NULL; -#ifdef PY3 if (DBusPyArray_Check(obj) && PyUnicode_Check(((DBusPyArray *)obj)->signature)) { @@ -362,14 +327,6 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) Py_CLEAR(ret); return concat; } -#else - if (DBusPyArray_Check(obj) && - PyBytes_Check(((DBusPyArray *)obj)->signature)) - { - PyBytes_Concat(&ret, ((DBusPyArray *)obj)->signature); - return ret; - } -#endif if (PyList_GET_SIZE(obj) == 0) { /* No items, so fail. Or should we guess "av"? */ PyErr_SetString(PyExc_ValueError, "Unable to guess signature " @@ -379,24 +336,18 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) tmp = PyList_GetItem(obj, 0); tmp = _signature_string_from_pyobject(tmp, NULL); if (!tmp) return NULL; -#ifdef PY3 { PyObject *concat = PyUnicode_Concat(ret, tmp); Py_CLEAR(ret); Py_CLEAR(tmp); return concat; } -#else - PyBytes_ConcatAndDel(&ret, tmp); - return ret; -#endif } else if (PyDict_Check(obj)) { PyObject *key, *value, *keysig, *valuesig; Py_ssize_t pos = 0; PyObject *ret = NULL; -#ifdef PY3 if (DBusPyDict_Check(obj) && PyUnicode_Check(((DBusPyDict *)obj)->signature)) { @@ -406,19 +357,6 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) DBUS_DICT_ENTRY_END_CHAR_AS_STRING), ((DBusPyDict *)obj)->signature); } -#else - if (DBusPyDict_Check(obj) && - PyBytes_Check(((DBusPyDict *)obj)->signature)) - { - const char *sig = PyBytes_AS_STRING(((DBusPyDict *)obj)->signature); - - return PyBytes_FromFormat((DBUS_TYPE_ARRAY_AS_STRING - DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING - "%s" - DBUS_DICT_ENTRY_END_CHAR_AS_STRING), - sig); - } -#endif if (!PyDict_Next(obj, &pos, &key, &value)) { /* No items, so fail. Or should we guess "a{vv}"? */ PyErr_SetString(PyExc_ValueError, "Unable to guess signature " @@ -428,20 +366,11 @@ _signature_string_from_pyobject(PyObject *obj, long *variant_level_ptr) keysig = _signature_string_from_pyobject(key, NULL); valuesig = _signature_string_from_pyobject(value, NULL); if (keysig && valuesig) { -#ifdef PY3 ret = PyUnicode_FromFormat((DBUS_TYPE_ARRAY_AS_STRING DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING "%U%U" DBUS_DICT_ENTRY_END_CHAR_AS_STRING), keysig, valuesig); -#else - ret = PyBytes_FromFormat((DBUS_TYPE_ARRAY_AS_STRING - DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING - "%s%s" - DBUS_DICT_ENTRY_END_CHAR_AS_STRING), - PyBytes_AS_STRING(keysig), - PyBytes_AS_STRING(valuesig)); -#endif } Py_CLEAR(keysig); Py_CLEAR(valuesig); @@ -644,7 +573,7 @@ _message_iter_append_unixfd(DBusMessageIter *appender, PyObject *obj) int fd; long original_fd; - if (INTORLONG_CHECK(obj)) + if (PyLong_Check(obj)) { /* on Python 2 this accepts either int or long */ original_fd = PyLong_AsLong(obj); diff --git a/dbus_bindings/message-get-args.c b/dbus_bindings/message-get-args.c index c097160..6dad272 100644 --- a/dbus_bindings/message-get-args.c +++ b/dbus_bindings/message-get-args.c @@ -45,11 +45,6 @@ char dbus_py_Message_get_args_list__doc__[] = ( " it's off by default for consistency.\n" "\n" " If false (default), convert them into a dbus.Array of Bytes.\n" -#ifndef PY3 -" `utf8_strings` : bool\n" -" If true, return D-Bus strings as Python `bytes` objects (in UTF-8).\n" -" If false (default), return D-Bus strings as Python `unicode` objects.\n" -#endif "\n" "Most of the type mappings should be fairly obvious:\n" "\n" @@ -75,9 +70,6 @@ char dbus_py_Message_get_args_list__doc__[] = ( typedef struct { int byte_arrays; -#ifndef PY3 - int utf8_strings; -#endif } Message_get_args_options; static PyObject *_message_iter_get_pyobject(DBusMessageIter *iter, @@ -205,7 +197,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, if (variant_level > 0 && type != DBUS_TYPE_VARIANT) { PyObject *variant_level_int; - variant_level_int = NATIVEINT_FROMLONG(variant_level); + variant_level_int = PyLong_FromLong(variant_level); if (!variant_level_int) { return NULL; } @@ -232,28 +224,16 @@ _message_iter_get_pyobject(DBusMessageIter *iter, case DBUS_TYPE_STRING: DBG("%s", "found a string"); dbus_message_iter_get_basic(iter, &u.str); -#ifndef PY3 - if (opts->utf8_strings) { - args = Py_BuildValue("(s)", u.str); - if (!args) break; - ret = PyObject_Call((PyObject *)&DBusPyUTF8String_Type, - args, kwargs); + unicode = PyUnicode_DecodeUTF8(u.str, strlen(u.str), NULL); + if (!unicode) { + break; } - else { -#endif - unicode = PyUnicode_DecodeUTF8(u.str, strlen(u.str), NULL); - if (!unicode) { - break; - } - args = Py_BuildValue("(N)", unicode); - if (!args) { - break; - } - ret = PyObject_Call((PyObject *)&DBusPyString_Type, - args, kwargs); -#ifndef PY3 + args = Py_BuildValue("(N)", unicode); + if (!args) { + break; } -#endif + ret = PyObject_Call((PyObject *)&DBusPyString_Type, + args, kwargs); break; case DBUS_TYPE_SIGNATURE: @@ -410,11 +390,7 @@ _message_iter_get_pyobject(DBusMessageIter *iter, * for an empty byte-blob... */ u.str = ""; } -#ifdef PY3 args = Py_BuildValue("(y#)", u.str, (Py_ssize_t)n); -#else - args = Py_BuildValue("(s#)", u.str, (Py_ssize_t)n); -#endif if (!args) break; ret = PyObject_Call((PyObject *)&DBusPyByteArray_Type, args, kwargs); @@ -498,13 +474,8 @@ _message_iter_get_pyobject(DBusMessageIter *iter, PyObject * dbus_py_Message_get_args_list(Message *self, PyObject *args, PyObject *kwargs) { -#ifdef PY3 Message_get_args_options opts = { 0 }; static char *argnames[] = { "byte_arrays", NULL }; -#else - Message_get_args_options opts = { 0, 0 }; - static char *argnames[] = { "byte_arrays", "utf8_strings", NULL }; -#endif PyObject *list; DBusMessageIter iter; @@ -524,16 +495,9 @@ dbus_py_Message_get_args_list(Message *self, PyObject *args, PyObject *kwargs) "arguments"); return NULL; } -#ifdef PY3 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:get_args_list", argnames, &(opts.byte_arrays))) return NULL; -#else - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ii:get_args_list", - argnames, - &(opts.byte_arrays), - &(opts.utf8_strings))) return NULL; -#endif if (!self->msg) return DBusPy_RaiseUnusableMessage(); list = PyList_New(0); diff --git a/dbus_bindings/message.c b/dbus_bindings/message.c index 7c0c192..4ebd59b 100644 --- a/dbus_bindings/message.c +++ b/dbus_bindings/message.c @@ -392,7 +392,7 @@ static PyObject * Message_get_type(Message *self, PyObject *unused UNUSED) { if (!self->msg) return DBusPy_RaiseUnusableMessage(); - return NATIVEINT_FROMLONG(dbus_message_get_type(self->msg)); + return PyLong_FromLong(dbus_message_get_type(self->msg)); } PyDoc_STRVAR(Message_get_serial__doc__, @@ -466,7 +466,7 @@ Message_get_member(Message *self, PyObject *unused UNUSED) if (!c_str) { Py_RETURN_NONE; } - return NATIVESTR_FROMSTR(c_str); + return PyUnicode_FromString(c_str); } PyDoc_STRVAR(Message_has_member__doc__, @@ -541,7 +541,7 @@ Message_get_path_decomposed(Message *self, PyObject *unused UNUSED) Py_RETURN_NONE; } for (ptr = paths; *ptr; ptr++) { - PyObject *str = NATIVESTR_FROMSTR(*ptr); + PyObject *str = PyUnicode_FromString(*ptr); if (!str) { Py_CLEAR(ret); @@ -627,7 +627,7 @@ Message_get_sender(Message *self, PyObject *unused UNUSED) if (!c_str) { Py_RETURN_NONE; } - return NATIVESTR_FROMSTR(c_str); + return PyUnicode_FromString(c_str); } PyDoc_STRVAR(Message_has_sender__doc__, @@ -673,7 +673,7 @@ Message_get_destination(Message *self, PyObject *unused UNUSED) if (!c_str) { Py_RETURN_NONE; } - return NATIVESTR_FROMSTR(c_str); + return PyUnicode_FromString(c_str); } PyDoc_STRVAR(Message_has_destination__doc__, @@ -718,7 +718,7 @@ Message_get_interface(Message *self, PyObject *unused UNUSED) if (!c_str) { Py_RETURN_NONE; } - return NATIVESTR_FROMSTR(c_str); + return PyUnicode_FromString(c_str); } PyDoc_STRVAR(Message_has_interface__doc__, @@ -763,7 +763,7 @@ Message_get_error_name(Message *self, PyObject *unused UNUSED) if (!c_str) { Py_RETURN_NONE; } - return NATIVESTR_FROMSTR(c_str); + return PyUnicode_FromString(c_str); } PyDoc_STRVAR(Message_set_error_name__doc__, diff --git a/dbus_bindings/module.c b/dbus_bindings/module.c index 2779bfa..8ca99a5 100644 --- a/dbus_bindings/module.c +++ b/dbus_bindings/module.c @@ -235,17 +235,12 @@ static PyMethodDef module_functions[] = { }; PyMODINIT_FUNC -#ifdef PY3 PyInit__dbus_bindings(void) -#else -init_dbus_bindings(void) -#endif { PyObject *this_module = NULL, *c_api; static const int API_count = DBUS_BINDINGS_API_COUNT; static _dbus_py_func_ptr dbus_bindings_API[DBUS_BINDINGS_API_COUNT]; -#ifdef PY3 static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "_dbus_bindings", /* m_name */ @@ -257,7 +252,6 @@ init_dbus_bindings(void) NULL, /* m_clear */ NULL /* m_free */ }; -#endif dbus_bindings_API[0] = (_dbus_py_func_ptr)&API_count; dbus_bindings_API[1] = (_dbus_py_func_ptr)DBusPyConnection_BorrowDBusConnection; @@ -281,12 +275,7 @@ init_dbus_bindings(void) if (!dbus_py_init_conn_types()) goto init_error; if (!dbus_py_init_server_types()) goto init_error; -#ifdef PY3 this_module = PyModule_Create(&moduledef); -#else - this_module = Py_InitModule3("_dbus_bindings", - module_functions, module_doc); -#endif if (!this_module) goto init_error; if (!dbus_py_insert_abstract_types(this_module)) goto init_error; @@ -409,26 +398,17 @@ init_dbus_bindings(void) if (PyModule_AddIntConstant(this_module, "_python_version", PY_VERSION_HEX) < 0) goto init_error; -#ifdef PY3 c_api = PyCapsule_New((void *)dbus_bindings_API, PYDBUS_CAPSULE_NAME, NULL); -#else - c_api = PyCObject_FromVoidPtr ((void *)dbus_bindings_API, NULL); -#endif if (!c_api) { goto init_error; } PyModule_AddObject(this_module, "_C_API", c_api); -#ifdef PY3 return this_module; init_error: Py_CLEAR(this_module); return NULL; -#else - init_error: - return; -#endif } /* vim:set ft=c cino< sw=4 sts=4 et: */ diff --git a/dbus_bindings/server.c b/dbus_bindings/server.c index dfbfa53..705ba2f 100644 --- a/dbus_bindings/server.c +++ b/dbus_bindings/server.c @@ -496,7 +496,7 @@ Server_get_address(Server *self, PyObject *args UNUSED) address = dbus_server_get_address(self->server); Py_END_ALLOW_THREADS - return NATIVESTR_FROMSTR(address); + return PyUnicode_FromString(address); } PyDoc_STRVAR(Server_get_id__doc__, @@ -513,7 +513,7 @@ Server_get_id(Server *self, PyObject *args UNUSED) id = dbus_server_get_id(self->server); Py_END_ALLOW_THREADS - return NATIVESTR_FROMSTR(id); + return PyUnicode_FromString(id); } PyDoc_STRVAR(Server_get_is_connected__doc__, @@ -565,11 +565,7 @@ PyTypeObject DBusPyServer_Type = { 0, /*tp_getattro*/ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ -#ifdef PY3 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, -#else - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS | Py_TPFLAGS_BASETYPE, -#endif Server_tp_doc, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ diff --git a/dbus_bindings/signature.c b/dbus_bindings/signature.c index 403907d..cd2ba03 100644 --- a/dbus_bindings/signature.c +++ b/dbus_bindings/signature.c @@ -146,16 +146,11 @@ Signature_tp_iter(PyObject *self) if (!iter) return NULL; -#ifdef PY3 self_as_bytes = PyUnicode_AsUTF8String(self); if (!self_as_bytes) { Py_CLEAR(iter); return NULL; } -#else - self_as_bytes = self; - Py_INCREF(self_as_bytes); -#endif if (PyBytes_GET_SIZE(self_as_bytes) > 0) { iter->bytes = self_as_bytes; @@ -235,9 +230,6 @@ dbus_py_init_signature(void) DBusPySignature_Type.tp_base = &DBusPyStrBase_Type; if (PyType_Ready(&DBusPySignature_Type) < 0) return 0; -#ifndef PY3 - DBusPySignature_Type.tp_print = NULL; -#endif return 1; } diff --git a/dbus_bindings/string.c b/dbus_bindings/string.c index b6f42ac..e57a483 100644 --- a/dbus_bindings/string.c +++ b/dbus_bindings/string.c @@ -30,103 +30,6 @@ #include "types-internal.h" #include <structmember.h> -#ifndef PY3 -/* UTF-8 string representation ====================================== */ - -PyDoc_STRVAR(UTF8String_tp_doc, -"dbus.UTF8String(value: bytes or unicode[, variant_level: int=0])\n" -"\n" -"A string represented using UTF-8 - a subtype of `bytes`.\n" -"This type is only available in Python 2.\n" -"\n" -"All strings on D-Bus are required to be valid Unicode; in the \"wire\n" -"protocol\" they're transported as UTF-8.\n" -"\n" -"By default, when byte arrays are converted from D-Bus to Python, they\n" -"come out as a `dbus.String`, which is a subtype of `unicode`.\n" -"If you prefer to get UTF-8 strings (as instances of this class) or you\n" -"want to avoid the conversion overhead of going from UTF-8 to Python's\n" -"internal Unicode representation, you can pass the ``utf8_strings=True``\n" -"keyword argument to any of these methods:\n" -"\n" -"* any D-Bus method proxy, or ``connect_to_signal``, on the objects returned\n" -" by `Bus.get_object`\n" -"* any D-Bus method on a `dbus.Interface`\n" -"* `dbus.Interface.connect_to_signal`\n" -"* `Bus.add_signal_receiver`\n" -"\n" -"If value is a bytes object it must be valid UTF-8.\n" -"\n" -"variant_level must be non-negative; the default is 0.\n" -"\n" -".. py:attribute:: variant_level\n" -"\n" -" Indicates how many nested Variant containers this object\n" -" is contained in: if a message's wire format has a variant containing a\n" -" variant containing a string, this is represented in Python by a\n" -" String or UTF8String with variant_level==2.\n" -"\n" -":Since: 0.80 (in older versions, use dbus.String)\n" -); - -static PyObject * -UTF8String_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) -{ - const char *str = NULL; - long variantness = 0; - static char *argnames[] = {"value", "variant_level", NULL}; - PyObject *unicode; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|l:__new__", argnames, - &str, &variantness)) return NULL; - unicode = PyUnicode_DecodeUTF8(str, strlen(str), NULL); - if (!unicode) return NULL; - Py_CLEAR(unicode); - return (DBusPyStrBase_Type.tp_new)(cls, args, kwargs); -} - -PyTypeObject DBusPyUTF8String_Type = { - PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) - "dbus.UTF8String", - 0, - 0, - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* 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 */ - UTF8String_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(&DBusPyStrBase_Type), /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - UTF8String_tp_new, /* tp_new */ -}; -#endif /* !PY3 */ - /* Object path ====================================================== */ PyDoc_STRVAR(ObjectPath_tp_doc, @@ -339,21 +242,9 @@ dbus_py_init_string_types(void) } DBusPyString_Type.tp_base = &PyUnicode_Type; if (PyType_Ready(&DBusPyString_Type) < 0) return 0; -#ifndef PY3 - DBusPyString_Type.tp_print = NULL; -#endif - -#ifndef PY3 - DBusPyUTF8String_Type.tp_base = &DBusPyStrBase_Type; - if (PyType_Ready(&DBusPyUTF8String_Type) < 0) return 0; - DBusPyUTF8String_Type.tp_print = NULL; -#endif DBusPyObjectPath_Type.tp_base = &DBusPyStrBase_Type; if (PyType_Ready(&DBusPyObjectPath_Type) < 0) return 0; -#ifndef PY3 - DBusPyObjectPath_Type.tp_print = NULL; -#endif return 1; } @@ -369,11 +260,6 @@ dbus_py_insert_string_types(PyObject *this_module) if (PyModule_AddObject(this_module, "String", (PyObject *)&DBusPyString_Type) < 0) return 0; -#ifndef PY3 - Py_INCREF(&DBusPyUTF8String_Type); - if (PyModule_AddObject(this_module, "UTF8String", - (PyObject *)&DBusPyUTF8String_Type) < 0) return 0; -#endif return 1; } diff --git a/dbus_bindings/types-internal.h b/dbus_bindings/types-internal.h index 37879cf..02c931f 100644 --- a/dbus_bindings/types-internal.h +++ b/dbus_bindings/types-internal.h @@ -35,24 +35,9 @@ */ #include <bytesobject.h> -/* In Python 2.x, we need this to define the type of PyLongObject */ -#ifndef PY3 -#include <longintrepr.h> -#endif - #ifndef DBUS_BINDINGS_TYPES_INTERNAL_H #define DBUS_BINDINGS_TYPES_INTERNAL_H -#ifndef PY3 -extern PyTypeObject DBusPyIntBase_Type; -DEFINE_CHECK(DBusPyIntBase) - -typedef struct { - PyIntObject base; - long variant_level; -} DBusPyIntBase; -#endif - extern PyTypeObject DBusPyLongBase_Type; DEFINE_CHECK(DBusPyLongBase) @@ -72,10 +57,8 @@ typedef struct { extern PyTypeObject DBusPyStrBase_Type; DEFINE_CHECK(DBusPyStrBase) -#ifdef PY3 extern PyTypeObject DBusPyBytesBase_Type; DEFINE_CHECK(DBusPyBytesBase) -#endif dbus_int16_t dbus_py_int16_range_check(PyObject *); dbus_uint16_t dbus_py_uint16_range_check(PyObject *); diff --git a/dbus_bindings/unixfd.c b/dbus_bindings/unixfd.c index ed99386..63a2402 100644 --- a/dbus_bindings/unixfd.c +++ b/dbus_bindings/unixfd.c @@ -77,7 +77,7 @@ make_fd(PyObject *arg, int *fd) { long fd_arg; - if (INTORLONG_CHECK(arg)) + if (PyLong_Check(arg)) { /* on Python 2 this accepts either int or long */ fd_arg = PyLong_AsLong(arg); |