| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <Python.h> |
| 7 |
|
| 8 |
#ifdef __cplusplus |
| 9 |
extern "C" { |
| 10 |
#endif |
| 11 |
|
| 12 |
static PyObject *unspecifiedModule = NULL; |
| 13 |
static PyObject *unspecified = NULL; |
| 14 |
|
| 15 |
static PyObject *py_valordefault(PyObject *self, PyObject *args, PyObject *kwargs) |
| 16 |
{ |
| 17 |
PyObject *value, *def; |
| 18 |
|
| 19 |
if (!PyArg_ParseTuple(args, "OO", &value, &def)) |
| 20 |
return NULL; |
| 21 |
|
| 22 |
if (value == unspecified) { |
| 23 |
Py_XINCREF(def); |
| 24 |
return def; |
| 25 |
} |
| 26 |
Py_XINCREF(value); |
| 27 |
return value; |
| 28 |
} |
| 29 |
|
| 30 |
static const char _template_doc[] = "\ |
| 31 |
\n\ |
| 32 |
"; |
| 33 |
static struct PyMethodDef _template_methods[] = { |
| 34 |
{"valOrDefault", (PyCFunction)py_valordefault, METH_VARARGS, NULL}, |
| 35 |
{NULL} |
| 36 |
}; |
| 37 |
|
| 38 |
PyMODINIT_FUNC init_template() |
| 39 |
{ |
| 40 |
PyObject *module = Py_InitModule3("_template", _template_methods, |
| 41 |
_template_doc); |
| 42 |
unspecifiedModule = PyImport_ImportModule("Cheetah.Unspecified"); |
| 43 |
if ( (PyErr_Occurred()) || (!unspecifiedModule) ) |
| 44 |
return; |
| 45 |
unspecified = PyObject_GetAttrString(unspecifiedModule, "Unspecified"); |
| 46 |
if (PyErr_Occurred()) |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
#ifdef __cplusplus |
| 51 |
} |
| 52 |
#endif |