diff options
author | Doug Knight <karmix0@gmail.com> | 2009-12-14 16:36:08 -0900 |
---|---|---|
committer | R. Tyler Ballance <tyler@monkeypox.org> | 2009-12-14 23:36:27 -0800 |
commit | 0cc9f781eeeb98d6c0d2812145a525f5dfe27b40 (patch) | |
tree | 1fccee90869cbca34c66660940b8426a85b3abd3 | |
parent | 5cd02208b268958e3c28a338d32041abc82a9b85 (diff) | |
download | python-cheetah-0cc9f781eeeb98d6c0d2812145a525f5dfe27b40.tar.gz |
move handling of escaped variables and directives to the parser
Once text reaches the compiler, it is too late to parse escaped
variables and directives. The compiler does not know where the text
came from, and can not determine when it should skip processing of
escape sequences for raw blocks.
Signed-off-by: R. Tyler Ballance <tyler@monkeypox.org>
-rw-r--r-- | cheetah/Compiler.py | 17 | ||||
-rw-r--r-- | cheetah/Parser.py | 15 |
2 files changed, 16 insertions, 16 deletions
diff --git a/cheetah/Compiler.py b/cheetah/Compiler.py index 4ff5e5c..97e69e7 100644 --- a/cheetah/Compiler.py +++ b/cheetah/Compiler.py @@ -428,27 +428,12 @@ class MethodCompiler(GenUtils): else: self._pendingStrConstChunks = [strConst] - def _unescapeCheetahVars(self, theString): - """Unescape any escaped Cheetah \$vars in the string. - """ - - token = self.setting('cheetahVarStartToken') - return theString.replace('\\' + token, token) - - def _unescapeDirectives(self, theString): - """Unescape any escaped Cheetah \$vars in the string. - """ - - token = self.setting('directiveStartToken') - return theString.replace('\\' + token, token) - def commitStrConst(self): """Add the code for outputting the pending strConst without chopping off any whitespace from it. """ if self._pendingStrConstChunks: - strConst = self._unescapeCheetahVars(''.join(self._pendingStrConstChunks)) - strConst = self._unescapeDirectives(strConst) + strConst = ''.join(self._pendingStrConstChunks) self._pendingStrConstChunks = [] if not strConst: return diff --git a/cheetah/Parser.py b/cheetah/Parser.py index 4390705..67f9fbc 100644 --- a/cheetah/Parser.py +++ b/cheetah/Parser.py @@ -510,6 +510,19 @@ class _LowLevelParser(SourceReader): endTokenEsc = escapeRegexChars(endToken) self.PSPEndTokenRE = cachedRegex(escCharLookBehind + endTokenEsc) + def _unescapeCheetahVars(self, theString): + """Unescape any escaped Cheetah \$vars in the string. + """ + + token = self.setting('cheetahVarStartToken') + return theString.replace('\\' + token, token) + + def _unescapeDirectives(self, theString): + """Unescape any escaped Cheetah directives in the string. + """ + + token = self.setting('directiveStartToken') + return theString.replace('\\' + token, token) def isLineClearToStartToken(self, pos=None): return self.isLineClearToPos(pos) @@ -1497,6 +1510,8 @@ class _HighLevelParser(_LowLevelParser): else: self.advance() strConst = self.readTo(self.pos(), start=startPos) + strConst = self._unescapeCheetahVars(strConst) + strConst = self._unescapeDirectives(strConst) self._compiler.addStrConst(strConst) return match |