[ZPT] CVS: Products/PageTemplates - Expressions.py:1.35.16.1 PageTemplate.py:1.24.16.1 PageTemplateFile.py:1.14.16.1 PathIterator.py:1.3.16.1 PythonExpr.py:1.7.16.1 TALES.py:1.30.6.1 ZPythonExpr.py:1.7.16.1 ZRPythonExpr.py:1.9.16.1 ZopePageTemplate.py:1.41.4.1
Evan Simpson
evan@zope.com
Tue, 9 Jul 2002 18:54:03 -0400
Update of /cvs-repository/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv29643
Modified Files:
Tag: evan-zpt-1_5_2-branch
Expressions.py PageTemplate.py PageTemplateFile.py
PathIterator.py PythonExpr.py TALES.py ZPythonExpr.py
ZRPythonExpr.py ZopePageTemplate.py
Log Message:
Remove string methods.
=== Products/PageTemplates/Expressions.py 1.35 => 1.35.16.1 ===
import re, sys
from TALES import Engine, CompilerError, _valid_name, NAME_RE, \
Undefined, Default, _parse_expr
+from string import strip, split, join, replace, lstrip
from Acquisition import aq_base, aq_inner, aq_parent
@@ -103,7 +104,7 @@
class SubPathExpr:
def __init__(self, path):
- self._path = path = path.strip().split('/')
+ self._path = path = split(strip(path), '/')
self._base = base = path.pop(0)
if not _valid_name(base):
raise CompilerError, 'Invalid variable name "%s"' % base
@@ -144,15 +145,15 @@
def __init__(self, name, expr, engine):
self._s = expr
self._name = name
- paths = expr.split('|')
+ paths = split(expr, '|')
self._subexprs = []
add = self._subexprs.append
for i in range(len(paths)):
- path = paths[i].lstrip()
+ path = lstrip(paths[i])
if _parse_expr(path):
# This part is the start of another expression type,
# so glue it back together and compile it.
- add(engine.compile(('|'.join(paths[i:]).lstrip())))
+ add(engine.compile(lstrip(join(paths[i:], '|'))))
break
add(SubPathExpr(path)._eval)
@@ -197,17 +198,17 @@
return '%s:%s' % (self._name, `self._s`)
-_interp = re.compile(r'\$(%(n)s)|\${(%(n)s(?:/[^}]*)*)}' % {'n': NAME_RE})
+_interp = re.compile(r'\$(%(n)s)|\${(%(n)s(?:/%(n)s)*)}' % {'n': NAME_RE})
class StringExpr:
def __init__(self, name, expr, engine):
self._s = expr
if '%' in expr:
- expr = expr.replace('%', '%%')
+ expr = replace(expr, '%', '%%')
self._vars = vars = []
if '$' in expr:
parts = []
- for exp in expr.split('$$'):
+ for exp in split(expr, '$$'):
if parts: parts.append('$')
m = _interp.search(exp)
while m is not None:
@@ -221,16 +222,15 @@
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):
vvals = []
for var in self._vars:
v = var(econtext)
- # I hope this isn't in use anymore.
- ## if isinstance(v, Exception):
- ## raise v
+ if isinstance(v, Exception):
+ raise v
vvals.append(v)
return self._expr % tuple(vvals)
@@ -242,7 +242,7 @@
class NotExpr:
def __init__(self, name, expr, compiler):
- self._s = expr = expr.lstrip()
+ self._s = expr = lstrip(expr)
self._c = compiler.compile(expr)
def __call__(self, econtext):
@@ -264,7 +264,7 @@
class DeferExpr:
def __init__(self, name, expr, compiler):
- self._s = expr = expr.lstrip()
+ self._s = expr = lstrip(expr)
self._c = compiler.compile(expr)
def __call__(self, econtext):
=== Products/PageTemplates/PageTemplate.py 1.24 => 1.24.16.1 ===
from TAL.TALGenerator import TALGenerator
from TAL.TALInterpreter import TALInterpreter
from Expressions import getEngine
+from string import join, strip, rstrip, split, replace, lower, find
from cStringIO import StringIO
from ExtensionClass import Base
from ComputedAttribute import ComputedAttribute
@@ -147,7 +148,7 @@
self._text) )
return ('%s\n %s\n-->\n%s' % (self._error_start,
- '\n '.join(self._v_errors),
+ join(self._v_errors, '\n '),
self._text))
def _cook(self):
@@ -181,7 +182,7 @@
class _ModuleImporter:
def __getitem__(self, module):
mod = __import__(module)
- path = module.split('.')
+ path = split(module, '.')
for name in path[1:]:
mod = getattr(mod, name)
return mod
=== Products/PageTemplates/PageTemplateFile.py 1.14 => 1.14.16.1 ===
import os, AccessControl, Acquisition, sys
from Globals import package_home, DevelopmentMode
from zLOG import LOG, ERROR, INFO
+from string import join, strip, rstrip, split, lower
from Shared.DC.Scripts.Script import Script, BindingsUI
from Shared.DC.Scripts.Signature import FuncCode
from AccessControl import getSecurityManager
@@ -115,7 +116,7 @@
self._cook()
if self._v_errors:
LOG('PageTemplateFile', ERROR, 'Error in template',
- '\n'.join(self._v_errors))
+ join(self._v_errors, '\n'))
return
self._v_last_read = mtime
=== Products/PageTemplates/PathIterator.py 1.3 => 1.3.16.1 ===
import TALES
from Expressions import restrictedTraverse, Undefs, getSecurityManager
+from string import split
class Iterator(TALES.Iterator):
def __bobo_traverse__(self, REQUEST, name):
@@ -35,7 +36,7 @@
if name is None:
return ob1 == ob2
if isinstance(name, type('')):
- name = name.split('/')
+ name = split(name, '/')
name = filter(None, name)
securityManager = getSecurityManager()
try:
=== Products/PageTemplates/PythonExpr.py 1.7 => 1.7.16.1 ===
__version__='$Revision$'[11:-2]
from TALES import CompilerError
+from string import strip, split, join, replace, lstrip
from sys import exc_info
class getSecurityManager:
@@ -27,10 +28,10 @@
class PythonExpr:
def __init__(self, name, expr, engine):
- self.expr = expr = expr.strip().replace('\n', ' ')
+ self.expr = expr = replace(strip(expr), '\n', ' ')
try:
d = {}
- exec 'def f():\n return %s\n' % expr.strip() in d
+ exec 'def f():\n return %s\n' % strip(expr) in d
self._f = d['f']
except:
raise CompilerError, ('Python expression error:\n'
=== Products/PageTemplates/TALES.py 1.30 => 1.30.6.1 ===
data = self.context.contexts.copy()
s = pprint.pformat(data)
if not as_html:
- return ' - Names:\n %s' % s.replace('\n', '\n ')
+ return ' - Names:\n %s' % string.replace(s, '\n', '\n ')
else:
from cgi import escape
return '<b>Names:</b><pre>%s</pre>' % (escape(s))
=== Products/PageTemplates/ZPythonExpr.py 1.7 => 1.7.16.1 ===
from Products.PythonScripts.Guarded import _marker, \
GuardedBlock, theGuard, safebin, WriteGuard, ReadGuard, UntupleFunction
from TALES import CompilerError
+from string import strip, split, join, replace, lstrip
from PythonExpr import PythonExpr
class PythonExpr(PythonExpr):
def __init__(self, name, expr, engine):
- self.expr = expr = expr.strip().replace('\n', ' ')
+ self.expr = expr = replace(strip(expr), '\n', ' ')
blk = GuardedBlock('def f():\n return \\\n %s\n' % expr)
if blk.errors:
raise CompilerError, ('Python expression error:\n%s' %
- '\n'.join(blk.errors) )
+ join(blk.errors, '\n') )
guards = {'$guard': theGuard, '$write_guard': WriteGuard,
'$read_guard': ReadGuard, '__debug__': __debug__}
self._f = UntupleFunction(blk.t, guards, __builtins__=safebin)
@@ -42,7 +43,7 @@
__allow_access_to_unprotected_subobjects__ = 1
def __getitem__(self, module):
mod = safebin['__import__'](module)
- path = module.split('.')
+ path = split(module, '.')
for name in path[1:]:
mod = getattr(mod, name)
return mod
=== Products/PageTemplates/ZRPythonExpr.py 1.9 => 1.9.16.1 ===
from AccessControl.ZopeGuards import guarded_getattr, guarded_getitem
from RestrictedPython import compile_restricted_eval
from TALES import CompilerError
+from string import strip, split, join, replace, lstrip
from PythonExpr import PythonExpr
@@ -32,11 +33,11 @@
'_getattr_': guarded_getattr,
'_getitem_': guarded_getitem,}
def __init__(self, name, expr, engine):
- self.expr = expr = expr.strip().replace('\n', ' ')
+ self.expr = expr = replace(strip(expr), '\n', ' ')
code, err, warn, use = compile_restricted_eval(expr, str(self))
if err:
raise CompilerError, ('Python expression error:\n%s' %
- '\n'.join(err) )
+ join(err, '\n') )
self._f_varnames = use.keys()
self._code = code
@@ -51,7 +52,7 @@
__allow_access_to_unprotected_subobjects__ = 1
def __getitem__(self, module):
mod = safe_builtins['__import__'](module)
- path = module.split('.')
+ path = split(module, '.')
for name in path[1:]:
mod = getattr(mod, name)
return mod
=== Products/PageTemplates/ZopePageTemplate.py 1.41 => 1.41.4.1 ===
__version__='$Revision$'[11:-2]
import os, AccessControl, Acquisition, sys
-from types import StringType
from Globals import DTMLFile, ImageFile, MessageDialog, package_home
from zLOG import LOG, ERROR, INFO
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
@@ -35,6 +35,7 @@
from OFS.Traversable import Traversable
from OFS.PropertyManager import PropertyManager
from PageTemplate import PageTemplate
+from types import StringType
from Expressions import SecureModuleImporter
from PageTemplateFile import PageTemplateFile
@@ -118,7 +119,7 @@
message = "Saved changes."
if getattr(self, '_v_warnings', None):
message = ("<strong>Warning:</strong> <i>%s</i>"
- % '<br>'.join(self._v_warnings))
+ % join(self._v_warnings, '<br>'))
return self.pt_editForm(manage_tabs_message=message)
def pt_setTitle(self, title):
@@ -144,12 +145,12 @@
szchw = {'Wider': 5, 'Narrower': -5, None: 0}
# The <textarea> can have dimensions expressed in percentages
- if type(width) is StringType and width.endswith('%'):
+ if type(width) is StringType and width[-1:] == '%':
cols = int(width[:-1])
cols = max(cols, 25) # Min width 25%
cols = max(cols, 100) # Max width 100%
cols = "%d%%" % cols # Add percent sign back on
- elif type(width) is StringType and dtpref_cols.endswith('%'):
+ elif type(width) is StringType and dtpref_cols[-1:] == '%':
cols = int(dtpref_cols[:-1])
cols = max(cols + szchw.get(width, 0), 25) # Min width 25%
cols = min(cols, 100) # Max width 100%
@@ -289,7 +290,7 @@
def pt_source_file(self):
"""Returns a file name to be compiled into the TAL code."""
try:
- return '/'.join(self.getPhysicalPath())
+ return string.join(self.getPhysicalPath(), '/')
except:
# This page template is being compiled without an
# acquisition context, so we don't know where it is. :-(