[Zope-Checkins] CVS: Zope3/lib/python/Zope/PageTemplate - Expressions.py:1.1.2.6 PageTemplate.py:1.1.2.11 PageTemplateFile.py:1.1.2.14 PythonExpr.py:1.1.2.4 TALES.py:1.1.2.6 ZopePageTemplate.py:1.1.2.4
Martijn Pieters
mj@zope.com
Wed, 13 Feb 2002 00:03:38 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/PageTemplate
In directory cvs.zope.org:/tmp/cvs-serv14206/PageTemplate
Modified Files:
Tag: Zope-3x-branch
Expressions.py PageTemplate.py PageTemplateFile.py
PythonExpr.py TALES.py ZopePageTemplate.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/PageTemplate/Expressions.py 1.1.2.5 => 1.1.2.6 ===
from TALES import Engine, CompilerError, _valid_name, NAME_RE, \
TALESError, Undefined, Default
-from string import strip, split, join, replace, lstrip
def aq_base(ob):
return ob
@@ -95,10 +94,10 @@
def __init__(self, name, expr, engine):
self._s = expr
self._name = name
- self._paths = map(self._prepPath, split(expr, '|'))
+ self._paths = map(self._prepPath, expr.split('|'))
def _prepPath(self, path):
- path = split(strip(path), '/')
+ path = path.strip().split('/')
base = path.pop(0)
if not _valid_name(base):
raise CompilerError, 'Invalid variable name "%s"' % base
@@ -106,7 +105,7 @@
dp = []
for i in range(len(path)):
e = path[i]
- if e[:1] == '?' and _valid_name(e[1:]):
+ if e.startswith('?') and _valid_name(e[1:]):
dp.append((i, e[1:]))
dp.reverse()
return base, path, dp
@@ -170,11 +169,11 @@
def __init__(self, name, expr, engine):
self._s = expr
if '%' in expr:
- expr = replace(expr, '%', '%%')
+ expr = expr.replace('%', '%%')
self._vars = vars = []
if '$' in expr:
parts = []
- for exp in split(expr, '$$'):
+ for exp in expr.split('$$'):
if parts: parts.append('$')
m = _interp.search(exp)
while m is not None:
@@ -188,7 +187,7 @@
raise CompilerError, (
'$ must be doubled or followed by a simple path')
parts.append(exp)
- expr = join(parts, '')
+ expr = ''.join(parts)
self._expr = expr
def __call__(self, econtext):
@@ -208,7 +207,7 @@
class NotExpr:
def __init__(self, name, expr, compiler):
- self._s = expr = lstrip(expr)
+ self._s = expr = expr.lstrip()
self._c = compiler.compile(expr)
def __call__(self, econtext):
@@ -230,7 +229,7 @@
class DeferExpr:
def __init__(self, name, expr, compiler):
- self._s = expr = lstrip(expr)
+ self._s = expr = expr.lstrip()
self._c = compiler.compile(expr)
def __call__(self, econtext):
=== Zope3/lib/python/Zope/PageTemplate/PageTemplate.py 1.1.2.10 => 1.1.2.11 ===
from Zope.TAL.TALInterpreter import TALInterpreter
from Expressions import getEngine
-from string import join, strip, rstrip, split, replace, lower, find
from cStringIO import StringIO
+from types import StringType
Z_DEBUG_MODE = os.environ.get('Z_DEBUG_MODE') == '1'
@@ -114,9 +114,9 @@
return self._v_warnings
def write(self, text):
- assert type(text) is type('')
+ assert isinstance(text, StringType)
if text[:len(self._error_start)] == self._error_start:
- errend = find(text, '-->')
+ errend = text.find('-->')
if errend >= 0:
text = text[errend + 4:]
if self._text != text:
@@ -135,7 +135,7 @@
self._text) )
return ('%s\n %s\n-->\n%s' % (self._error_start,
- join(self._v_errors, '\n '),
+ '\n'.join(self._v_errors),
self._text))
def _cook(self):
@@ -170,7 +170,7 @@
class _ModuleImporter:
def __getitem__(self, module):
mod = __import__(module)
- path = split(module, '.')
+ path = module.split('.')
for name in path[1:]:
mod = getattr(mod, name)
return mod
=== Zope3/lib/python/Zope/PageTemplate/PageTemplateFile.py 1.1.2.13 => 1.1.2.14 ===
import os, sys
from zLOG import LOG, ERROR, INFO
-from string import join
from ViewZPT import ViewZPT
from Expressions import SecureModuleImporter
from Zope.Misc.package_home import package_home
@@ -72,7 +71,7 @@
self._cook()
if self._v_errors:
LOG('PageTemplateFile', ERROR, 'Error in template',
- join(self._v_errors, '\n'))
+ '\n'.join(self._v_errors))
return
self._v_last_read = mtime
=== Zope3/lib/python/Zope/PageTemplate/PythonExpr.py 1.1.2.3 => 1.1.2.4 ===
from TALES import CompilerError
-from string import strip, split, join, replace, lstrip
from sys import exc_info
class getSecurityManager:
@@ -23,10 +22,10 @@
class PythonExpr:
def __init__(self, name, expr, engine):
- self.expr = expr = replace(strip(expr), '\n', ' ')
+ self.expr = expr = expr.strip().replace('\n', ' ')
try:
d = {}
- exec 'def f():\n return %s\n' % strip(expr) in d
+ exec 'def f():\n return %s\n' % expr.strip() in d
self._f = d['f']
except:
raise CompilerError, ('Python expression error:\n'
=== Zope3/lib/python/Zope/PageTemplate/TALES.py 1.1.2.5 => 1.1.2.6 ===
import Zope.ZTUtils
-StringType = type('')
+from types import StringType
NAME_RE = r"[a-zA-Z][a-zA-Z0-9_]*"
_parse_expr = re.compile(r"(%s):" % NAME_RE).match
=== Zope3/lib/python/Zope/PageTemplate/ZopePageTemplate.py 1.1.2.3 => 1.1.2.4 ===
from OFS.SimpleItem import SimpleItem
from DateTime.DateTime import DateTime
-from string import join, strip, rstrip, split, replace, lower
from Shared.DC.Scripts.Script import Script, BindingsUI
from Shared.DC.Scripts.Signature import FuncCode
from AccessControl import getSecurityManager, Unauthorized
@@ -29,6 +28,7 @@
from TALES import TALESError
from Expressions import SecureModuleImporter
from PageTemplateFile import PageTemplateFile
+from types import StringType
try:
from webdav.Lockable import ResourceLockedError
@@ -107,7 +107,7 @@
message = "Saved changes."
if getattr(self, '_v_warnings', None):
message = ("<strong>Warning:</strong> <i>%s</i>"
- % join(self._v_warnings, '<br>'))
+ % '<br>'.join(self._v_warnings))
return self.pt_editForm(manage_tabs_message=message)
def pt_setTitle(self, title):
@@ -117,7 +117,7 @@
"""Replace the document with the text in file."""
if SUPPORTS_WEBDAV_LOCKS and self.wl_isLocked():
raise ResourceLockedError, "File is locked via WebDAV"
- if type(file) is not type(''): file = file.read()
+ if not isinstance(filei, StringType): file = file.read()
self.write(file)
message = 'Saved changes.'
return self.pt_editForm(manage_tabs_message=message)