def lookupTemplate(self, request):
"""
Use acquisition to look up the template named by self.templateFile,
located anywhere above this object in the heirarchy, and use it
as the template. The first time the template is used it is cached
for speed.
"""
if self.template:
return microdom.parseString(self.template)
if not self.templateDirectory:
mod = sys.modules[self.__module__]
if hasattr(mod, '__file__'):
self.templateDirectory = os.path.split(mod.__file__)[0]
# First see if templateDirectory + templateFile is a file
templatePath = os.path.join(self.templateDirectory, self.templateFile)
# Check to see if there is an already compiled copy of it
templateName = os.path.splitext(self.templateFile)[0]
compiledTemplateName = '.' + templateName + '.pxp'
compiledTemplatePath = os.path.join(self.templateDirectory, compiledTemplateName)
# No? Compile and save it
if (not os.path.exists(compiledTemplatePath) or
os.stat(compiledTemplatePath)[stat.ST_MTIME] < os.stat(templatePath)[stat.ST_MTIME]):
compiledTemplate = microdom.parse(templatePath)
pickle.dump(compiledTemplate, open(compiledTemplatePath, 'wb'), 1)
else:
compiledTemplate = pickle.load(open(compiledTemplatePath, "rb"))
return compiledTemplate
评论列表
文章目录