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

Commit

Permalink
Merge commit 'abbeyj/performance' into performance
Browse files Browse the repository at this point in the history
Conflicts:
	src/Template.py
	src/c/_template.c
  • Loading branch information
R. Tyler Ballance committed Jun 28, 2009
2 parents 899407b + 714a46b commit c38cbeb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
3 changes: 3 additions & 0 deletions SetupConfig.py
Expand Up @@ -34,6 +34,7 @@

import os
import os.path
import sys
from distutils.core import Extension

ext_modules=[
Expand All @@ -51,6 +52,8 @@
scripts = ['bin/cheetah-compile',
'bin/cheetah',
]
if sys.platform == "win32":
scripts.append('bin/cheetah.bat')
data_files = ['recursive: src *.tmpl *.txt LICENSE README TODO CHANGES',
]
if not os.getenv('CHEETAH_INSTALL_WITHOUT_SETUPTOOLS'):
Expand Down
1 change: 1 addition & 0 deletions bin/.gitattributes
@@ -0,0 +1 @@
cheetah.bat -crlf
1 change: 1 addition & 0 deletions bin/cheetah.bat
@@ -0,0 +1 @@
@"%~dp0..\python" "%~dpn0" %*
39 changes: 15 additions & 24 deletions src/Template.py
Expand Up @@ -25,11 +25,6 @@
from types import StringTypes
except ImportError:
StringTypes = (types.StringType,types.UnicodeType)
try:
from types import BooleanType
boolTypeAvailable = True
except ImportError:
boolTypeAvailable = False

try:
from threading import Lock
Expand Down Expand Up @@ -607,11 +602,11 @@ def __str__(self): return self.respond()
N = types.NoneType; S = types.StringType; U = types.UnicodeType
D = types.DictType; F = types.FileType
C = types.ClassType; M = types.ModuleType
I = types.IntType
I = types.IntType; B = types.BooleanType

IB = (I, B)
NS = (N, S)

if boolTypeAvailable:
B = types.BooleanType

vt(source, 'source', (N,S,U), 'string or None')
vt(file, 'file',(N,S,U,F), 'string, file-like object, or None')

Expand All @@ -622,12 +617,10 @@ def __str__(self): return self.respond()

cacheCompilationResults = valOrDefault(
cacheCompilationResults, klass._CHEETAH_cacheCompilationResults)
if boolTypeAvailable:
vt(cacheCompilationResults, 'cacheCompilationResults', (I,B), 'boolean')
vt(cacheCompilationResults, 'cacheCompilationResults', IB, 'boolean')

useCache = valOrDefault(useCache, klass._CHEETAH_useCompilationCache)
if boolTypeAvailable:
vt(cacheCompilationResults, 'cacheCompilationResults', (I,B), 'boolean')
vt(useCache, 'useCache', IB, 'boolean')

compilerSettings = valOrDefault(
compilerSettings, klass._getCompilerSettings(source, file) or {})
Expand All @@ -638,38 +631,36 @@ def __str__(self): return self.respond()

keepRefToGeneratedCode = valOrDefault(
keepRefToGeneratedCode, klass._CHEETAH_keepRefToGeneratedCode)
if boolTypeAvailable:
vt(cacheCompilationResults, 'cacheCompilationResults', (I,B), 'boolean')

vt(moduleName, 'moduleName', (N,S), 'string or None')
vt(keepRefToGeneratedCode, 'keepRefToGeneratedCode', IB, 'boolean')

vt(moduleName, 'moduleName', NS, 'string or None')
__orig_file__ = None
if not moduleName:
if file and type(file) in StringTypes:
moduleName = convertTmplPathToModuleName(file)
__orig_file__ = file
else:
moduleName = klass._CHEETAH_defaultModuleNameForTemplates

className = valOrDefault(
className, klass._CHEETAH_defaultClassNameForTemplates)
vt(className, 'className', (N,S), 'string or None')
vt(className, 'className', NS, 'string or None')
className = className or moduleName

mainMethodName = valOrDefault(
mainMethodName, klass._CHEETAH_defaultMainMethodNameForTemplates)
vt(mainMethodName, 'mainMethodName', (N,S), 'string or None')
vt(mainMethodName, 'mainMethodName', NS, 'string or None')

moduleGlobals = valOrDefault(
moduleGlobals, klass._CHEETAH_defaultModuleGlobalsForTemplates)

cacheModuleFilesForTracebacks = valOrDefault(
cacheModuleFilesForTracebacks, klass._CHEETAH_cacheModuleFilesForTracebacks)
if boolTypeAvailable:
vt(cacheModuleFilesForTracebacks, 'cacheModuleFilesForTracebacks', (I,B), 'boolean')

vt(cacheModuleFilesForTracebacks, 'cacheModuleFilesForTracebacks', IB, 'boolean')

cacheDirForModuleFiles = valOrDefault(
cacheDirForModuleFiles, klass._CHEETAH_cacheDirForModuleFiles)
vt(cacheDirForModuleFiles, 'cacheDirForModuleFiles', (N,S), 'string or None')
vt(cacheDirForModuleFiles, 'cacheDirForModuleFiles', NS, 'string or None')

except TypeError, reason:
raise TypeError(reason)
Expand Down
15 changes: 15 additions & 0 deletions src/Tests/Template.py
Expand Up @@ -326,7 +326,22 @@ def test_BasicDecorator(self):
except AttributeError, ex:
self.fail(ex)

class Useless(object):
def boink(self):
return [1, 2, 3]

class MultipleInheritanceSupport(TemplateTest):
def runTest(self):
template = '''
#extends Template, Useless
#def foo()
#return [4,5] + $boink()
#end def
'''
template = Template.compile(template)
template = template()
result = template.foo()
print result


##################################################
Expand Down
8 changes: 4 additions & 4 deletions src/c/_template.c
Expand Up @@ -14,7 +14,7 @@ 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;
Expand All @@ -31,7 +31,7 @@ static const char _template_doc[] = "\
\n\
";
static struct PyMethodDef _template_methods[] = {
{"valOrDefault", py_valordefault, METH_VARARGS, NULL},
{"valOrDefault", (PyCFunction)py_valordefault, METH_VARARGS, NULL},
{NULL}
};

Expand All @@ -41,10 +41,10 @@ PyMODINIT_FUNC init_template()
_template_doc);
unspecifiedModule = PyImport_ImportModule("Cheetah.Unspecified");
if ( (PyErr_Occurred()) || (!unspecifiedModule) )
return NULL;
return;
unspecified = PyObject_GetAttrString(unspecifiedModule, "Unspecified");
if (PyErr_Occurred())
return NULL;
return;
}

#ifdef __cplusplus
Expand Down

0 comments on commit c38cbeb

Please sign in to comment.