summaryrefslogtreecommitdiff
path: root/src/Compiler.py
diff options
context:
space:
mode:
authorR. Tyler Ballance <tyler@slide.com>2009-04-16 22:32:41 -0700
committerR. Tyler Ballance <tyler@slide.com>2009-04-16 22:32:41 -0700
commit45f570f03abfbe929a14a7c23e2aa2a39ce152c5 (patch)
tree992e83fd05db4ab0231ec1a2257ba45b744376c5 /src/Compiler.py
parent2fc2c598e3ab45631739fe0f582fbfc18573b417 (diff)
parent1c42c232c419001116a099e4a49032231fff38fe (diff)
downloadpython-cheetah-45f570f03abfbe929a14a7c23e2aa2a39ce152c5.tar.gz
Merge branch 'next' of git@github.com:rtyler/cheetahv2.1.1
Diffstat (limited to 'src/Compiler.py')
-rw-r--r--src/Compiler.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/Compiler.py b/src/Compiler.py
index a4f311c..71eeeb9 100644
--- a/src/Compiler.py
+++ b/src/Compiler.py
@@ -63,6 +63,7 @@ DEFAULT_COMPILER_SETTINGS = {
'alwaysFilterNone':True, # filter out None, before the filter is called
'useFilters':True, # use str instead if =False
'includeRawExprInFilterArgs':True,
+ 'useLegacyImportMode' : True,
#'lookForTransactionAttr':False,
'autoAssignDummyTransactionToSelf':False,
@@ -973,9 +974,16 @@ class MethodCompiler(GenUtils):
def nextFilterRegionID(self):
return self.nextCacheID()
+
+ def setTransform(self, transformer, isKlass):
+ self.addChunk('trans = TransformerTransaction()')
+ self.addChunk('trans._response = trans.response()')
+ self.addChunk('trans._response._filter = %s' % transformer)
+ self.addChunk('write = trans._response.write')
def setFilter(self, theFilter, isKlass):
- class FilterDetails: pass
+ class FilterDetails:
+ pass
filterDetails = FilterDetails()
filterDetails.ID = ID = self.nextFilterRegionID()
filterDetails.theFilter = theFilter
@@ -1566,8 +1574,8 @@ class ModuleCompiler(SettingsManager, GenUtils):
self._fileDirName, self._fileBaseName = os.path.split(self._filePath)
self._fileBaseNameRoot, self._fileBaseNameExt = os.path.splitext(self._fileBaseName)
- if not isinstance(source, (str,unicode)):
- source = str(source)
+ if not isinstance(source, basestring):
+ source = unicode(source)
# by converting to string here we allow objects such as other Templates
# to be passed in
@@ -1638,7 +1646,7 @@ class ModuleCompiler(SettingsManager, GenUtils):
"from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion",
"from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple",
"from Cheetah.Template import Template",
- "from Cheetah.DummyTransaction import DummyTransaction",
+ "from Cheetah.DummyTransaction import *",
"from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList",
"from Cheetah.CacheRegion import CacheRegion",
"import Cheetah.Filters as Filters",
@@ -1712,9 +1720,10 @@ class ModuleCompiler(SettingsManager, GenUtils):
return self._importedVarNames
def addImportedVarNames(self, varNames, raw_statement=None):
+ settings = self.settings()
if not varNames:
return
- if self._methodBodyChunks and raw_statement:
+ if self._methodBodyChunks and raw_statement and not settings.get('useLegacyImportMode'):
self.addChunk(raw_statement)
else:
self._importedVarNames.extend(varNames)
@@ -1836,7 +1845,11 @@ class ModuleCompiler(SettingsManager, GenUtils):
self._specialVars[name] = contents.strip()
def addImportStatement(self, impStatement):
- self._importStatements.append(impStatement)
+ settings = self.settings()
+ if not self._methodBodyChunks or settings.get('useLegacyImportMode'):
+ # In the case where we are importing inline in the middle of a source block
+ # we don't want to inadvertantly import the module at the top of the file either
+ self._importStatements.append(impStatement)
#@@TR 2005-01-01: there's almost certainly a cleaner way to do this!
importVarNames = impStatement[impStatement.find('import') + len('import'):].split(',')