[ZPT] CVS: Zope3/lib/python/Zope/TAL - TALGenerator.py:1.52.16.3.4.4

Fred L. Drake, Jr. fdrake@acm.org
Wed, 22 May 2002 15:16:29 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/TAL
In directory cvs.zope.org:/tmp/cvs-serv29013

Modified Files:
      Tag: fdrake-tal-i18n-branch
	TALGenerator.py 
Log Message:
optimizeStartTag():  More comments, small simplification of how the
    replacement text is built up.


=== Zope3/lib/python/Zope/TAL/TALGenerator.py 1.52.16.3.4.3 => 1.52.16.3.4.4 ===
     # TALInterpreter.attrAction() and .attrAction_tal().
     #
+    # Each attribute is represented by a tuple:
+    #
+    # (name, value)                 -- a simple name/value pair, with
+    #                                  no special processing
+    #
+    # (name, value, action, *extra) -- attribute with special
+    #                                  processing needs, action is a
+    #                                  code that indicates which
+    #                                  branch to take, and *extra
+    #                                  contains additional,
+    #                                  action-specific information
+    #                                  needed by the processing
+    #
     actionIndex = {"replace":0, "insert":1, "metal":2, "tal":3, "xmlns":4,
                    0: 0, 1: 1, 2: 2, 3: 3, 4: 4}
     def optimizeStartTag(self, collect, name, attrlist, end):
@@ -133,10 +146,7 @@
                 else:
                     s = "%s=%s" % (item[0], quote(item[1]))
                 attrlist[i] = item[0], s
-            if item[1] is None:
-                new.append(" " + item[0])
-            else:
-                new.append(" %s=%s" % (item[0], quote(item[1])))
+                new.append(" " + s)
         # if no non-optimizable attributes were found, convert to plain text
         if opt:
             new.append(end)
@@ -532,7 +542,7 @@
         if attrsubst or i18nattrs:
             if attrsubst:
                 repldict = parseAttributeReplacements(attrsubst)
-                print >>sys.__stderr__, "emitStartElement", name, `repldict`
+                #print >>sys.__stderr__, "emitStartElement", name, `repldict`
             else:
                 repldict = {}
             if i18nattrs:
@@ -542,8 +552,8 @@
             # Convert repldict's name-->expr mapping to a
             # name-->(compiled_expr, translate) mapping
             for key, value in repldict.items():
-                if key == 'src':
-                    print >>sys.__stderr__, "src = %r" % value
+                #if key == 'src':
+                #    print >>sys.__stderr__, "src = %r" % value
                 repldict[key] = self.compileExpression(value), key in i18nattrs
             for key in i18nattrs:
                 if key not in repldict: