Files

38 lines
816 B
Python
Raw Permalink Normal View History

2021-05-03 11:45:43 -04:00
SPAM_C_TEMPLATE = r"""
2020-05-02 16:54:19 +01:00
#include <Python.h>
2020-05-02 16:54:19 +01:00
{{ spam_c_top_level_add }}
2020-05-02 16:54:19 +01:00
static PyObject *
spam_filter(PyObject *self, PyObject *args)
2020-05-02 16:54:19 +01:00
{
const char *content;
2020-05-02 16:54:19 +01:00
int sts;
2020-05-02 09:59:55 +01: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
// Spam should not be allowed through the filter.
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-05-02 16:54:19 +01:00
/* Module initialization */
static PyMethodDef module_methods[] = {
{"filter", (PyCFunction)spam_filter, METH_VARARGS,
2020-05-02 16:54:19 +01:00
"Execute a shell command."},
{NULL} /* Sentinel */
};
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
"""