summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cheetah/Template.py107
-rw-r--r--cheetah/Tests/Performance.py31
-rwxr-xr-xsbin/sign3
-rwxr-xr-xsbin/upload16
4 files changed, 65 insertions, 92 deletions
diff --git a/cheetah/Template.py b/cheetah/Template.py
index 01cf676..30ba90d 100644
--- a/cheetah/Template.py
+++ b/cheetah/Template.py
@@ -95,6 +95,7 @@ def hashDict(d):
hashedList.append((k,v))
return hash(tuple(hashedList))
+
################################################################################
## MODULE GLOBALS AND CONSTANTS
@@ -579,19 +580,12 @@ class Template(Servlet):
preprocessors=[ dict(tokens='@ %', searchList=[...]) ] )
"""
- ##################################################
- ## normalize and validate args
- N = types.NoneType; S = types.StringType; U = types.UnicodeType
- D = types.DictType; F = types.FileType
- C = types.ClassType; M = types.ModuleType
- I = types.IntType; B = types.BooleanType
errmsg = "arg '%s' must be %s"
- t = type(source)
- if not (t is N or t is S or t is U):
+ if not isinstance(source, (types.NoneType, basestring)):
raise TypeError(errmsg % ('source', 'string or None'))
- t = type(file)
- if not (t is N or t is S or t is U or t is F):
+
+ if not isinstance(file, (types.NoneType, basestring, types.FileType)):
raise TypeError(errmsg %
('file', 'string, file-like object, or None'))
@@ -599,25 +593,25 @@ class Template(Servlet):
baseclass = klass._CHEETAH_defaultBaseclassForTemplates
if isinstance(baseclass, Template):
baseclass = baseclass.__class__
- t = type(baseclass)
- if not (t is N or t is S or t is C or t is type):
+
+ if not isinstance(baseclass, (types.NoneType, basestring, types.ClassType, types.TypeType)):
raise TypeError(errmsg % ('baseclass', 'string, class or None'))
if cacheCompilationResults is Unspecified:
cacheCompilationResults = klass._CHEETAH_cacheCompilationResults
- t = type(cacheCompilationResults)
- if not (t is I or t is B):
+
+ if not isinstance(cacheCompilationResults, (int, bool)):
raise TypeError(errmsg % ('cacheCompilationResults', 'boolean'))
if useCache is Unspecified:
useCache = klass._CHEETAH_useCompilationCache
- t = type(useCache)
- if not (t is I or t is B):
+
+ if not isinstance(useCache, (int, bool)):
raise TypeError(errmsg % ('useCache', 'boolean'))
if compilerSettings is Unspecified:
compilerSettings = klass._getCompilerSettings(source, file) or {}
- if type(compilerSettings) is not D:
+ if not isinstance(compilerSettings, dict):
raise TypeError(errmsg % ('compilerSettings', 'dictionary'))
if compilerClass is Unspecified:
@@ -627,16 +621,15 @@ class Template(Servlet):
if keepRefToGeneratedCode is Unspecified:
keepRefToGeneratedCode = klass._CHEETAH_keepRefToGeneratedCode
- t = type(keepRefToGeneratedCode)
- if not (t is I or t is B):
+
+ if not isinstance(keepRefToGeneratedCode, (int, bool)):
raise TypeError(errmsg % ('keepReftoGeneratedCode', 'boolean'))
- t = type(moduleName)
- if not (t is N or t is S):
+ if not isinstance(moduleName, (types.NoneType, basestring)):
raise TypeError(errmsg % ('moduleName', 'string or None'))
__orig_file__ = None
if not moduleName:
- if file and type(file) in StringTypes:
+ if file and isinstance(file, basestring):
moduleName = convertTmplPathToModuleName(file)
__orig_file__ = file
else:
@@ -644,15 +637,15 @@ class Template(Servlet):
if className is Unspecified:
className = klass._CHEETAH_defaultClassNameForTemplates
- t = type(className)
- if not (t is N or t is S):
+
+ if not isinstance(className, (types.NoneType, basestring)):
raise TypeError(errmsg % ('className', 'string or None'))
className = className or moduleName
if mainMethodName is Unspecified:
mainMethodName = klass._CHEETAH_defaultMainMethodNameForTemplates
- t = type(mainMethodName)
- if not (t is N or t is S):
+
+ if not isinstance(mainMethodName, (types.NoneType, basestring)):
raise TypeError(errmsg % ('mainMethodName', 'string or None'))
if moduleGlobals is Unspecified:
@@ -660,15 +653,15 @@ class Template(Servlet):
if cacheModuleFilesForTracebacks is Unspecified:
cacheModuleFilesForTracebacks = klass._CHEETAH_cacheModuleFilesForTracebacks
- t = type(cacheModuleFilesForTracebacks)
- if not (t is I or t is B):
+
+ if not isinstance(cacheModuleFilesForTracebacks, (int, bool)):
raise TypeError(errmsg %
('cacheModuleFilesForTracebacks', 'boolean'))
if cacheDirForModuleFiles is Unspecified:
cacheDirForModuleFiles = klass._CHEETAH_cacheDirForModuleFiles
- t = type(cacheDirForModuleFiles)
- if not (t is N or t is S):
+
+ if not isinstance(cacheDirForModuleFiles, (types.NoneType, basestring)):
raise TypeError(errmsg %
('cacheDirForModuleFiles', 'string or None'))
@@ -683,9 +676,9 @@ class Template(Servlet):
baseclassValue = None
baseclassName = None
if baseclass:
- if type(baseclass) in StringTypes:
+ if isinstance(baseclass, basestring):
baseclassName = baseclass
- elif type(baseclass) in (ClassType, type):
+ elif isinstance(baseclass, (types.ClassType, types.TypeType)):
# @@TR: should soft-code this
baseclassName = 'CHEETAH_dynamicallyAssignedBaseClass_'+baseclass.__name__
baseclassValue = baseclass
@@ -1142,46 +1135,41 @@ class Template(Servlet):
Do NOT mess with the args _globalSetVars or _preBuiltSearchList!
- """
-
- ##################################################
- ## Verify argument keywords and types
- S = types.StringType; U = types.UnicodeType
- L = types.ListType; T = types.TupleType
- D = types.DictType; F = types.FileType
- C = types.ClassType; M = types.ModuleType
- N = types.NoneType
+ """
errmsg = "arg '%s' must be %s"
errmsgextra = errmsg + "\n%s"
- t = type(source)
- if not (t is N or t is S or t is U):
+ if not isinstance(source, (types.NoneType, basestring)):
raise TypeError(errmsg % ('source', 'string or None'))
- t = type(file)
- if not (t is N or t is S or t is U or t is F):
+
+ if not isinstance(source, (types.NoneType, basestring, types.FileType)):
raise TypeError(errmsg %
('file', 'string, file open for reading, or None'))
- t = type(filter)
- if not (t is S or (t is C and issubclass(filter, Filters.Filter)) or
- t is type):
+
+ if not isinstance(filter, (basestring, types.TypeType)) and not \
+ (isinstance(filter, types.ClassType) and issubclass(filter, Filters.Filter)):
raise TypeError(errmsgextra %
('filter', 'string or class',
'(if class, must be subclass of Cheetah.Filters.Filter)'))
- t = type(filtersLib)
- if not (t is S or t is M):
+ if not isinstance(filtersLib, (basestring, types.ModuleType)):
raise TypeError(errmsgextra %
('filtersLib', 'string or module',
'(if module, must contain subclasses of Cheetah.Filters.Filter)'))
- t = type(errorCatcher)
- if not (t is N or t is S or
- (t is C and issubclass(errorCatcher, ErrorCatchers.ErrorCatcher)) or
- t is type):
- raise TypeError(errmsgextra %
+
+ if not errorCatcher is None:
+ err = True
+ if isinstance(errorCatcher, (basestring, types.TypeType)):
+ err = False
+ if isinstance(errorCatcher, types.ClassType) and \
+ issubclass(errorCatcher, ErrorCatchers.ErrorCatcher):
+ err = False
+ if err:
+ raise TypeError(errmsgextra %
('errorCatcher', 'string, class or None',
'(if class, must be subclass of Cheetah.ErrorCatchers.ErrorCatcher)'))
if compilerSettings is not Unspecified:
- if type(compilerSettings) is not D:
+ if not isinstance(compilerSettings, types.DictType):
raise TypeError(errmsg %
('compilerSettings', 'dictionary'))
@@ -1213,11 +1201,10 @@ class Template(Servlet):
##################################################
## Setup instance state attributes used during the life of template
## post-compile
- reserved_searchlist = dir(self)
if searchList:
for namespace in searchList:
if isinstance(namespace, dict):
- intersection = set(reserved_searchlist) & set(namespace.keys())
+ intersection = Reserved_SearchList & set(namespace.keys())
warn = False
if intersection:
warn = True
@@ -1526,7 +1513,7 @@ class Template(Servlet):
self._fileMtime = None
self._fileDirName = None
self._fileBaseName = None
- if file and type(file) in StringTypes:
+ if file and isinstance(file, basestring):
file = self.serverSidePath(file)
self._fileMtime = os.path.getmtime(file)
self._fileDirName, self._fileBaseName = os.path.split(file)
@@ -1832,7 +1819,7 @@ class Template(Servlet):
return dic
T = Template # Short and sweet for debugging at the >>> prompt.
-
+Reserved_SearchList = set(dir(Template))
def genParserErrorFromPythonException(source, file, generatedPyCode, exception):
diff --git a/cheetah/Tests/Performance.py b/cheetah/Tests/Performance.py
index 0f7d613..3dcd8c5 100644
--- a/cheetah/Tests/Performance.py
+++ b/cheetah/Tests/Performance.py
@@ -1,9 +1,7 @@
#!/usr/bin/env python
-import Cheetah.NameMapper
-import Cheetah.Template
-from Cheetah.Utils import statprof
-
+import hotshot
+import hotshot.stats
import os
import sys
import unittest
@@ -11,6 +9,9 @@ import unittest
from test import pystone
import time
+import Cheetah.NameMapper
+import Cheetah.Template
+
# This can be turned on with the `--debug` flag when running the test
# and will cause the tests to all just dump out how long they took
# insteasd of asserting on duration
@@ -83,25 +84,29 @@ class DynamicTemplatePerformanceTest(unittest.TestCase):
test_BasicDynamic = perftest(1200)(test_BasicDynamic)
class PerformanceTest(unittest.TestCase):
- iterations = 1000000
+ iterations = 100000
display = False
- def setUp(self):
- super(PerformanceTest, self).setUp()
- statprof.start()
+ save = False
def runTest(self):
+ self.prof = hotshot.Profile('%s.prof' % self.__class__.__name__)
+ self.prof.start()
for i in xrange(self.iterations):
if hasattr(self, 'performanceSample'):
self.display = True
self.performanceSample()
-
- def tearDown(self):
- super(PerformanceTest, self).tearDown()
- statprof.stop()
+ self.prof.stop()
+ self.prof.close()
if self.display:
print '>>> %s (%d iterations) ' % (self.__class__.__name__,
self.iterations)
- statprof.display()
+ stats = hotshot.stats.load('%s.prof' % self.__class__.__name__)
+ #stats.strip_dirs()
+ stats.sort_stats('time', 'calls')
+ stats.print_stats(50)
+
+ if not self.save:
+ os.unlink('%s.prof' % self.__class__.__name__)
class DynamicMethodCompilationTest(PerformanceTest):
def performanceSample(self):
diff --git a/sbin/sign b/sbin/sign
deleted file mode 100755
index 5f68159..0000000
--- a/sbin/sign
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-release=$1
-gpg --armor --detach-sign dist/Cheetah-${release}.tar.gz
diff --git a/sbin/upload b/sbin/upload
deleted file mode 100755
index 4dcebd6..0000000
--- a/sbin/upload
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-release=$1
-echo curl -T dist/Cheetah-${release}.tar.gz.asc ftp://anonymous@upload.sourceforge.net/incoming/
-curl -T dist/Cheetah-${release}.tar.gz.asc ftp://anonymous@upload.sourceforge.net/incoming/
-
-echo curl -T dist/Cheetah-${release}.tar.gz ftp://anonymous@upload.sourceforge.net/incoming/
-curl -T dist/Cheetah-${release}.tar.gz ftp://anonymous@upload.sourceforge.net/incoming/
-
-echo scp CHANGES tavis_rudd@cheetahtemplate.sourceforge.net:www/docs/
-scp CHANGES tavis_rudd@cheetahtemplate.sourceforge.net:www/docs/
-
-echo scp TODO tavis_rudd@cheetahtemplate.sourceforge.net:www/docs/
-scp TODO tavis_rudd@cheetahtemplate.sourceforge.net:www/docs/
-
-echo scp BUGS tavis_rudd@cheetahtemplate.sourceforge.net:www/docs/
-scp BUGS tavis_rudd@cheetahtemplate.sourceforge.net:www/docs/