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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/* -*- Mode: C; c-basic-offset: 4 -*-
*
* soup-xmlrpc.override: overrides for soup-xmlrpc
*/
%%
ignore
soup_xmlrpc_extract_method_response
%%
override soup_xmlrpc_build_method_call
static char *
pysoup_xmlrpc_build_method_call (PyObject *args, int name_arg)
{
PyObject *py_method_name, *py_param;
Py_ssize_t size, i;
char *method_name, *method_call;
GValueArray *params;
GValue value;
size = PyTuple_Size (args);
if (size <= name_arg) {
PyErr_SetString (PyExc_TypeError, "soup.xmlrpc_build_method_call: 'method_name' not specified");
return NULL;
}
py_method_name = PyTuple_GetItem (args, name_arg);
if (!PyString_Check (py_method_name)) {
PyErr_SetString (PyExc_TypeError, "soup.xmlrpc_build_method_call: 'method_name' must be a string");
return NULL;
}
method_name = PyString_AsString (py_method_name);
params = g_value_array_new (size - name_arg - 1);
for (i = name_arg + 1; i < size; i++) {
py_param = PyTuple_GetItem (args, i);
if (!pysoup_value_from_pyobject (&value, py_param)) {
PyErr_Format (PyExc_TypeError, "soup.xmlrpc_build_method_call: parameter %d could not be converted", (int)i);
g_value_array_free (params);
return NULL;
}
g_value_array_append (params, &value);
g_value_unset (&value);
}
method_call = soup_xmlrpc_build_method_call (method_name, params->values,
params->n_values);
g_value_array_free (params);
return method_call;
}
static PyObject *
_wrap_soup_xmlrpc_build_method_call (PyObject *self, PyObject *args)
{
char *method_call;
PyObject *py_ret;
method_call = pysoup_xmlrpc_build_method_call (args, 0);
if (!method_call)
return NULL;
py_ret = PyString_FromString (method_call);
g_free (method_call);
return py_ret;
}
%%
override soup_xmlrpc_request_new
static PyObject *
_wrap_soup_xmlrpc_request_new (PyObject *self, PyObject *args)
{
char *uri, *method_call;
SoupMessage *msg;
PyObject *py_uri;
if (PyTuple_Size (args) < 1) {
PyErr_SetString (PyExc_TypeError, "soup.xmlrpc_request_new: 'uri' not specified");
return NULL;
}
py_uri = PyTuple_GetItem (args, 0);
if (!PyString_Check (py_uri)) {
PyErr_SetString (PyExc_TypeError, "soup.xmlrpc_request_new: 'uri' must be a string");
return NULL;
}
uri = PyString_AsString (py_uri);
method_call = pysoup_xmlrpc_build_method_call (args, 1);
if (!method_call)
return NULL;
msg = soup_message_new ("POST", uri);
soup_message_set_request (msg, "text/xml", SOUP_MEMORY_TAKE,
method_call, strlen (method_call));
return pygobject_new (G_OBJECT (msg));
}
%%
override soup_xmlrpc_parse_method_response kwargs
static PyObject *
_wrap_soup_xmlrpc_parse_method_response (PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "method_response", NULL };
PyObject *py_method_response;
char *method_response;
Py_ssize_t length;
GError *error = NULL;
GValue value;
PyObject *py_ret;
if (!PyArg_ParseTupleAndKeywords (args, kwargs,
"O:soup.xmlrpc_parse_method_response",
kwlist, &py_method_response))
return NULL;
if (PyString_Check (py_method_response))
PyString_AsStringAndSize (py_method_response, &method_response, &length);
else if (pygobject_check (py_method_response, &PySoupMessage_Type)) {
SoupMessage *msg = (SoupMessage *)(((PyGObject *)py_method_response)->obj);
method_response = (char *)msg->response_body->data;
length = msg->response_body->length;
} else {
PyErr_SetString (PyExc_TypeError, "method_response should be a string or SoupMessage");
return NULL;
}
if (!soup_xmlrpc_parse_method_response (method_response, length,
&value, &error)) {
pyg_error_check (&error);
return NULL;
}
py_ret = pysoup_value_to_pyobject (&value);
g_value_unset (&value);
return py_ret;
}
|