SVN: r25824 - in trunk/quixote: . test

David Binger <dbinger-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Wed, 5 Jan 2005 11:22:03 -0500
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: dbinger
Date: 2005-01-05 08:25:58 -0500 (Wed, 05 Jan 2005)
New Revision: 25824

Modified:
   trunk/quixote/ptl_compile.py
   trunk/quixote/test/utest_ptl.py
Log:
Remove $-substitution option.


Modified: trunk/quixote/ptl_compile.py
===================================================================
--- trunk/quixote/ptl_compile.py	2005-01-04 15:19:35 UTC (rev 25823)
+++ trunk/quixote/ptl_compile.py	2005-01-05 13:25:58 UTC (rev 25824)
@@ -32,20 +32,18 @@
 
 HTML_TEMPLATE_PREFIX = "_q_html_template_"
 PLAIN_TEMPLATE_PREFIX = "_q_plain_template_"
-HTML_DOLLAR_TEMPLATE_PREFIX = "_q_html_dollar_template_"
-PLAIN_DOLLAR_TEMPLATE_PREFIX = "_q_plain_dollar_template_"
 
 class TemplateTransformer(transformer.Transformer):
 
     def __init__(self, *args, **kwargs):
         transformer.Transformer.__init__(self, *args, **kwargs)
         # __template_type is a stack whose values are
-        # "html", "plain", "html$", "plain$", or None
+        # "html", "plain", or None
         self.__template_type = []
 
     def _get_template_type(self):
         """Return the type of the function being compiled (
-        "html", "plain", "html$", "plain$", or None)
+        "html", "plain", or None)
         """
         if self.__template_type:
             return self.__template_type[-1]
@@ -89,12 +87,6 @@
             elif name.startswith(HTML_TEMPLATE_PREFIX):
                 name = name[len(HTML_TEMPLATE_PREFIX):]
                 template_type = "html"
-            elif name.startswith(HTML_DOLLAR_TEMPLATE_PREFIX):
-                name = name[len(HTML_DOLLAR_TEMPLATE_PREFIX):]
-                template_type = "html$"
-            elif name.startswith(PLAIN_DOLLAR_TEMPLATE_PREFIX):
-                name = name[len(PLAIN_DOLLAR_TEMPLATE_PREFIX):]
-                template_type = "plain$"
             else:
                 raise RuntimeError, 'unknown prefix on %s' % name
 
@@ -112,7 +104,7 @@
 
             # _q_output = _q_TemplateIO()
             klass = ast.Name('_q_TemplateIO')
-            args = [ast.Const(template_type in ("html", "html$"))]
+            args = [ast.Const(template_type == "html")]
             instance = ast.CallFunc(klass, args)
             assign_name = ast.AssName('_q_output', OP_ASSIGN)
             assign = ast.Assign([assign_name], instance)
@@ -164,48 +156,18 @@
         for node in nodelist:
             k = k + eval(node[1])
         lineno = node[2]
-        if self._get_template_type() in ('html$', 'plain$') and '$' in k:
-            try:
-                k = _convert_string(k)
-            except ValueError, e:
-                raise SyntaxError(str(e), (None, lineno, None, None))
-            return ast.Mod((self._get_text_node(k),
-                            ast.CallFunc(ast.Name('_q_vars'), [])))
-        else:
-            return self._get_text_node(k)
+        return self._get_text_node(k)
 
     def _get_text_node(self, k):
-        if self._get_template_type() in ("html", "html$"):
+        if self._get_template_type() == "html":
             return ast.CallFunc(ast.Name('_q_htmltext'), [ast.Const(k)])
         else:
             return ast.Const(k)
 
-_substitution_pattern = r"""
-    \$(?:
-    (?P<escaped>\$) |
-    (?P<named>%(idpat)s) |
-    {(?P<braced>%(idpat)s)} |
-    (?P<invalid>.*)
-    )""" % dict(idpat='[_a-z][_a-z0-9]*')
-
-_substitution_re = re.compile(_substitution_pattern, re.I|re.VERBOSE)
-
-def _convert_string(s):
-    def convert(mo):
-        name = mo.group('named') or mo.group('braced')
-        if name is not None:
-            return '%(' + name + ')s'
-        elif mo.group('escaped') is not None:
-            return '$'
-        elif mo.group('invalid') is not None:
-            invalid = '$' + mo.group('invalid')
-            raise ValueError('invalid substitution %r' % invalid)
-    return _substitution_re.sub(convert, s.replace('%', '%%'))
-
 _template_re = re.compile(
     r"^(?P<indent>[ \t]*) def (?:[ \t]+)"
     r" (?P<name>[a-zA-Z_][a-zA-Z_0-9]*)"
-    r" (?:[ \t]*) \[(?P<type>plain|html|html\$|plain\$)\] (?:[ \t]*)"
+    r" (?:[ \t]*) \[(?P<type>plain|html)\] (?:[ \t]*)"
     r" (?:[ \t]*[\(\\])",
     re.MULTILINE|re.VERBOSE)
 
@@ -224,12 +186,9 @@
     """
     def replacement(match):
         template_type = match.group('type')
-        if template_type[-1] == '$':
-            template_type = template_type[:-1] + '_dollar'
         return '%sdef _q_%s_template_%s(' % (match.group('indent'),
                                              template_type,
                                              match.group('name'))
-
     return  _template_re.sub(replacement, buf)
 
 def parse(buf, filename='<string>'):

Modified: trunk/quixote/test/utest_ptl.py
===================================================================
--- trunk/quixote/test/utest_ptl.py	2005-01-04 15:19:35 UTC (rev 25823)
+++ trunk/quixote/test/utest_ptl.py	2005-01-05 13:25:58 UTC (rev 25824)
@@ -53,36 +53,6 @@
         except SyntaxError, e:
             assert e.lineno == 1
 
-    def check_dollar(self):
-        run_ptl('def f(a):',
-                '    "yes $a"',
-                'assert f(1) == None')
-        run_ptl('def f [plain$] (a):',
-                '    "yes $a"',
-                'assert f(1) == "yes 1"')
-        run_ptl('def f [html$] (a):',
-                '    "yes ${a} $a $$"',
-                'assert f(1) == "yes 1 1 $"')
-        try:
-            run_ptl('def f [plain$] (a):',
-                    '    "yes ${a} $a $"')
-            assert 0
-        except SyntaxError, e:
-            assert str(e) == "invalid substitution '$' (line 2) (test, line 2)"
-        try:
-            run_ptl('def f [plain$] (a):',
-                    '    "$-"')
-            assert 0
-        except SyntaxError, e:
-            assert str(e) == (
-                "invalid substitution '$-' (line 2) (test, line 2)")
-        run_ptl('def f [html$] (a):',
-                '    "yes %s $a" % "odd"',
-                'assert f(1) == "yes odd 1"')
-        run_ptl('def f [plain$] (a):',
-                '    "yes %(a)s $a" % locals()',
-                'assert f(1) == "yes 1 1"')
-
 if __name__ == "__main__":
     Test()