pax_global_header00006660000000000000000000000064111656604540014522gustar00rootroot0000000000000052 comment=24483b11a5e01642739306bd66f096fb85b480e5 python-module-turbocheetah-1.0/000075500000000000000000000000001116566045400166375ustar00rootroot00000000000000python-module-turbocheetah-1.0/.gear/000075500000000000000000000000001116566045400176335ustar00rootroot00000000000000python-module-turbocheetah-1.0/.gear/rules000064400000000000000000000000071116566045400207050ustar00rootroot00000000000000tar: . python-module-turbocheetah-1.0/README.txt000064400000000000000000000013641116566045400203410ustar00rootroot00000000000000TurboCheetah ============ This package provides a template engine plugin, allowing you to easily use Cheetah with TurboGears, Buffet and other tools that support the python.templating.engines entry point. Cheetah templates are assumed to have a "tmpl" extension. For information on the Cheetah templating engine, go here: http://www.cheetahtemplate.org For information on using Cheetah templates with TurboGears, go here: http://docs.turbogears.org/1.0/CheetahTemplating http://docs.turbogears.org/1.0/AdvancedCheetahTemplates For general information on using a template engine plugin with TurboGears or writing a template engine plugin, go here: http://docs.turbogears.org/1.0/TemplatePlugins http://docs.turbogears.org/1.0/AlternativeTemplating python-module-turbocheetah-1.0/python-module-turbocheetah.spec000064400000000000000000000017131116566045400247740ustar00rootroot00000000000000%define modulename turbocheetah Name: python-module-%modulename Version: 1.0 Release: alt1 Summary: TurboGears support package which provides a template engine plug-in for the Cheetah templating engine License: MIT Group: Development/Python Url: http://docs.turbogears.org/TurboCheetah Packager: Vladimir V. Kamarzin BuildArch: noarch Source: %name-%version.tar BuildRequires: python-module-setuptools %setup_python_module %modulename %description TurboCheetah is a TurboGears support package which provides a template engine plug-in for the Cheetah templating engine, allowing you to use Cheetah templates with TurboGears, Buffet or other systems that support the python.templating.engines entry point. %prep %setup %build %python_build %install %python_install %files %python_sitelibdir/%modulename/ %python_sitelibdir/*.egg-info %changelog * Sat Apr 04 2009 Vladimir V. Kamarzin 1.0-alt1 - Initial build for Sisyphus python-module-turbocheetah-1.0/setup.cfg000064400000000000000000000000651116566045400204610ustar00rootroot00000000000000[egg_info] #tag_build = dev #tag_svn_revision = true python-module-turbocheetah-1.0/setup.py000064400000000000000000000020631116566045400203520ustar00rootroot00000000000000from setuptools import setup, find_packages setup( name="TurboCheetah", version="1.0", description="TurboGears plugin to support use of Cheetah templates", author="Kevin Dangoor et al", author_email="dangoor+turbogears@gmail.com", url="http://www.turbogears.org", download_url="http://www.turbogears.org/download/", keywords=["python.templating.engines", "turbogears"], license="MIT", install_requires = ["Cheetah >= 2.0.1"], zip_safe=False, packages=find_packages(exclude=['*.tests', '*.tests.*']), classifiers = [ 'Development Status :: 4 - Beta', 'Framework :: TurboGears', 'Environment :: Web Environment :: Buffet', 'Operating System :: OS Independent', 'Programming Language :: Python', 'License :: OSI Approved :: MIT License', 'Topic :: Software Development :: Libraries :: Python Modules' ], entry_points=""" [python.templating.engines] cheetah = turbocheetah.cheetahsupport:CheetahSupport """, test_suite = 'nose.collector', ) python-module-turbocheetah-1.0/turbocheetah/000075500000000000000000000000001116566045400213145ustar00rootroot00000000000000python-module-turbocheetah-1.0/turbocheetah/__init__.py000064400000000000000000000001651116566045400234270ustar00rootroot00000000000000from turbocheetah import cheetahsupport CheetahSupport = cheetahsupport.CheetahSupport __all__ = ["CheetahSupport"]python-module-turbocheetah-1.0/turbocheetah/cheetahsupport.py000064400000000000000000000074741116566045400247400ustar00rootroot00000000000000"""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() python-module-turbocheetah-1.0/turbocheetah/tests/000075500000000000000000000000001116566045400224565ustar00rootroot00000000000000python-module-turbocheetah-1.0/turbocheetah/tests/__init__.py000064400000000000000000000000251116566045400245640ustar00rootroot00000000000000# turbocheetah.tests python-module-turbocheetah-1.0/turbocheetah/tests/extra.tmpl000064400000000000000000000000221116566045400244710ustar00rootroot00000000000000Another check: $x python-module-turbocheetah-1.0/turbocheetah/tests/master.tmpl000064400000000000000000000000201116566045400246370ustar00rootroot00000000000000Hello! $content python-module-turbocheetah-1.0/turbocheetah/tests/master2.tmpl000064400000000000000000000002171116566045400247310ustar00rootroot00000000000000#extends turbocheetah.tests.sub.master #def content $hello # the data ${one}: $v ## ignore me $two: ${x} # the end That's all, folks! #end defpython-module-turbocheetah-1.0/turbocheetah/tests/page.tmpl000064400000000000000000000001231116566045400242640ustar00rootroot00000000000000#extends turbocheetah.tests.master #def content Welcome to TurboCheetah! #end def python-module-turbocheetah-1.0/turbocheetah/tests/page2.tmpl000064400000000000000000000001231116566045400243460ustar00rootroot00000000000000#extends turbocheetah.tests.master2 #def hello This is getting tricky: #end def python-module-turbocheetah-1.0/turbocheetah/tests/simple.tmpl000064400000000000000000000000121116566045400246360ustar00rootroot00000000000000Check: $v python-module-turbocheetah-1.0/turbocheetah/tests/sub/000075500000000000000000000000001116566045400232475ustar00rootroot00000000000000python-module-turbocheetah-1.0/turbocheetah/tests/sub/__init__.py000064400000000000000000000000311116566045400253520ustar00rootroot00000000000000# turbocheetah.tests.sub python-module-turbocheetah-1.0/turbocheetah/tests/sub/master.tmpl000064400000000000000000000000421116566045400254340ustar00rootroot00000000000000Hello from my subpackage! $contentpython-module-turbocheetah-1.0/turbocheetah/tests/sub/page.tmpl000064400000000000000000000001341116566045400250570ustar00rootroot00000000000000#extends turbocheetah.tests.sub.master #def content Welcome to my subpackage page. #end defpython-module-turbocheetah-1.0/turbocheetah/tests/subpage.tmpl000064400000000000000000000001251116566045400250000ustar00rootroot00000000000000#extends turbocheetah.tests.sub.master #def content Welcome to my subpage. #end def python-module-turbocheetah-1.0/turbocheetah/tests/test_template.py000064400000000000000000000067151116566045400257130ustar00rootroot00000000000000"""TurboCheetah tests.""" import os from turbocheetah import CheetahSupport # Note: To test with the precompiled or without the importhooks feature, # you need to compile the templates manually with "cheetah-compile". importhooks = True precompiled = False here = os.path.dirname(__file__) values = { 'v': 'My value!', 'one': 1 } def extra_vars(): return { 'x': 'Extra value!', 'two': 2 } options = { 'cheetah.importhooks': importhooks, 'cheetah.precompiled': precompiled, 'dummy': 'does nothing' } def get_engine(): return CheetahSupport(extra_vars, options) def check_lines(expect, result): """Check lines of result against expectation after stripping lines.""" expect = expect.splitlines() result = result.splitlines() for expect_line, result_line in zip(expect, result): expect_line = expect_line.strip() result_line = result_line.strip() assert result_line == expect_line, \ '\nExpect: %r\nResult: %r' % (expect_line, result_line) def test_options(): """Make sure all engine options are set.""" engine = get_engine() opt = engine.options assert opt['dummy'] == 'does nothing' assert opt['cheetah.importhooks'] == engine.importhooks == importhooks assert opt['cheetah.precompiled'] == engine.precompiled == precompiled def test_simple(): """Make sure a simple test works.""" engine = get_engine() s = engine.render(values, template='turbocheetah.tests.simple') assert s.strip() == 'Check: My value!' def test_not_found(): """Make sure undefined variables do not go unnoticed.""" try: from Cheetah.NameMapper import NotFound except ImportError: assert False, 'Cheetah.NameMapper does not export NotFound error' engine = get_engine() try: s = engine.render(None, template='turbocheetah.tests.simple') except NotFound: pass except Exception, e: assert False, 'Undefined name raised wrong exception (%s)' % str(e) else: assert s.strip() != 'Check:', 'Undefined name was ignored' assert False, 'Undefined name did not raise any exception' def test_extra(): """Make sure extra variables work.""" engine = get_engine() s = engine.render(None, template='turbocheetah.tests.extra') assert s.strip() == 'Another check: Extra value!' def test_unicode(): """Make sure unicode values work.""" engine = get_engine() s = engine.render({'v': u"K\xe4se!"}, template='turbocheetah.tests.simple') assert isinstance(s, unicode) assert s.strip() == u'Check: K\xe4se!' def test_extend(): """Make sure one template can inherit from another.""" engine = get_engine() s = engine.render(None, template='turbocheetah.tests.page') assert s.strip() == 'Hello! Welcome to TurboCheetah!' def test_sub(): """Make sure we can use subpackages.""" engine = get_engine() check_lines(engine.render(None, template='turbocheetah.tests.subpage'), 'Hello from my subpackage! Welcome to my subpage.') check_lines(engine.render(None, template='turbocheetah.tests.sub.page'), 'Hello from my subpackage! Welcome to my subpackage page.') def test_tricky(): """Make sure we can do trickier things.""" engine = get_engine() check_lines(engine.render(values, template='turbocheetah.tests.page2'), """Hello from my subpackage!\n This is getting tricky:\n # the data\n1: My value!\n2: Extra value! # the end\nThat's all, folks!""")