=== modified file 'PY3PORT.rst' --- PY3PORT.rst 2011-12-05 23:17:00 +0000 +++ PY3PORT.rst 2011-12-10 16:32:08 +0000 @@ -201,7 +201,9 @@ `PySequence_Fast()` returns a new reference, which wasn't getting decref'd in any return path. - - Metaclasses are declared differently in Python 3. I had to use `exec()`. + - Instantiation of metaclasses uses different, incompatible syntax in Python + 2 and 3. You have to use direct calling of the metaclass to work across + versions, i.e. `Interface = InterfaceType('Interface', (object,), {})` - `iteritems()` and friends are gone. I dropped the "iter" prefixes. - `xrange() is gone. I changed them to use `range()`. - `isSequenceType()` is gone in Python 3, so I use a different idiom there. === modified file '_dbus_bindings/unixfd.c' --- _dbus_bindings/unixfd.c 2011-12-05 16:04:53 +0000 +++ _dbus_bindings/unixfd.c 2011-12-07 18:48:57 +0000 @@ -100,7 +100,7 @@ UnixFdObject *self = NULL; PyObject *arg; PyObject *fdnumber; - long fd_original; + long fd_original = -1; int fd, status; if (!PyArg_ParseTuple(args, "O", &arg, NULL)) { @@ -136,6 +136,7 @@ return NULL; } } + assert(fd_original >= 0); self = (UnixFdObject *) cls->tp_alloc(cls, 0); if (!self) return NULL; === modified file 'dbus/service.py' --- dbus/service.py 2011-12-05 20:33:02 +0000 +++ dbus/service.py 2011-12-10 16:33:56 +0000 @@ -30,6 +30,8 @@ import logging import operator import traceback +from collections import Sequence + try: import _thread as thread except ImportError: @@ -55,17 +57,6 @@ _logger = logging.getLogger('dbus.service') -def is_sequence(obj): - # Python 2.7 also has collections.Sequence, but Python 2.6 does not. - # isSequenceType() has been deprecated since Python 2.7. - try: - from collections import Sequence - except ImportError: - return operator.isSequenceType(obj) - else: - return isinstance(obj, Sequence) - - class _VariantSignature(object): """A fake method signature which, when iterated, yields an endless stream of 'v' characters representing variants (handy with zip()). @@ -390,10 +381,9 @@ return reflection_data -if is_py3: - exec('class Interface(metaclass=InterfaceType): pass') -else: - exec('class Interface(object): __metaclass__ = InterfaceType') +# Define Interface as an instance of the metaclass InterfaceType, in a way +# that is compatible across both Python 2 and Python 3. +Interface = InterfaceType('Interface', (object,), {}) #: A unique object used as the value of Object._object_path and @@ -747,7 +737,7 @@ elif len(signature_tuple) == 1: retval = (retval,) else: - if is_sequence(retval): + if isinstance(retval, Sequence): # multi-value signature, multi-value return... proceed unchanged pass else: