This repository has been archived by the owner on Mar 8, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
_template.c should grow to include minor utility methods that benefit…
… 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |