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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/* -*- Mode: C; c-basic-offset: 4 -*-
*
* SoupMessageHeaders.override: overrides for SoupMessageHeaders
*/
%%
ignore
soup_message_headers_foreach
%%
override-slot SoupMessageHeaders.tp_as_mapping
static PyObject *
_wrap_soup_message_headers_tp_getitem (PyGObject *self, PyObject *item)
{
char *name;
const char *value;
if (!PyString_Check (item)) {
PyErr_SetString (PyExc_TypeError,
"could not parse subscript as a header name");
return NULL;
}
name = PyString_AsString (item);
value = soup_message_headers_get ((SoupMessageHeaders *)self->obj, name);
return Py_BuildValue ("s", value);
}
static int
_wrap_soup_message_headers_tp_setitem (PyGObject *self, PyObject *item,
PyObject *value)
{
char *name, *string_value;
if (!PyString_Check (item)) {
PyErr_SetString (PyExc_TypeError,
"could not parse subscript as a header name");
return -1;
}
name = PyString_AsString (item);
if (!PyString_Check (value)) {
PyErr_SetString (PyExc_TypeError,
"could not parse value as a string");
return -1;
}
string_value = PyString_AsString (value);
soup_message_headers_replace ((SoupMessageHeaders *)self->obj, name,
string_value);
return 0;
}
static PyMappingMethods _wrap_soup_message_headers_tp_as_mapping = {
(lenfunc) NULL,
(binaryfunc)_wrap_soup_message_headers_tp_getitem,
(objobjargproc)_wrap_soup_message_headers_tp_setitem
};
%%
override-slot SoupMessageHeaders.tp_iter
typedef struct {
PyObject_HEAD
SoupMessageHeadersIter iter;
} PySoupMessageHeadersIter;
static void
pysoup_message_headers_iter_dealloc (PySoupMessageHeadersIter *iter)
{
soup_message_headers_iter_free (&iter->iter);
PyObject_Del ((PyObject*) iter);
}
static PyObject *
pysoup_message_headers_iter_next (PySoupMessageHeadersIter *iter)
{
const char *name, *value;
if (!soup_message_headers_iter_next (&iter->iter, &name, &value)) {
PyErr_SetNone (PyExc_StopIteration);
return NULL;
}
return Py_BuildValue ("(ss)", name, value);
}
static PyTypeObject PySoupMessageHeadersIter_Type = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"soup.SoupMessageHeadersIter", /* tp_name */
sizeof (PySoupMessageHeadersIter), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)pysoup_message_headers_iter_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"SoupMessageHeaders iterator", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
(iternextfunc)pysoup_message_headers_iter_next, /* tp_iternext */
};
static PyObject *
_wrap_soup_message_headers_tp_iter (PyGObject *self)
{
PySoupMessageHeadersIter *iter;
iter = PyObject_NEW (PySoupMessageHeadersIter,
&PySoupMessageHeadersIter_Type);
soup_message_headers_iter_init (&iter->iter,
(SoupMessageHeaders *)self->obj);
return (PyObject *) iter;
}
%%
override soup_message_headers_get_content_length
static PyObject *
_wrap_soup_message_headers_get_content_length (PyObject *self)
{
goffset content_length;
content_length = soup_message_headers_get_content_length (pyg_boxed_get (self, SoupMessageHeaders));
return PyLong_FromLongLong (content_length);
}
%%
override soup_message_headers_set_content_length
static PyObject *
_wrap_soup_message_headers_set_content_length (PyObject *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "content_length", NULL };
long long content_length;
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"L:SoupMessageHeaders.set_content_length",
kwlist, &content_length))
return NULL;
soup_message_headers_set_content_length (pyg_boxed_get (self, SoupMessageHeaders), content_length);
Py_INCREF(Py_None);
return Py_None;
}
|