[ZPT] CVS: Packages/TAL - test_htmltalparser.py:1.23

fred@digicool.com fred@digicool.com
Sat, 9 Jun 2001 01:25:22 -0400 (EDT)


Update of /cvs-repository/Packages/TAL/tests
In directory korak.digicool.com:/tmp/cvs-serv21730/tests

Modified Files:
	test_htmltalparser.py 
Log Message:
More micro-optimizations.

A (minor) change to the bytecode format: for "extended" attributes
(handled by TALInterpreter.attrAction()), the instruction contains the
integer previously retrieved from the actionIndex table; the bytecode
generator now takes care of the lookup.  This allows attrAction() to
no longer need to lookup the table that it used to lookup the
integers.

Many handlers are now separated into TAL and non-TAL versions -- the
TALInterpreter constructor determines which dispatch table to use when
it initializes self.tal (which is not changed later).  This allows
each of the handlers to do only what is needed without having to
decide based on the self.tal attribute.

TALInterpreter.do_startTag() no longer contains a special case for an
empty attribute list; that case is already optimized away by the
bytecode generator.  What remains would actually work in that case,
but it simply doesn't occur.  This removes one test of the attrList
parameter.



--- Updated File test_htmltalparser.py in package Packages/TAL --
--- test_htmltalparser.py	2001/06/08 22:59:34	1.22
+++ test_htmltalparser.py	2001/06/09 05:25:21	1.23
@@ -155,7 +155,7 @@
 
     def check_define_macro(self):
         macro = self.initial_program + [
-            ('startTag', ('p', [('metal:define-macro', 'M', 'metal')])),
+            ('startTag', ('p', [('metal:define-macro', 'M', 2)])),
             rawtext('booh</p>'),
             ]
         program = [
@@ -170,17 +170,17 @@
             ('setPosition', (1, 0)),
             ('useMacro',
              ('M', '$M$', {},
-              [('startTag', ('p', [('metal:use-macro', 'M', 'metal')])),
+              [('startTag', ('p', [('metal:use-macro', 'M', 2)])),
                rawtext('booh</p>')])),
             ])
 
     def check_define_slot(self):
         macro = self.initial_program + [
-            ('startTag', ('p', [('metal:define-macro', 'M', 'metal')])),
+            ('startTag', ('p', [('metal:define-macro', 'M', 2)])),
             rawtext('foo'),
             ('setPosition', (1, 29)),
             ('defineSlot', ('S',
-             [('startTag', ('span', [('metal:define-slot', 'S', 'metal')])),
+             [('startTag', ('span', [('metal:define-slot', 'S', 2)])),
               rawtext('spam</span>')])),
             rawtext('bar</p>'),
             ]
@@ -198,13 +198,13 @@
             ('useMacro',
              ('M', '$M$',
               {'S': [('startTag', ('span',
-                                   [('metal:fill-slot', 'S', 'metal')])),
+                                   [('metal:fill-slot', 'S', 2)])),
                      rawtext('spam</span>')]},
-             [('startTag', ('p', [('metal:use-macro', 'M', 'metal')])),
+             [('startTag', ('p', [('metal:use-macro', 'M', 2)])),
               rawtext('foo'),
               ('setPosition', (1, 26)),
               ('fillSlot', ('S',
-               [('startTag', ('span', [('metal:fill-slot', 'S', 'metal')])),
+               [('startTag', ('span', [('metal:fill-slot', 'S', 2)])),
                 rawtext('spam</span>')])),
               rawtext('bar</p>')])),
             ])
@@ -220,7 +220,7 @@
             ('setPosition', (1, 0)),
             ('beginScope', {'tal:define': 'xyzzy string:spam'}),
             ('setLocal', ('xyzzy', '$string:spam$')),
-            ('startTag', ('p', [('tal:define', 'xyzzy string:spam', 'tal')])),
+            ('startTag', ('p', [('tal:define', 'xyzzy string:spam', 3)])),
             rawtext('</p>'),
             ('endScope', ()),
             ])
@@ -231,7 +231,7 @@
             ('beginScope', {'tal:define': 'local xyzzy string:spam'}),
             ('setLocal', ('xyzzy', '$string:spam$')),
             ('startTag', ('p',
-             [('tal:define', 'local xyzzy string:spam', 'tal')])),
+             [('tal:define', 'local xyzzy string:spam', 3)])),
             rawtext('</p>'),
             ('endScope', ()),
             ])
@@ -242,7 +242,7 @@
             ('beginScope', {'tal:define': 'global xyzzy string:spam'}),
             ('setGlobal', ('xyzzy', '$string:spam$')),
             ('startTag', ('p',
-             [('tal:define', 'global xyzzy string:spam', 'tal')])),
+             [('tal:define', 'global xyzzy string:spam', 3)])),
             rawtext('</p>'),
             ('endScope', ()),
             ])
@@ -253,7 +253,7 @@
             ('beginScope', {'tal:define': 'x string:spam; y x'}),
             ('setLocal', ('x', '$string:spam$')),
             ('setLocal', ('y', '$x$')),
-            ('startTag', ('p', [('tal:define', 'x string:spam; y x', 'tal')])),
+            ('startTag', ('p', [('tal:define', 'x string:spam; y x', 3)])),
             rawtext('</p>'),
             ('endScope', ()),
             ])
@@ -264,7 +264,7 @@
             ('beginScope', {'tal:define': 'x string:;;;;; y x'}),
             ('setLocal', ('x', '$string:;;$')),
             ('setLocal', ('y', '$x$')),
-            ('startTag', ('p', [('tal:define', 'x string:;;;;; y x', 'tal')])),
+            ('startTag', ('p', [('tal:define', 'x string:;;;;; y x', 3)])),
             rawtext('</p>'),
             ('endScope', ()),
             ])
@@ -279,7 +279,7 @@
             ('setGlobal', ('y', '$x$')),
             ('setLocal', ('z', '$y$')),
             ('startTag', ('p',
-             [('tal:define', 'x string:spam; global y x; local z y', 'tal')])),
+             [('tal:define', 'x string:spam; global y x; local z y', 3)])),
             rawtext('</p>'),
             ('endScope', ()),
             ])
@@ -291,7 +291,7 @@
             ('setPosition', (1, 3)),
             ('beginScope', {'tal:condition': 'python:1'}),
             ('condition', ('$python:1$',
-             [('startTag', ('span', [('tal:condition', 'python:1', 'tal')])),
+             [('startTag', ('span', [('tal:condition', 'python:1', 3)])),
               rawtext('<b>foo</b></span>')])),
             ('endScope', ()),
             rawtext('</p>'),
@@ -301,7 +301,7 @@
         self._run_check("<p tal:content='string:foo'>bar</p>", [
              ('setPosition', (1, 0)),
              ('beginScope', {'tal:content': 'string:foo'}), 
-             ('startTag', ('p', [('tal:content', 'string:foo', 'tal')])),
+             ('startTag', ('p', [('tal:content', 'string:foo', 3)])),
              ('insertText', ('$string:foo$', [rawtext('bar')])),
              rawtext('</p>'),
              ('endScope', ()),
@@ -311,7 +311,7 @@
         self._run_check("<p tal:content='text string:foo'>bar</p>", [
              ('setPosition', (1, 0)),
              ('beginScope', {'tal:content': 'text string:foo'}),
-             ('startTag', ('p', [('tal:content', 'text string:foo', 'tal')])),
+             ('startTag', ('p', [('tal:content', 'text string:foo', 3)])),
              ('insertText', ('$string:foo$', [rawtext('bar')])),
              rawtext('</p>'),
              ('endScope', ()),
@@ -322,7 +322,7 @@
              ('setPosition', (1, 0)),
              ('beginScope', {'tal:content': 'structure string:<br>'}),
              ('startTag', ('p',
-              [('tal:content', 'structure string:<br>', 'tal')])),
+              [('tal:content', 'structure string:<br>', 3)])),
              ('insertStructure',
               ('$string:<br>$', {}, [rawtext('bar')])),
              rawtext('</p>'),
@@ -334,7 +334,7 @@
              ('setPosition', (1, 0)),
              ('beginScope', {'tal:replace': 'string:foo'}),
              ('insertText', ('$string:foo$',
-              [('startTag', ('p', [('tal:replace', 'string:foo', 'tal')])),
+              [('startTag', ('p', [('tal:replace', 'string:foo', 3)])),
                rawtext('bar</p>')])),
              ('endScope', ()),
              ])
@@ -345,7 +345,7 @@
              ('beginScope', {'tal:replace': 'text string:foo'}),
              ('insertText', ('$string:foo$',
               [('startTag', ('p',
-                             [('tal:replace', 'text string:foo', 'tal')])),
+                             [('tal:replace', 'text string:foo', 3)])),
                rawtext('bar</p>')])),
              ('endScope', ()),
              ])
@@ -356,7 +356,7 @@
              ('beginScope', {'tal:replace': 'structure string:<br>'}),
              ('insertStructure', ('$string:<br>$', {},
               [('startTag', ('p',
-                [('tal:replace', 'structure string:<br>', 'tal')])),
+                [('tal:replace', 'structure string:<br>', 3)])),
                rawtext('bar</p>')])),
              ('endScope', ()),
              ])
@@ -368,11 +368,11 @@
              ('beginScope', {'tal:repeat': 'x python:(1,2,3)'}),
              ('loop', ('x', '$python:(1,2,3)$',
               [('startTag', ('p',
-                             [('tal:repeat', 'x python:(1,2,3)', 'tal')])),
+                             [('tal:repeat', 'x python:(1,2,3)', 3)])),
                ('setPosition', (1, 33)),
                ('beginScope', {'tal:replace': 'x'}),
                ('insertText', ('$x$',
-                [('startTag', ('span', [('tal:replace', 'x', 'tal')])),
+                [('startTag', ('span', [('tal:replace', 'x', 3)])),
                  rawtext('dummy</span>')])),
                ('endScope', ()),
                rawtext('</p>')])),
@@ -388,11 +388,11 @@
              {'tal:attributes': 'href string:http://www.zope.org; x string:y',
               'name': 'bar', 'href': 'foo'}),
             ('startTag', ('a',
-             [('href', 'foo', 'replace', '$string:http://www.zope.org$'),
+             [('href', 'foo', 0, '$string:http://www.zope.org$'),
               ('name', 'name="bar"'),
               ('tal:attributes',
-               'href string:http://www.zope.org; x string:y', 'tal'),
-              ('x', None, 'insert', '$string:y$')])),
+               'href string:http://www.zope.org; x string:y', 3),
+              ('x', None, 1, '$string:y$')])),
             rawtext('link</a>'),
             ('endScope', ()),
             ])
@@ -407,8 +407,8 @@
             ('insertStructure', ('$string:<img>$',
              {'src': '$string:foo.png$'},
              [('startTag', ('p',
-               [('tal:replace', 'structure string:<img>', 'tal'),
-                ('tal:attributes', 'src string:foo.png', 'tal')])),
+               [('tal:replace', 'structure string:<img>', 3),
+                ('tal:attributes', 'src string:foo.png', 3)])),
               rawtext('duh</p>')])),
             ('endScope', ()),
             ])
@@ -421,13 +421,13 @@
              {'tal:content': 'notHere', 'tal:on-error': 'string:error'}),
             ('onError',
              ([('startTag', ('p',
-                [('tal:on-error', 'string:error', 'tal'),
-                 ('tal:content', 'notHere', 'tal')])),
+                [('tal:on-error', 'string:error', 3),
+                 ('tal:content', 'notHere', 3)])),
                ('insertText', ('$notHere$', [rawtext('okay')])),
                rawtext('</p>')],
               [('startTag', ('p',
-                [('tal:on-error', 'string:error', 'tal'),
-                 ('tal:content', 'notHere', 'tal')])),
+                [('tal:on-error', 'string:error', 3),
+                 ('tal:content', 'notHere', 3)])),
                ('insertText', ('$string:error$', [])),
                rawtext('</p>')])),
             ('endScope', ()),
@@ -442,12 +442,12 @@
             ('onError',
              ([('insertText', ('$notHere$',
                 [('startTag', ('p',
-                  [('tal:on-error', 'string:error', 'tal'),
-                   ('tal:replace', 'notHere', 'tal')])),
+                  [('tal:on-error', 'string:error', 3),
+                   ('tal:replace', 'notHere', 3)])),
                  rawtext('okay</p>')]))],
               [('startTag', ('p',
-                [('tal:on-error', 'string:error', 'tal'),
-                 ('tal:replace', 'notHere', 'tal')])),
+                [('tal:on-error', 'string:error', 3),
+                 ('tal:replace', 'notHere', 3)])),
                ('insertText', ('$string:error$', [])),
                rawtext('</p>')])),
             ('endScope', ()),