The template:
#import pprint #errorCatcher ListErrors $noValue $anotherMissingValue.really $pprint.pformat($errorCatcher.listErrors) ## This is really self.errorCatcher().listErrors()
The output:
$noValue
$anotherMissingValue.really
[{'code': 'VFS(SL,"noValue",1)',
'exc_val': <NameMapper.NotFound instance at 0x8170ecc>,
'lineCol': (3, 1),
'rawCode': '$noValue',
'time': 'Wed May 15 00:38:23 2002'},
{'code': 'VFS(SL,"anotherMissingValue.really",1)',
'exc_val': <NameMapper.NotFound instance at 0x816d0fc>,
'lineCol': (4, 1),
'rawCode': '$anotherMissingValue.really',
'time': 'Wed May 15 00:38:23 2002'}]
The generated import:
import pprint
Then in the generated class, we have our familiar .respond method
and several new methods:
def __errorCatcher1(self, localsDict={}):
"""
Generated from $noValue at line, col (3, 1).
"""
try:
return eval('''VFS(SL,"noValue",1)''', globals(), localsDict)
except self._errorCatcher.exceptions(), e:
return self._errorCatcher.warn(exc_val=e, code= 'VFS(SL,"noValue",1)' ,
rawCode= '$noValue' , lineCol=(3, 1))
def __errorCatcher2(self, localsDict={}):
"""
Generated from $anotherMissingValue.really at line, col (4, 1).
"""
try:
return eval('''VFS(SL,"anotherMissingValue.really",1)''', globals(),
localsDict)
except self._errorCatcher.exceptions(), e:
return self._errorCatcher.warn(exc_val=e,
code= 'VFS(SL,"anotherMissingValue.really",1)' ,
rawCode= '$anotherMissingValue.really' , lineCol=(4, 1))
def __errorCatcher3(self, localsDict={}):
"""
Generated from $pprint.pformat($errorCatcher.listErrors) at line, col
(5, 1).
"""
try:
return eval('''VFN(pprint,"pformat",0)(VFS(SL,
"errorCatcher.listErrors",1))''', globals(), localsDict)
except self._errorCatcher.exceptions(), e:
return self._errorCatcher.warn(exc_val=e, code=
'VFN(pprint,"pformat",0)(VFS(SL,"errorCatcher.listErrors",1))' ,
rawCode= '$pprint.pformat($errorCatcher.listErrors)' ,
lineCol=(5, 1))
def respond(self,
trans=None,
dummyTrans=False,
VFS=valueFromSearchList,
VFN=valueForName,
getmtime=getmtime,
currentTime=time.time):
"""
This is the main method generated by Cheetah
"""
if not trans:
trans = DummyTransaction()
dummyTrans = True
write = trans.response().write
SL = self._searchList
filter = self._currentFilter
globalSetVars = self._globalSetVars
########################################
## START - generated method body
if exists(self._filePath) and getmtime(self._filePath) > self._fileMtime:
self.compile(file=self._filePath)
write(getattr(self, self._mainCheetahMethod_for_x)(trans=trans))
if dummyTrans:
return trans.response().getvalue()
else:
return ""
if self._errorCatchers.has_key("ListErrors"):
self._errorCatcher = self._errorCatchers["ListErrors"]
else:
self._errorCatcher = self._errorCatchers["ListErrors"] = \
ErrorCatchers.ListErrors(self)
write(filter(self.__errorCatcher1(localsDict=locals())))
# generated from '$noValue' at line 3, col 1.
write('\n')
write(filter(self.__errorCatcher2(localsDict=locals())))
# generated from '$anotherMissingValue.really' at line 4, col 1.
write('\n')
write(filter(self.__errorCatcher3(localsDict=locals())))
# generated from '$pprint.pformat($errorCatcher.listErrors)' at line
# 5, col 1.
write('\n')
# This is really self.errorCatcher().listErrors()
########################################
## END - generated method body
if dummyTrans:
return trans.response().getvalue()
else:
return ""
So whenever an error catcher is active, each placeholder gets wrapped in its own method. No wonder error catchers slow down the system!