diff options
author | tavis_rudd <tavis_rudd> | 2006-01-10 21:41:43 +0000 |
---|---|---|
committer | tavis_rudd <tavis_rudd> | 2006-01-10 21:41:43 +0000 |
commit | 7e0674a5d13fdcb8671d7f06958e249e70312820 (patch) | |
tree | b0100d373c8e9ec02421ee898ed83d9ceb6ee439 | |
parent | f0bbcd0740a5aeb703fc646d667a3aeb47b65f8c (diff) | |
download | python-cheetah-7e0674a5d13fdcb8671d7f06958e249e70312820.tar.gz |
fixed issue with buffering and use of #call when template is used as a webkit servlet
-rw-r--r-- | src/Compiler.py | 23 | ||||
-rw-r--r-- | src/Template.py | 43 |
2 files changed, 37 insertions, 29 deletions
diff --git a/src/Compiler.py b/src/Compiler.py index 6faf99c..6c58449 100644 --- a/src/Compiler.py +++ b/src/Compiler.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# $Id: Compiler.py,v 1.119 2006/01/09 09:06:44 tavis_rudd Exp $ +# $Id: Compiler.py,v 1.120 2006/01/10 21:41:43 tavis_rudd Exp $ """Compiler classes for Cheetah: ModuleCompiler aka 'Compiler' ClassCompiler @@ -11,12 +11,12 @@ ModuleCompiler.compile, and ModuleCompiler.__getattr__. Meta-Data ================================================================================ Author: Tavis Rudd <tavis@damnsimple.com> -Version: $Revision: 1.119 $ +Version: $Revision: 1.120 $ Start Date: 2001/09/19 -Last Revision Date: $Date: 2006/01/09 09:06:44 $ +Last Revision Date: $Date: 2006/01/10 21:41:43 $ """ __author__ = "Tavis Rudd <tavis@damnsimple.com>" -__revision__ = "$Revision: 1.119 $"[11:-2] +__revision__ = "$Revision: 1.120 $"[11:-2] import sys import os @@ -783,6 +783,8 @@ class MethodCompiler(GenUtils): +' of '+functionName +' at line, col ' + str(lineCol) + ' in the source.') self.addChunk('_orig_trans%(ID)s = trans'%locals()) + self.addChunk('_wasBuffering%(ID)s = self._CHEETAH__isBuffering'%locals()) + self.addChunk('self._CHEETAH__isBuffering = True') self.addChunk('trans = _callCollector%(ID)s = DummyTransaction()'%locals()) self.addChunk('write = _callCollector%(ID)s.response().write'%locals()) @@ -809,9 +811,14 @@ class MethodCompiler(GenUtils): ID, callDetails = self._callRegionsStack[-1] functionName, initialKwArgs, lineCol = ( callDetails.functionName, callDetails.args, callDetails.lineCol) - if not callDetails.usesKeywordArgs: + + def reset(ID=ID): self.addChunk('trans = _orig_trans%(ID)s'%locals()) self.addChunk('write = trans.response().write') + self.addChunk('self._CHEETAH__isBuffering = _wasBuffering%(ID)s '%locals()) + + if not callDetails.usesKeywordArgs: + reset() self.addChunk('_callArgVal%(ID)s = _callCollector%(ID)s.response().getvalue()'%locals()) self.addChunk('del _callCollector%(ID)s'%locals()) if initialKwArgs: @@ -822,8 +829,7 @@ class MethodCompiler(GenUtils): if initialKwArgs: initialKwArgs = initialKwArgs+', ' self._endCallArg() - self.addChunk('trans = _orig_trans%(ID)s'%locals()) - self.addChunk('write = trans.response().write') + reset() self.addFilteredChunk('%(functionName)s(%(initialKwArgs)s**_callKws%(ID)s)'%locals()) self.addChunk('del _callKws%(ID)s'%locals()) self.addChunk('## END CALL REGION: '+ID @@ -942,7 +948,8 @@ class AutoMethodCompiler(MethodCompiler): if self._streamingEnabled: if self._useKWsDictArgForPassingTrans() and self._kwargsName: self.addChunk('trans = %s.get("trans")'%self._kwargsName) - self.addChunk('if not trans and not callable(self.transaction):') + self.addChunk('if (not trans and not self._CHEETAH__isBuffering' + ' and not callable(self.transaction)):') self.indent() self.addChunk('trans = self.transaction' ' # is None unless self.awake() was called') diff --git a/src/Template.py b/src/Template.py index 13c00fe..c327910 100644 --- a/src/Template.py +++ b/src/Template.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# $Id: Template.py,v 1.137 2006/01/09 19:55:43 tavis_rudd Exp $ +# $Id: Template.py,v 1.138 2006/01/10 21:42:16 tavis_rudd Exp $ """Provides the core API for Cheetah. See the docstring in the Template class and the Users' Guide for more information @@ -9,12 +9,12 @@ Meta-Data Author: Tavis Rudd <tavis@damnsimple.com> License: This software is released for unlimited distribution under the terms of the MIT license. See the LICENSE file. -Version: $Revision: 1.137 $ +Version: $Revision: 1.138 $ Start Date: 2001/03/30 -Last Revision Date: $Date: 2006/01/09 19:55:43 $ +Last Revision Date: $Date: 2006/01/10 21:42:16 $ """ __author__ = "Tavis Rudd <tavis@damnsimple.com>" -__revision__ = "$Revision: 1.137 $"[11:-2] +__revision__ = "$Revision: 1.138 $"[11:-2] ################################################################################ ## DEPENDENCIES @@ -568,6 +568,21 @@ class Template(Servlet): return generatedModuleCode compile = classmethod(compile) + def subclass(klass, *args, **kws): + """Takes the same args as the .compile() classmethod and returns a + template that is a subclass of the template this method is called from. + + T1 = Template.compile(' foo - $meth1 - bar\n#def meth1: this is T1.meth1') + T2 = T1.subclass('#implements meth1\n this is T2.meth1') + """ + kws['baseclass'] = klass + if isinstance(klass, Template): + templateAPIClass = klass + else: + templateAPIClass = Template + return templateAPIClass.compile(*args, **kws) + subclass = classmethod(subclass) + def _preprocessSource(klass, source, file, preprocessors): """Iterates through the .compile() classmethod's preprocessors argument and pipes the source code through each each preprocessor. @@ -706,21 +721,6 @@ class Template(Servlet): _assignRequiredMethodsToClass = classmethod(_assignRequiredMethodsToClass) - def subclass(klass, *args, **kws): - """Takes the same args as the .compile() classmethod and returns a - template that is a subclass of the template this method is called from. - - T1 = Template.compile(' foo - $meth1 - bar\n#def meth1: this is T1.meth1') - T2 = T1.subclass('#implements meth1\n this is T2.meth1') - """ - kws['baseclass'] = klass - if isinstance(klass, Template): - templateAPIClass = klass - else: - templateAPIClass = Template - return templateAPIClass.compile(*args, **kws) - subclass = classmethod(subclass) - ## end classmethods ## def __init__(self, source=None, searchList=Unspecified, namespaces=Unspecified, @@ -967,6 +967,7 @@ class Template(Servlet): if not hasattr(self, 'transaction'): self.transaction = None self._CHEETAH__instanceInitialized = True + self._CHEETAH__isBuffering = False def _compile(self, source=None, file=None, compilerSettings=Unspecified, moduleName=None, mainMethodName=None): @@ -1222,9 +1223,9 @@ class Template(Servlet): Author: Mike Orr <iron@mso.oz.net> License: This software is released for unlimited distribution under the terms of the MIT license. See the LICENSE file. - Version: $Revision: 1.137 $ + Version: $Revision: 1.138 $ Start Date: 2002/03/17 - Last Revision Date: $Date: 2006/01/09 19:55:43 $ + Last Revision Date: $Date: 2006/01/10 21:42:16 $ """ src = src.lower() isCgi = not self.isControlledByWebKit |