PK\r7;><<turbocheetah/cheetahsupport.py"""Template support for Cheetah""" import sys from os import stat from imp import new_module from threading import RLock from logging import getLogger from pkg_resources import resource_filename from Cheetah import Compiler log = getLogger("turbokid.kidsupport") def _compile_template(package, basename, tfile): code = str(Compiler.Compiler(file=tfile, mainClassName=basename)) modname = '%s.%s' % (package, basename) mod = new_module(modname) ns = dict() exec code in ns mainclass = ns[basename] setattr(mod, basename, mainclass) sys.modules[modname] = mod return mod class CheetahSupport(object): extension = ".tmpl" importhooks = False precompiled = False def __init__(self, extra_vars_func=None, options=None): if options is None: options = dict() self.get_extra_vars = extra_vars_func self.options = options self.compiledTemplates = {} self.precompiled = options.get( "cheetah.precompiled", CheetahSupport.precompiled) if not self.precompiled: self.compile_lock = RLock() if not CheetahSupport.importhooks and options.get( "cheetah.importhooks", False): from Cheetah import ImportHooks # needs Cheetah 2.0.1 ImportHooks.install(templateFileExtensions=(self.extension,)) CheetahSupport.importhooks = True def load_template(self, template): """Search for a template along the Python path. Cheetah template files must end in ".tmpl" and must be contained in legitimate Python packages. """ if not template: raise ValueError, "You must pass a template as parameter" divider = template.rfind(".") if divider > -1: package, basename = template[:divider], template[divider+1:] else: raise ValueError, "All Cheetah templates must be in a package" if self.precompiled: mod = __import__(template, dict(), dict(), [basename]) else: tfile = resource_filename(package, basename + self.extension) ct = self.compiledTemplates self.compile_lock.acquire() try: try: mtime = stat(tfile).st_mtime except OSError: mtime = None # if this is not really coming from a file if ct.has_key(template): if ct[template] == mtime: mod = __import__(template, dict(), dict(), [basename]) else: del sys.modules[template] mod = _compile_template(package, basename, tfile) ct[template] = mtime else: mod = _compile_template(package, basename, tfile) ct[template] = mtime finally: self.compile_lock.release() mainclass = getattr(mod, basename) return mainclass def render(self, info, format="html", fragment=False, template=None): """Renders data in the desired format. @param info: the data itself @type info: dict @param format: Cheetah output method (not used) @type format: string @param fragment: passed through to tell the template if only a fragment of a page is desired @type fragment: bool @param template: the name of the Cheetah template to use @type template: string """ tempclass = self.load_template(template) if self.get_extra_vars: extra = self.get_extra_vars() else: extra = {} tempobj = tempclass(searchList=[info, extra]) if fragment: return tempobj.fragment() else: return tempobj.respond() PK\r7mLuuturbocheetah/__init__.pyfrom turbocheetah import cheetahsupport CheetahSupport = cheetahsupport.CheetahSupport __all__ = ["CheetahSupport"]PKr7bwturbocheetah/cheetahsupport.pyc; t@Gc@sdZdkZdklZdklZdklZdkl Z dk l Z dk l Z e dZd Zd efd YZdS( sTemplate support for CheetahN(sstat(s new_module(sRLock(s getLogger(sresource_filename(sCompilersturbokid.kidsupportcBszeeid|d|}d||f}e|}e }||U||}e ||||e i|<|SdS(Nsfiles mainClassNames%s.%s(sstrsCompilerstfilesbasenamescodespackagesmodnames new_modulesmodsdictsnss mainclassssetattrssyssmodules(spackagesbasenamestfilesmodnamescodesnss mainclasssmod((s4build\bdist.win32\egg\turbocheetah\cheetahsupport.pys_compile_templates    sCheetahSupportcBsDtZdZeZeZeedZdZdeedZ RS(Ns.tmplcCs|tjo t}n||_||_h|_|idti |_ |i ot |_ nti o|idt o0dkl}|id|iftt_ ndS(Nscheetah.precompiledscheetah.importhooks(s ImportHooksstemplateFileExtensions(soptionssNonesdictsextra_vars_funcsselfsget_extra_varsscompiledTemplatessgetsCheetahSupports precompiledsRLocks compile_locks importhookssFalsesCheetahs ImportHookssinstalls extensionsTrue(sselfsextra_vars_funcsoptionss ImportHooks((s4build\bdist.win32\egg\turbocheetah\cheetahsupport.pys__init__"s       c Cs| o tdn|id}|djo"|| ||df\}}n td|io"t|t t |g} nt |||i }|i}|iizyt|i}Wntj o t}nX|i|o]|||jo"t|t t |g} qoti|=t|||} |||EGG-INFO/PKG-INFOMetadata-Version: 1.0 Name: TurboCheetah Version: 1.0 Summary: TurboGears plugin to support use of Cheetah templates Home-page: http://www.turbogears.org Author: Kevin Dangoor et al Author-email: dangoor+turbogears@gmail.com License: MIT Download-URL: http://www.turbogears.org/download/ Description: UNKNOWN Keywords: python.templating.engines,turbogears Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Framework :: TurboGears Classifier: Environment :: Web Environment :: Buffet Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: License :: OSI Approved :: MIT License Classifier: Topic :: Software Development :: Libraries :: Python Modules PKr7^9EGG-INFO/SOURCES.txtREADME.txt setup.cfg setup.py TurboCheetah.egg-info/PKG-INFO TurboCheetah.egg-info/SOURCES.txt TurboCheetah.egg-info/dependency_links.txt TurboCheetah.egg-info/entry_points.txt TurboCheetah.egg-info/not-zip-safe TurboCheetah.egg-info/requires.txt TurboCheetah.egg-info/top_level.txt turbocheetah/__init__.py turbocheetah/cheetahsupport.py turbocheetah/tests/__init__.py turbocheetah/tests/extra.tmpl turbocheetah/tests/master.tmpl turbocheetah/tests/master2.tmpl turbocheetah/tests/page.tmpl turbocheetah/tests/page2.tmpl turbocheetah/tests/simple.tmpl turbocheetah/tests/subpage.tmpl turbocheetah/tests/test_template.py turbocheetah/tests/sub/__init__.py turbocheetah/tests/sub/master.tmpl turbocheetah/tests/sub/page.tmpl PKr72EGG-INFO/dependency_links.txt PKr7jq^^EGG-INFO/entry_points.txt [python.templating.engines] cheetah = turbocheetah.cheetahsupport:CheetahSupport PKr72EGG-INFO/not-zip-safe PKr7b.0EGG-INFO/requires.txtCheetah >= 2.0.1PKr796 EGG-INFO/top_level.txtturbocheetah PK\r7;><<turbocheetah/cheetahsupport.pyPK\r7mLuuxturbocheetah/__init__.pyPKr7bw#turbocheetah/cheetahsupport.pycPKr75AA4#turbocheetah/__init__.pycPKr7%>$EGG-INFO/PKG-INFOPKr7^9'EGG-INFO/SOURCES.txtPKr72*EGG-INFO/dependency_links.txtPKr7jq^^+EGG-INFO/entry_points.txtPKr72+EGG-INFO/not-zip-safePKr7b.0+EGG-INFO/requires.txtPKr796 $,EGG-INFO/top_level.txtPK e,