[Zope-Checkins] CVS: Packages/TAL - DummyEngine.py:1.31.6.1 HTMLParser.py:1.24.10.1 HTMLTALParser.py:1.32.24.1 TALDefs.py:1.27.24.1 TALGenerator.py:1.54.24.1 TALInterpreter.py:1.68.24.1 TALParser.py:1.18.24.1 driver.py:1.27.24.1 markbench.py:1.3.24.1 markupbase.py:1.2.16.1 runtest.py:1.21.24.1 setpath.py:1.5.16.1

Evan Simpson evan@zope.com
Tue, 9 Jul 2002 18:50:03 -0400


Update of /cvs-repository/Packages/TAL
In directory cvs.zope.org:/tmp/cvs-serv28386

Modified Files:
      Tag: evan-zpt-1_5_2-branch
	DummyEngine.py HTMLParser.py HTMLTALParser.py TALDefs.py 
	TALGenerator.py TALInterpreter.py TALParser.py driver.py 
	markbench.py markupbase.py runtest.py setpath.py 
Log Message:
Remove string methods.


=== Packages/TAL/DummyEngine.py 1.31 => 1.31.6.1 ===
 
 import re
 import sys
+from string import rfind, strip
 
 import driver
 
@@ -57,8 +58,7 @@
         return "$%s$" % expr
 
     def uncompile(self, expression):
-        assert (expression.startswith("$") and expression.endswith("$"),
-            expression)
+        assert expression[:1] == "$" == expression[-1:], expression
         return expression[1:-1]
 
     def beginScope(self):
@@ -78,8 +78,7 @@
         self.globals[name] = value
 
     def evaluate(self, expression):
-        assert (expression.startswith("$") and expression.endswith("$"),
-            expression)
+        assert expression[:1] == "$" == expression[-1:], expression
         expression = expression[1:-1]
         m = name_match(expression)
         if m:
@@ -90,7 +89,7 @@
         if type in ("string", "str"):
             return expr
         if type in ("path", "var", "global", "local"):
-            expr = expr.strip()
+            expr = strip(expr)
             if self.locals.has_key(expr):
                 return self.locals[expr]
             elif self.globals.has_key(expr):
@@ -137,8 +136,7 @@
         return self.evaluate(expr)
 
     def evaluateMacro(self, macroName):
-        assert (macroName.startswith("$") and macroName.endswith("$"),
-            macroName)
+        assert macroName[:1] == "$" == macroName[-1:], macroName
         macroName = macroName[1:-1]
         file, localName = self.findMacroFile(macroName)
         if not file:
@@ -163,7 +161,7 @@
     def findMacroFile(self, macroName):
         if not macroName:
             raise TALESError("empty macro name")
-        i = macroName.rfind('/')
+        i = rfind(macroName, '/')
         if i < 0:
             # No slash -- must be a locally defined macro
             return None, macroName


=== Packages/TAL/HTMLParser.py 1.24 => 1.24.10.1 ===
 
 import markupbase
 import re
+import string
 
 # Regular expressions used for parsing
 
@@ -259,7 +260,7 @@
         match = tagfind.match(rawdata, i+1)
         assert match, 'unexpected call to parse_starttag()'
         k = match.end()
-        self.lasttag = tag = rawdata[i+1:k].lower()
+        self.lasttag = tag = string.lower(rawdata[i+1:k])
 
         while k < endpos:
             m = attrfind.match(rawdata, k)
@@ -272,16 +273,16 @@
                  attrvalue[:1] == '"' == attrvalue[-1:]:
                 attrvalue = attrvalue[1:-1]
                 attrvalue = self.unescape(attrvalue)
-            attrs.append((attrname.lower(), attrvalue))
+            attrs.append((string.lower(attrname), attrvalue))
             k = m.end()
 
-        end = rawdata[k:endpos].strip()
+        end = string.strip(rawdata[k:endpos])
         if end not in (">", "/>"):
             lineno, offset = self.getpos()
             if "\n" in self.__starttag_text:
-                lineno = lineno + self.__starttag_text.count("\n")
+                lineno = lineno + string.count(self.__starttag_text, "\n")
                 offset = len(self.__starttag_text) \
-                         - self.__starttag_text.rfind("\n")
+                         - string.rfind(self.__starttag_text, "\n")
             else:
                 offset = offset + len(self.__starttag_text)
             self.error("junk characters in start tag: %s"
@@ -338,7 +339,7 @@
         match = endtagfind.match(rawdata, i) # </ + tag + >
         if not match:
             self.error("bad end tag: %s" % `rawdata[i:j]`)
-        tag = match.group(1).lower()
+        tag = string.lower(match.group(1))
         if (  self.cdata_endtag is not None
               and tag != self.cdata_endtag):
             # Should be a mismatched end tag, but we'll treat it
@@ -394,9 +395,9 @@
     def unescape(self, s):
         if '&' not in s:
             return s
-        s = s.replace("&lt;", "<")
-        s = s.replace("&gt;", ">")
-        s = s.replace("&apos;", "'")
-        s = s.replace("&quot;", '"')
-        s = s.replace("&amp;", "&") # Must be last
+        s = string.replace(s, "&lt;", "<")
+        s = string.replace(s, "&gt;", ">")
+        s = string.replace(s, "&apos;", "'")
+        s = string.replace(s, "&quot;", '"')
+        s = string.replace(s, "&amp;", "&") # Must be last
         return s


=== Packages/TAL/HTMLTALParser.py 1.32 => 1.32.24.1 ===
 """
 
 import sys
+import string
 
 from TALGenerator import TALGenerator
 from TALDefs import ZOPE_METAL_NS, ZOPE_TAL_NS, METALError, TALError
@@ -74,7 +75,7 @@
                        % (tagstack[0], endtag))
             else:
                 msg = ('Open tags <%s> do not match close tag </%s>'
-                       % ('>, <'.join(tagstack), endtag))
+                       % (string.join(tagstack, '>, <'), endtag))
         else:
             msg = 'No tags are open to match </%s>' % endtag
         HTMLParseError.__init__(self, msg, position)
@@ -235,7 +236,7 @@
     def scan_xmlns(self, attrs):
         nsnew = {}
         for key, value in attrs:
-            if key.startswith("xmlns:"):
+            if key[:6] == "xmlns:":
                 nsnew[key[6:]] = value
         if nsnew:
             self.nsstack.append(self.nsdict)
@@ -249,7 +250,7 @@
 
     def fixname(self, name):
         if ':' in name:
-            prefix, suffix = name.split(':', 1)
+            prefix, suffix = string.split(name, ':', 1)
             if prefix == 'xmlns':
                 nsuri = self.nsdict.get(suffix)
                 if nsuri in (ZOPE_TAL_NS, ZOPE_METAL_NS):


=== Packages/TAL/TALDefs.py 1.27 => 1.27.24.1 ===
     "use-macro",
     "define-slot",
     "fill-slot",
-    "slot",
+    "slot"
     ]
 
 KNOWN_TAL_ATTRIBUTES = [
@@ -69,7 +69,6 @@
 class TALESError(TALError):
     pass
 
-
 class ErrorInfo:
 
     def __init__(self, err, position=(None, None)):
@@ -82,8 +81,6 @@
         self.lineno = position[0]
         self.offset = position[1]
 
-
-
 import re
 _attr_re = re.compile(r"\s*([^\s]+)\s+([^\s].*)\Z", re.S)
 _subst_re = re.compile(r"\s*(?:(text|structure)\s+)?(.*)\Z", re.S)
@@ -113,10 +110,11 @@
 def splitParts(arg):
     # Break in pieces at undoubled semicolons and
     # change double semicolons to singles:
-    arg = arg.replace(";;", "\0")
-    parts = arg.split(';')
-    parts = [p.replace("\0", ";") for p in parts]
-    if len(parts) > 1 and not parts[-1].strip():
+    import string
+    arg = string.replace(arg, ";;", "\0")
+    parts = string.split(arg, ';')
+    parts = map(lambda s, repl=string.replace: repl(s, "\0", ";"), parts)
+    if len(parts) > 1 and not string.strip(parts[-1]):
         del parts[-1] # It ended in a semicolon
     return parts
 


=== Packages/TAL/TALGenerator.py 1.54 => 1.54.24.1 ===
 Code generator for TALInterpreter intermediate code.
 """
 
+import string
 import re
 import cgi
 
@@ -82,9 +83,9 @@
                 # instructions to be joined together.
                 output.append(self.optimizeArgsList(item))
                 continue
-            text = "".join(collect)
+            text = string.join(collect, "")
             if text:
-                i = text.rfind("\n")
+                i = string.rfind(text, "\n")
                 if i >= 0:
                     i = len(text) - (i + 1)
                     output.append(("rawtextColumn", (text, i)))
@@ -276,7 +277,7 @@
 
     def emitDefineMacro(self, macroName):
         program = self.popProgram()
-        macroName = macroName.strip()
+        macroName = string.strip(macroName)
         if self.macros.has_key(macroName):
             raise METALError("duplicate macro definition: %s" % `macroName`,
                              self.position)
@@ -295,7 +296,7 @@
 
     def emitDefineSlot(self, slotName):
         program = self.popProgram()
-        slotName = slotName.strip()
+        slotName = string.strip(slotName)
         if not re.match('%s$' % NAME_RE, slotName):
             raise METALError("invalid slot name: %s" % `slotName`,
                              self.position)
@@ -303,7 +304,7 @@
 
     def emitFillSlot(self, slotName):
         program = self.popProgram()
-        slotName = slotName.strip()
+        slotName = string.strip(slotName)
         if self.slots.has_key(slotName):
             raise METALError("duplicate fill-slot name: %s" % `slotName`,
                              self.position)
@@ -334,7 +335,7 @@
                 self.program[i] = ("rawtext", text[:m.start()])
                 collect.append(m.group())
         collect.reverse()
-        return "".join(collect)
+        return string.join(collect, "")
 
     def unEmitNewlineWhitespace(self):
         collect = []
@@ -353,7 +354,7 @@
                 break
             text, rest = m.group(1, 2)
             collect.reverse()
-            rest = rest + "".join(collect)
+            rest = rest + string.join(collect, "")
             del self.program[i:]
             if text:
                 self.emit("rawtext", text)


=== Packages/TAL/TALInterpreter.py 1.68 => 1.68.24.1 ===
 import getopt
 
 from cgi import escape
+from string import join, lower, rfind
+try:
+    from strop import lower, rfind
+except ImportError:
+    pass
 
 try:
     from cStringIO import StringIO
@@ -159,9 +164,9 @@
             self.col = 0
 
     def stream_write(self, s,
-                     len=len):
+                     len=len, rfind=rfind):
         self._stream_write(s)
-        i = s.rfind('\n')
+        i = rfind(s, '\n')
         if i < 0:
             self.col = self.col + len(s)
         else:
@@ -267,7 +272,7 @@
             # Clear 'entering' flag
             macs[-1][2] = 0
             # Convert or drop depth-one METAL attributes.
-            i = name.rfind(":") + 1
+            i = rfind(name, ":") + 1
             prefix, suffix = name[:i], name[i:]
             if suffix == "define-macro":
                 # Convert define-macro as we enter depth one.
@@ -291,7 +296,7 @@
         if action > 1:
             return self.attrAction(item)
         ok = 1
-        if self.html and name.lower() in BOOLEAN_HTML_ATTRS:
+        if self.html and lower(name) in BOOLEAN_HTML_ATTRS:
             evalue = self.engine.evaluateBoolean(item[3])
             if evalue is self.Default:
                 if action == 1: # Cancelled insert
@@ -419,7 +424,7 @@
             return
         s = escape(text)
         self._stream_write(s)
-        i = s.rfind('\n')
+        i = rfind(s, '\n')
         if i < 0:
             self.col = self.col + len(s)
         else:


=== Packages/TAL/TALParser.py 1.18 => 1.18.24.1 ===
 Parse XML and compile to TALInterpreter intermediate code.
 """
 
+import string
 from XMLParser import XMLParser
 from TALDefs import *
 from TALGenerator import TALGenerator
@@ -99,7 +100,7 @@
 
     def fixname(self, name):
         if ' ' in name:
-            uri, name = name.split(' ')
+            uri, name = string.split(name, ' ')
             prefix = self.nsDict[uri]
             prefixed = name
             if prefix:


=== Packages/TAL/driver.py 1.27 => 1.27.24.1 ===
-#!/usr/bin/env python
+#! /usr/bin/env python
 ##############################################################################
 #
 # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
@@ -18,6 +18,7 @@
 
 import os
 import sys
+import string
 
 import getopt
 
@@ -93,7 +94,7 @@
     assert mode in ("html", "xml", None)
     if mode is None:
         ext = os.path.splitext(file)[1]
-        if ext.lower() in (".html", ".htm"):
+        if string.lower(ext) in (".html", ".htm"):
             mode = "html"
         else:
             mode = "xml"


=== Packages/TAL/markbench.py 1.3 => 1.3.24.1 ===
 #! /usr/bin/env python
-
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
 # This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS 
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+# 
+##############################################################################
 
 '''Run benchmarks of TAL vs. DTML'''
 


=== Packages/TAL/markupbase.py 1.2 => 1.2.16.1 ===
 """Shared support for scanning document type declarations in HTML and XHTML."""
 
-import re, string
+import re
+import string
 
 _declname_match = re.compile(r'[a-zA-Z][-_.a-zA-Z0-9]*\s*').match
 _declstringlit_match = re.compile(r'(\'[^\']*\'|"[^"]*")\s*').match
@@ -28,10 +29,10 @@
         if i >= j:
             return j
         rawdata = self.rawdata
-        nlines = rawdata.count("\n", i, j)
+        nlines = string.count(rawdata, "\n", i, j)
         if nlines:
             self.lineno = self.lineno + nlines
-            pos = rawdata.rindex("\n", i, j) # Should not fail
+            pos = string.rindex(rawdata, "\n", i, j) # Should not fail
             self.offset = j-(pos+1)
         else:
             self.offset = self.offset + j-i
@@ -168,7 +169,7 @@
             return -1
         # style content model; just skip until '>'
         if '>' in rawdata[j:]:
-            return rawdata.find(">", j) + 1
+            return string.find(rawdata, ">", j) + 1
         return -1
 
     # Internal -- scan past <!ATTLIST declarations
@@ -192,7 +193,7 @@
             if c == "(":
                 # an enumerated type; look for ')'
                 if ")" in rawdata[j:]:
-                    j = awdata.find(")", j) + 1
+                    j = string.find(rawdata, ")", j) + 1
                 else:
                     return -1
                 while rawdata[j:j+1] in string.whitespace:
@@ -296,10 +297,10 @@
         m = _declname_match(rawdata, i)
         if m:
             s = m.group()
-            name = s.strip()
+            name = string.strip(s)
             if (i + len(s)) == n:
                 return None, -1  # end of buffer
-            return name.lower(), m.end()
+            return string.lower(name), m.end()
         else:
             self.updatepos(declstartpos, i)
             self.error("expected name token", self.getpos())


=== Packages/TAL/runtest.py 1.21 => 1.21.24.1 ===
 #! /usr/bin/env python
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2001,2002 Zope Corporation and Contributors.
 # All Rights Reserved.
 # 
 # This software is subject to the provisions of the Zope Public License,
@@ -18,6 +18,7 @@
 
 import sys
 import os
+import string
 from cStringIO import StringIO
 import glob
 import traceback
@@ -57,7 +58,7 @@
     if args and args[0] == "-Q":
         unittesting = 1
         del args[0]
-    while args and args[0].startswith('-'):
+    while args and args[0][:1] == '-':
         opts.append(args[0])
         del args[0]
     if not args:
@@ -76,12 +77,12 @@
     errors = 0
     for arg in args:
         locopts = []
-        if arg.find("metal") >= 0 and "-m" not in opts:
+        if string.find(arg, "metal") >= 0 and "-m" not in opts:
             locopts.append("-m")
         if not unittesting:
             print arg,
             sys.stdout.flush()
-        if tests.utils.skipxml and arg.endswith(".xml"):
+        if tests.utils.skipxml and arg[-4:] == ".xml":
             print "SKIPPED (XML parser not available)"
             continue
         save = sys.stdout, sys.argv
@@ -109,7 +110,7 @@
             continue
         head, tail = os.path.split(arg)
         outfile = os.path.join(
-            head.replace("input", "output"),
+            string.replace(head, "input", "output"),
             tail)
         try:
             f = open(outfile)


=== Packages/TAL/setpath.py 1.5 => 1.5.16.1 ===
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
 # This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS 
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+# 
+##############################################################################
 """
 Read a module search path from .path.
 """
 import os
 import sys
+import string
 
 dir = os.path.dirname(__file__)
 path = os.path.join(dir, ".path")
@@ -19,9 +26,9 @@
     raise IOError, "Please edit .path to point to <Zope2/lib/python>"
 else:
     for line in f.readlines():
-        line = line.strip()
+        line = string.strip(line)
         if line and line[0] != '#':
-            for dir in line.split(os.pathsep):
+            for dir in string.split(line, os.pathsep):
                 dir = os.path.expanduser(os.path.expandvars(dir))
                 if dir not in sys.path:
                     sys.path.append(dir)