~jderose/ubuntu/precise/dbus-python/oneiric-backport

« back to all changes in this revision

Viewing changes to _dbus_bindings/conn.c

  • Committer: Package Import Robot
  • Author(s): Barry Warsaw
  • Date: 2012-01-12 14:47:33 UTC
  • Revision ID: package-import@ubuntu.com-20120112144733-xtfbmgw30h0j40d2
Tags: 0.84.0-2ubuntu1
* debian/patches:
  - since-0.84.0.patch: Upstream unreleased changes from git tag
    dbus-python-0.84.0 to HEAD.  This is a precursor to the following.
  - python3-support.patch: Upstream unreleased changes from git
    `python3` branch for supporting Python 3. (LP: #893091)
* debian/rules: Enable the test suite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
100
100
    }
101
101
    else {
102
 
        long i = PyInt_AsLong(obj);
 
102
        long i = PyLong_AsLong(obj);
103
103
        DBG("%p: handler %p returned %ld", conn, callable, i);
104
104
        Py_CLEAR(obj);
105
105
        if (i == -1 && PyErr_Occurred()) {
232
232
    self->has_mainloop = (mainloop != Py_None);
233
233
    self->conn = NULL;
234
234
    self->filters = PyList_New(0);
 
235
    self->weaklist = NULL;
235
236
    if (!self->filters) goto err;
236
237
    self->object_paths = PyDict_New();
237
238
    if (!self->object_paths) goto err;
298
299
Connection_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs)
299
300
{
300
301
    DBusConnection *conn;
301
 
    const char *address;
302
302
    PyObject *address_or_conn;
303
303
    DBusError error;
304
304
    PyObject *self, *mainloop = NULL;
317
317
 
318
318
        conn = dbus_connection_ref (wrapper->conn);
319
319
    }
320
 
    else if ((address = PyString_AsString(address_or_conn)) != NULL) {
321
 
        dbus_error_init(&error);
322
 
 
323
 
        /* We always open a private connection (at the libdbus level). Sharing
324
 
         * is done in Python, to keep things simple. */
325
 
        Py_BEGIN_ALLOW_THREADS
326
 
        conn = dbus_connection_open_private(address, &error);
327
 
        Py_END_ALLOW_THREADS
328
 
 
 
320
    else if (PyBytes_Check(address_or_conn)) {
 
321
        const char *address = PyBytes_AS_STRING(address_or_conn);
 
322
 
 
323
        dbus_error_init(&error);
 
324
 
 
325
        /* We always open a private connection (at the libdbus level). Sharing
 
326
         * is done in Python, to keep things simple. */
 
327
        Py_BEGIN_ALLOW_THREADS
 
328
        conn = dbus_connection_open_private(address, &error);
 
329
        Py_END_ALLOW_THREADS
 
330
 
 
331
        if (!conn) {
 
332
            DBusPyException_ConsumeError(&error);
 
333
            return NULL;
 
334
        }
 
335
    }
 
336
    else if (PyUnicode_Check(address_or_conn)) {
 
337
        PyObject *address_as_bytes = PyUnicode_AsUTF8String(address_or_conn);
 
338
        const char *address;
 
339
 
 
340
        if (!address_as_bytes)
 
341
            return NULL;
 
342
        address = PyBytes_AS_STRING(address_as_bytes);
 
343
 
 
344
        dbus_error_init(&error);
 
345
 
 
346
        /* We always open a private connection (at the libdbus level). Sharing
 
347
         * is done in Python, to keep things simple. */
 
348
        Py_BEGIN_ALLOW_THREADS
 
349
        conn = dbus_connection_open_private(address, &error);
 
350
        Py_END_ALLOW_THREADS
 
351
 
 
352
        Py_CLEAR(address_as_bytes);
329
353
        if (!conn) {
330
354
            DBusPyException_ConsumeError(&error);
331
355
            return NULL;
332
356
        }
333
357
    }
334
358
    else {
 
359
        PyErr_SetString(PyExc_TypeError, "connection or str expected");
335
360
        return NULL;
336
361
    }
337
362
 
398
423
 
399
424
    DBG("Connection at %p: freeing self", self);
400
425
    PyErr_Restore(et, ev, etb);
401
 
    (self->ob_type->tp_free)((PyObject *)self);
 
426
    (Py_TYPE(self)->tp_free)((PyObject *)self);
402
427
}
403
428
 
404
429
/* Connection type object =========================================== */
405
430
 
406
431
PyTypeObject DBusPyConnection_Type = {
407
 
    PyObject_HEAD_INIT(NULL)
408
 
    0,                      /*ob_size*/
 
432
    PyVarObject_HEAD_INIT(NULL, 0)
409
433
    "_dbus_bindings.Connection", /*tp_name*/
410
434
    sizeof(Connection),     /*tp_basicsize*/
411
435
    0,                      /*tp_itemsize*/
425
449
    0,                      /*tp_getattro*/
426
450
    0,                      /*tp_setattro*/
427
451
    0,                      /*tp_as_buffer*/
 
452
#ifdef PY3
 
453
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
 
454
#else
428
455
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS | Py_TPFLAGS_BASETYPE,
 
456
#endif
429
457
    Connection_tp_doc,      /*tp_doc*/
430
458
    0,                      /*tp_traverse*/
431
459
    0,                      /*tp_clear*/