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

« back to all changes in this revision

Viewing changes to _dbus_bindings/message.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:
32
32
 
33
33
static inline int Message_Check(PyObject *o)
34
34
{
35
 
    return (o->ob_type == &MessageType)
 
35
    return (Py_TYPE(o) == &MessageType)
36
36
            || PyObject_IsInstance(o, (PyObject *)&MessageType);
37
37
}
38
38
 
53
53
    if (self->msg) {
54
54
        dbus_message_unref(self->msg);
55
55
    }
56
 
    self->ob_type->tp_free((PyObject *)self);
 
56
    Py_TYPE(self)->tp_free((PyObject *)self);
57
57
}
58
58
 
59
59
static PyObject *
69
69
    return (PyObject *)self;
70
70
}
71
71
 
 
72
static PyObject *
 
73
MethodCallMessage_tp_repr(PyObject *self)
 
74
{
 
75
    DBusMessage *msg = ((Message *)self)->msg;
 
76
    const char *destination = dbus_message_get_destination(msg);
 
77
    const char *path = dbus_message_get_path(msg);
 
78
    const char *interface = dbus_message_get_interface(msg);
 
79
    const char *member = dbus_message_get_member(msg);
 
80
 
 
81
    if (!path)
 
82
        path = "n/a";
 
83
    if (!interface)
 
84
        interface = "n/a";
 
85
    if (!member)
 
86
        member = "n/a";
 
87
    if (!destination)
 
88
        destination = "n/a";
 
89
 
 
90
    return PyUnicode_FromFormat(
 
91
        "<%s path: %s, iface: %s, member: %s dest: %s>",
 
92
        Py_TYPE(self)->tp_name,
 
93
        path, interface, member, destination);
 
94
}
 
95
 
72
96
PyDoc_STRVAR(MethodCallMessage_tp_doc, "A method-call message.\n"
73
97
"\n"
74
98
"Constructor::\n"
169
193
    return 0;
170
194
}
171
195
 
 
196
static PyObject *
 
197
SignalMessage_tp_repr(PyObject *self)
 
198
{
 
199
    DBusMessage *msg = ((Message *)self)->msg;
 
200
    const char *path = dbus_message_get_path(msg);
 
201
    const char *interface = dbus_message_get_interface(msg);
 
202
    const char *member = dbus_message_get_member(msg);
 
203
    const char *destination = dbus_message_get_destination(msg);
 
204
 
 
205
    if (!path)
 
206
        path = "n/a";
 
207
    if (!interface)
 
208
        interface = "n/a";
 
209
    if (!member)
 
210
        member = "n/a";
 
211
    if (!destination)
 
212
        destination = "(broadcast)";
 
213
 
 
214
    return PyUnicode_FromFormat("<%s path: %s, iface: %s, member: %s, dest: %s>",
 
215
                                Py_TYPE(self)->tp_name,
 
216
                                path, interface, member, destination);
 
217
}
 
218
 
172
219
PyDoc_STRVAR(ErrorMessage_tp_doc, "An error message.\n\n"
173
220
"Constructor::\n\n"
174
221
"   dbus.lowlevel.ErrorMessage(reply_to: Message, error_name: str,\n"
341
388
Message_get_type(Message *self, PyObject *unused UNUSED)
342
389
{
343
390
    if (!self->msg) return DBusPy_RaiseUnusableMessage();
344
 
    return PyInt_FromLong(dbus_message_get_type(self->msg));
 
391
    return NATIVEINT_FROMLONG(dbus_message_get_type(self->msg));
345
392
}
346
393
 
347
394
PyDoc_STRVAR(Message_get_serial__doc__,
415
462
    if (!c_str) {
416
463
        Py_RETURN_NONE;
417
464
    }
418
 
    return PyString_FromString(c_str);
 
465
    return NATIVESTR_FROMSTR(c_str);
419
466
}
420
467
 
421
468
PyDoc_STRVAR(Message_has_member__doc__,
490
537
        Py_RETURN_NONE;
491
538
    }
492
539
    for (ptr = paths; *ptr; ptr++) {
493
 
        PyObject *str = PyString_FromString(*ptr);
 
540
        PyObject *str = NATIVESTR_FROMSTR(*ptr);
494
541
 
495
542
        if (!str) {
496
543
            Py_CLEAR(ret);
576
623
    if (!c_str) {
577
624
        Py_RETURN_NONE;
578
625
    }
579
 
    return PyString_FromString(c_str);
 
626
    return NATIVESTR_FROMSTR(c_str);
580
627
}
581
628
 
582
629
PyDoc_STRVAR(Message_has_sender__doc__,
622
669
    if (!c_str) {
623
670
        Py_RETURN_NONE;
624
671
    }
625
 
    return PyString_FromString(c_str);
 
672
    return NATIVESTR_FROMSTR(c_str);
626
673
}
627
674
 
628
675
PyDoc_STRVAR(Message_has_destination__doc__,
667
714
    if (!c_str) {
668
715
        Py_RETURN_NONE;
669
716
    }
670
 
    return PyString_FromString(c_str);
 
717
    return NATIVESTR_FROMSTR(c_str);
671
718
}
672
719
 
673
720
PyDoc_STRVAR(Message_has_interface__doc__,
712
759
    if (!c_str) {
713
760
        Py_RETURN_NONE;
714
761
    }
715
 
    return PyString_FromString(c_str);
 
762
    return NATIVESTR_FROMSTR(c_str);
716
763
}
717
764
 
718
765
PyDoc_STRVAR(Message_set_error_name__doc__,
808
855
};
809
856
 
810
857
static PyTypeObject MessageType = {
811
 
    PyObject_HEAD_INIT(NULL)
812
 
    0,                         /*ob_size*/
 
858
    PyVarObject_HEAD_INIT(NULL, 0)
813
859
    "dbus.lowlevel.Message",   /*tp_name*/
814
860
    sizeof(Message),     /*tp_basicsize*/
815
861
    0,                         /*tp_itemsize*/
850
896
};
851
897
 
852
898
static PyTypeObject MethodCallMessageType = {
853
 
    PyObject_HEAD_INIT(NULL)
854
 
    0,                         /*ob_size*/
 
899
    PyVarObject_HEAD_INIT(NULL, 0)
855
900
    "dbus.lowlevel.MethodCallMessage",  /*tp_name*/
856
901
    0,                         /*tp_basicsize*/
857
902
    0,                         /*tp_itemsize*/
860
905
    0,                         /*tp_getattr*/
861
906
    0,                         /*tp_setattr*/
862
907
    0,                         /*tp_compare*/
863
 
    0,                         /*tp_repr*/
 
908
    MethodCallMessage_tp_repr, /*tp_repr*/
864
909
    0,                         /*tp_as_number*/
865
910
    0,                         /*tp_as_sequence*/
866
911
    0,                         /*tp_as_mapping*/
892
937
};
893
938
 
894
939
static PyTypeObject MethodReturnMessageType = {
895
 
    PyObject_HEAD_INIT(NULL)
896
 
    0,                         /*ob_size*/
 
940
    PyVarObject_HEAD_INIT(NULL, 0)
897
941
    "dbus.lowlevel.MethodReturnMessage",  /*tp_name*/
898
942
    0,                         /*tp_basicsize*/
899
943
    0,                         /*tp_itemsize*/
934
978
};
935
979
 
936
980
static PyTypeObject SignalMessageType = {
937
 
    PyObject_HEAD_INIT(NULL)
938
 
    0,                         /*ob_size*/
 
981
    PyVarObject_HEAD_INIT(NULL, 0)
939
982
    "dbus.lowlevel.SignalMessage",  /*tp_name*/
940
983
    0,                         /*tp_basicsize*/
941
984
    0,                         /*tp_itemsize*/
944
987
    0,                         /*tp_getattr*/
945
988
    0,                         /*tp_setattr*/
946
989
    0,                         /*tp_compare*/
947
 
    0,                         /*tp_repr*/
 
990
    SignalMessage_tp_repr,     /*tp_repr*/
948
991
    0,                         /*tp_as_number*/
949
992
    0,                         /*tp_as_sequence*/
950
993
    0,                         /*tp_as_mapping*/
976
1019
};
977
1020
 
978
1021
static PyTypeObject ErrorMessageType = {
979
 
    PyObject_HEAD_INIT(NULL)
980
 
    0,                         /*ob_size*/
 
1022
    PyVarObject_HEAD_INIT(NULL, 0)
981
1023
    "dbus.lowlevel.ErrorMessage",  /*tp_name*/
982
1024
    0,                         /*tp_basicsize*/
983
1025
    0,                         /*tp_itemsize*/