[PATCH 1/2] move handling of escaped variables and directives to the parser
Doug Knight <[email protected]> Mon, 14 Dec 2009 16:36:08 -0900
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <[email protected]> |
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.
---
cheetah/Compiler.py | 17 +----------------
cheetah/Parser.py | 15 +++++++++++++++
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/cheetah/Compiler.py b/cheetah/Compiler.py
index 39c7f51..248ba1f 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 7436e9c..bb70d06 100644
--- a/cheetah/Parser.py
+++ b/cheetah/Parser.py
@@ -519,6 +519,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)
@@ -1509,6 +1522,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
--
1.6.5.2
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev