Skip to content
This repository has been archived by the owner on Mar 8, 2018. It is now read-only.

Commit

Permalink
_template.c should grow to include minor utility methods that benefit…
Browse files Browse the repository at this point in the history
… from moving into C
  • Loading branch information
R. Tyler Ballance committed Jun 28, 2009
1 parent f742451 commit cec1d6b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/c/_template.c
@@ -0,0 +1,49 @@
/*
* Implementing a few of the functions needed for Template.py in C
*
* (c) 2009, R. Tyler Ballance <tyler@slide.com>
*/
#include <Python.h>

#ifdef __cplusplus
extern "C" {
#endif

static PyObject *unspecifiedModule = NULL;
static PyObject *unspecified = NULL;

static PyObject *py_valordefault(PyObject *self, PyObject *args, PyObject *kwargs)
{
PyObject *value, *def, *res;

if (!PyArg_ParseTuple(args, "OO", &value, &def))
return NULL;

if (value == unspecified)
return def;
return value;
}

static const char _template_doc[] = "\
\n\
";
static struct PyMethodDef _template_methods[] = {
{"valOrDefault", py_valordefault, METH_VARARGS, NULL},
{NULL}
};

PyMODINIT_FUNC init_template()
{
PyObject *module = Py_InitModule3("_template", _template_methods,
_template_doc);
unspecifiedModule = PyImport_ImportModule("Cheetah.Unspecified");
if ( (PyErr_Occurred()) || (!unspecifiedModule) )
return NULL;
unspecified = PyObject_GetAttrString(unspecifiedModule, "Unspecified");
if (PyErr_Occurred())
return NULL;
}

#ifdef __cplusplus
}
#endif

0 comments on commit cec1d6b

Please sign in to comment.