Permalink
Browse files

Implement valorDefault in C

  • Loading branch information...
1 parent de0eb40 commit e570b82844ac94788cbef9c16f431afbaf6fd483 R. Tyler Ballance committed Jun 28, 2009
Showing with 14 additions and 16 deletions.
  1. +9 −5 src/Template.py
  2. +5 −11 src/c/_template.c
View
@@ -122,11 +122,15 @@ def _genUniqueModuleName(baseModuleName):
# This is only relavent to templates used as CGI scripts.
_formUsedByWebInput = None
-# used in Template.compile()
-def valOrDefault(val, default):
- if val is not None:
- return val
- return default
+try:
+ from Cheetah._template import valOrDefault
+except ImportError:
+ raise
+ # used in Template.compile()
+ def valOrDefault(val, default):
+ if val is not None:
+ return val
+ return default
def updateLinecache(filename, src):
import linecache
View
@@ -9,18 +9,18 @@
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;
+ PyObject *value, *def;
if (!PyArg_ParseTuple(args, "OO", &value, &def))
return NULL;
- if (value == unspecified)
+ if (value == Py_None) {
+ Py_XINCREF(def);
return def;
+ }
+ Py_XINCREF(value);
return value;
}
@@ -36,12 +36,6 @@ 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

0 comments on commit e570b82

Please sign in to comment.