1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include "module.h"
#include "except.h"
#include "response.h"
#include "reply.h"
/*
* Helpers
*/
/*
* Infrastructure
*/
/*
* Members
*/
static PyObject *
xpybReply_getattro(PyObject *self, PyObject *obj)
{
const char *name = PyString_AS_STRING(obj);
xcb_generic_reply_t *data;
Py_ssize_t size;
if (PyObject_AsReadBuffer(self, (const void **)&data, &size) < 0)
return NULL;
if (strcmp(name, "length") == 0)
return Py_BuildValue("I", data->length);
return xpybReply_type.tp_base->tp_getattro(self, obj);
}
/*
* Definition
*/
PyTypeObject xpybReply_type = {
PyObject_HEAD_INIT(NULL)
.tp_name = "xcb.Reply",
.tp_basicsize = sizeof(xpybReply),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = "XCB generic reply object",
.tp_base = &xpybResponse_type,
.tp_getattro = xpybReply_getattro
};
/*
* Module init
*/
int xpybReply_modinit(PyObject *m)
{
if (PyType_Ready(&xpybReply_type) < 0)
return -1;
Py_INCREF(&xpybReply_type);
if (PyModule_AddObject(m, "Reply", (PyObject *)&xpybReply_type) < 0)
return -1;
return 0;
}
|