[ZPT] CVS: Zope3/lib/python/Zope/TAL - DummyEngine.py:1.28.14.2 HTMLTALParser.py:1.30.4.2 TALDefs.py:1.24.10.2 TALGenerator.py:1.52.16.2 TALParser.py:1.16.16.2 driver.py:1.25.18.2 ndiff.py:1.2.24.1 runtest.py:1.19.14.2 setpath.py:1.3.24.2
Martijn Pieters
mj@zope.com
Wed, 13 Feb 2002 00:03:41 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/TAL
In directory cvs.zope.org:/tmp/cvs-serv14206/TAL
Modified Files:
Tag: Zope-3x-branch
DummyEngine.py HTMLTALParser.py TALDefs.py TALGenerator.py
TALParser.py driver.py ndiff.py runtest.py setpath.py
Log Message:
Optimizations and code style updates:
- Use isinstance on type checks
- Test UnicodeType and StringType through StringTypes
- Remove use of the string module
- Use startswith and endswith instead of slices.
- Fix weird tests where isinstance suffices.
=== Zope3/lib/python/Zope/TAL/DummyEngine.py 1.28.14.1 => 1.28.14.2 ===
import re
import sys
-from string import rfind, strip
import driver
@@ -46,7 +45,8 @@
return "$%s$" % expr
def uncompile(self, expression):
- assert expression[:1] == "$" == expression[-1:], expression
+ assert (expression.startswith("$") and expression.endswith("$"),
+ expression)
return expression[1:-1]
def beginScope(self):
@@ -66,7 +66,8 @@
self.globals[name] = value
def evaluate(self, expression):
- assert expression[:1] == "$" == expression[-1:], expression
+ assert (expression.startswith("$") and expression.endswith("$"),
+ expression)
expression = expression[1:-1]
m = name_match(expression)
if m:
@@ -77,7 +78,7 @@
if type in ("string", "str"):
return expr
if type in ("path", "var", "global", "local"):
- expr = strip(expr)
+ expr = expr.strip()
if self.locals.has_key(expr):
return self.locals[expr]
elif self.globals.has_key(expr):
@@ -117,7 +118,8 @@
return self.evaluate(expr)
def evaluateMacro(self, macroName):
- assert macroName[:1] == "$" == macroName[-1:], macroName
+ assert (macroName.startswith("$") and macroName.endswith("$"),
+ macroName)
macroName = macroName[1:-1]
file, localName = self.findMacroFile(macroName)
if not file:
@@ -142,7 +144,7 @@
def findMacroFile(self, macroName):
if not macroName:
raise TALESError("empty macro name")
- i = rfind(macroName, '/')
+ i = macroName.rfind('/')
if i < 0:
# No slash -- must be a locally defined macro
return None, macroName
=== Zope3/lib/python/Zope/TAL/HTMLTALParser.py 1.30.4.1 => 1.30.4.2 ===
import sys
-import string
from TALGenerator import TALGenerator
from TALDefs import ZOPE_METAL_NS, ZOPE_TAL_NS, METALError, TALError
@@ -69,7 +68,7 @@
% (tagstack[0], endtag))
else:
msg = ('Open tags <%s> do not match close tag </%s>'
- % (string.join(tagstack, '>, <'), endtag))
+ % ('>, <'.join(tagstack), endtag))
else:
msg = 'No tags are open to match </%s>' % endtag
HTMLParseError.__init__(self, msg, position)
@@ -230,7 +229,7 @@
def scan_xmlns(self, attrs):
nsnew = {}
for key, value in attrs:
- if key[:6] == "xmlns:":
+ if key.startswith("xmlns:"):
nsnew[key[6:]] = value
if nsnew:
self.nsstack.append(self.nsdict)
@@ -244,7 +243,7 @@
def fixname(self, name):
if ':' in name:
- prefix, suffix = string.split(name, ':', 1)
+ prefix, suffix = name.split(':', 1)
if prefix == 'xmlns':
nsuri = self.nsdict.get(suffix)
if nsuri in (ZOPE_TAL_NS, ZOPE_METAL_NS):
=== Zope3/lib/python/Zope/TAL/TALDefs.py 1.24.10.1 => 1.24.10.2 ===
# Break in pieces at undoubled semicolons and
# change double semicolons to singles:
- 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]):
+ arg = arg.replace(";;", "\0")
+ parts = arg.split(';')
+ parts = [p.replace("\0", ";") for p in parts]
+ if len(parts) > 1 and not parts[-1].strip():
del parts[-1] # It ended in a semicolon
return parts
=== Zope3/lib/python/Zope/TAL/TALGenerator.py 1.52.16.1 => 1.52.16.2 ===
"""
-import string
import re
import cgi
@@ -73,9 +72,9 @@
# instructions to be joined together.
output.append(self.optimizeArgsList(item))
continue
- text = string.join(collect, "")
+ text = "".join(collect)
if text:
- i = string.rfind(text, "\n")
+ i = text.rfind("\n")
if i >= 0:
i = len(text) - (i + 1)
output.append(("rawtextColumn", (text, i)))
@@ -267,7 +266,7 @@
def emitDefineMacro(self, macroName):
program = self.popProgram()
- macroName = string.strip(macroName)
+ macroName = macroName.strip()
if self.macros.has_key(macroName):
raise METALError("duplicate macro definition: %s" % `macroName`,
self.position)
@@ -286,7 +285,7 @@
def emitDefineSlot(self, slotName):
program = self.popProgram()
- slotName = string.strip(slotName)
+ slotName = slotName.strip()
if not re.match('%s$' % NAME_RE, slotName):
raise METALError("invalid slot name: %s" % `slotName`,
self.position)
@@ -294,7 +293,7 @@
def emitFillSlot(self, slotName):
program = self.popProgram()
- slotName = string.strip(slotName)
+ slotName = slotName.strip()
if self.slots.has_key(slotName):
raise METALError("duplicate fill-slot name: %s" % `slotName`,
self.position)
@@ -325,7 +324,7 @@
self.program[i] = ("rawtext", text[:m.start()])
collect.append(m.group())
collect.reverse()
- return string.join(collect, "")
+ return "".join(collect)
def unEmitNewlineWhitespace(self):
collect = []
@@ -344,7 +343,7 @@
break
text, rest = m.group(1, 2)
collect.reverse()
- rest = rest + string.join(collect, "")
+ rest = rest + "".join(collect)
del self.program[i:]
if text:
self.emit("rawtext", text)
=== Zope3/lib/python/Zope/TAL/TALParser.py 1.16.16.1 => 1.16.16.2 ===
"""
-import string
from XMLParser import XMLParser
from TALDefs import *
from TALGenerator import TALGenerator
@@ -94,7 +93,7 @@
def fixname(self, name):
if ' ' in name:
- uri, name = string.split(name, ' ')
+ uri, name = name.split(' ')
prefix = self.nsDict[uri]
prefixed = name
if prefix:
=== Zope3/lib/python/Zope/TAL/driver.py 1.25.18.1 => 1.25.18.2 ===
import os
import sys
-import string
import getopt
@@ -89,7 +88,7 @@
assert mode in ("html", "xml", None)
if mode is None:
ext = os.path.splitext(file)[1]
- if string.lower(ext) in (".html", ".htm"):
+ if ext.lower() in (".html", ".htm"):
mode = "html"
else:
mode = "xml"
=== Zope3/lib/python/Zope/TAL/ndiff.py 1.2 => 1.2.24.1 ===
# have been in sys.argv[1:] had the cmd-line form been used.
-import string
TRACE = 0
# define what "junk" means
=== Zope3/lib/python/Zope/TAL/runtest.py 1.19.14.1 => 1.19.14.2 ===
import sys
import os
-import string
from cStringIO import StringIO
import glob
import traceback
@@ -53,7 +52,7 @@
if args and args[0] == "-Q":
unittesting = 1
del args[0]
- while args and args[0][:1] == '-':
+ while args and args[0].startswith('-'):
opts.append(args[0])
del args[0]
if not args:
@@ -72,12 +71,12 @@
errors = 0
for arg in args:
locopts = []
- if string.find(arg, "metal") >= 0 and "-m" not in opts:
+ if arg.find("metal") >= 0 and "-m" not in opts:
locopts.append("-m")
if not unittesting:
print arg,
sys.stdout.flush()
- if tests.utils.skipxml and arg[-4:] == ".xml":
+ if tests.utils.skipxml and arg.endswith(".xml"):
print "SKIPPED (XML parser not available)"
continue
save = sys.stdout, sys.argv
@@ -105,7 +104,7 @@
continue
head, tail = os.path.split(arg)
outfile = os.path.join(
- string.replace(head, "input", "output"),
+ head.replace("input", "output"),
tail)
try:
f = open(outfile)
=== Zope3/lib/python/Zope/TAL/setpath.py 1.3.24.1 => 1.3.24.2 ===
import os
import sys
-import string
dir = os.path.dirname(__file__)
path = os.path.join(dir, ".path")
@@ -20,7 +19,7 @@
raise IOError, "Please edit .path to point to <Zope2/lib/python>"
else:
for line in f.readlines():
- line = string.strip(line)
+ line = line.strip()
if line and line[0] != '#':
for dir in string.split(line, os.pathsep):
dir = os.path.expanduser(os.path.expandvars(dir))