2021-05-03 11:45:43 -04:00
|
|
|
SPAM_C_TEMPLATE = r"""
|
2020-05-02 16:54:19 +01:00
|
|
|
#include <Python.h>
|
2020-04-25 16:09:11 +01:00
|
|
|
|
2020-05-02 16:54:19 +01:00
|
|
|
{{ spam_c_top_level_add }}
|
2020-04-25 16:09:11 +01:00
|
|
|
|
2020-05-02 16:54:19 +01:00
|
|
|
static PyObject *
|
2025-03-12 04:48:35 +08:00
|
|
|
spam_filter(PyObject *self, PyObject *args)
|
2020-05-02 16:54:19 +01:00
|
|
|
{
|
2025-03-12 04:48:35 +08:00
|
|
|
const char *content;
|
2020-05-02 16:54:19 +01:00
|
|
|
int sts;
|
2020-05-02 09:59:55 +01:00
|
|
|
|
2025-03-12 04:48:35 +08:00
|
|
|
if (!PyArg_ParseTuple(args, "s", &content))
|
2020-05-02 16:54:19 +01:00
|
|
|
return NULL;
|
2020-05-02 09:59:55 +01:00
|
|
|
|
2025-03-12 04:48:35 +08:00
|
|
|
// Spam should not be allowed through the filter.
|
2025-07-23 22:18:33 +01:00
|
|
|
sts = strcmp(content, "spam") != 0;
|
2020-05-02 09:59:55 +01:00
|
|
|
|
2020-05-02 16:54:19 +01:00
|
|
|
{{ spam_c_function_add | indent(4) }}
|
2020-05-02 09:59:55 +01:00
|
|
|
|
2020-05-02 16:54:19 +01:00
|
|
|
return PyLong_FromLong(sts);
|
|
|
|
|
}
|
2020-04-25 16:09:11 +01:00
|
|
|
|
2020-05-02 16:54:19 +01:00
|
|
|
/* Module initialization */
|
|
|
|
|
static PyMethodDef module_methods[] = {
|
2025-03-12 04:48:35 +08:00
|
|
|
{"filter", (PyCFunction)spam_filter, METH_VARARGS,
|
2020-05-02 16:54:19 +01:00
|
|
|
"Execute a shell command."},
|
|
|
|
|
{NULL} /* Sentinel */
|
|
|
|
|
};
|
2020-04-25 16:09:11 +01:00
|
|
|
|
2021-02-14 20:44:20 +01:00
|
|
|
PyMODINIT_FUNC PyInit_spam(void)
|
2020-05-02 16:54:19 +01:00
|
|
|
{
|
2021-02-14 20:44:20 +01:00
|
|
|
static struct PyModuleDef moduledef = {
|
|
|
|
|
PyModuleDef_HEAD_INIT, "spam", "Example module", -1, module_methods,
|
|
|
|
|
};
|
|
|
|
|
return PyModule_Create(&moduledef);
|
2020-05-02 16:54:19 +01:00
|
|
|
}
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|