[Zope-Checkins] CVS: Zope/lib/python/DocumentTemplate - DT_HTML.py:1.30 DT_Return.py:1.4 DT_String.py:1.48 DT_Try.py:1.9 DT_Var.py:1.43 pDocumentTemplate.py:1.32
Andreas Jung
andreas@zope.com
Tue, 25 Sep 2001 09:37:02 -0400
Update of /cvs-repository/Zope/lib/python/DocumentTemplate
In directory cvs.zope.org:/tmp/cvs-serv30750
Modified Files:
DT_HTML.py DT_Return.py DT_String.py DT_Try.py DT_Var.py
pDocumentTemplate.py
Log Message:
replaced string module function calls by string method calls.
DTML stuff is now roughly 8-10% faster.
=== Zope/lib/python/DocumentTemplate/DT_HTML.py 1.29 => 1.30 ===
import DT_String, re
from DT_Util import ParseError, str
-from string import strip, find, split, join, rfind, replace
class dtml_re_class:
""" This needs to be replaced before 2.4. It's a hackaround. """
@@ -98,9 +97,6 @@
end_match=re.compile('[\000- ]*(/|end)', re.I).match,
start_search=re.compile('[<&]').search,
ent_name=re.compile('[-a-zA-Z0-9_.]+').match,
- find=find,
- strip=strip,
- replace=replace,
):
while 1:
@@ -109,23 +105,23 @@
s = mo.start(0)
if text[s:s+5] == '<!--#':
n=s+5
- e=find(text,'-->',n)
+ e=text.find('-->',n)
if e < 0: return None
en=3
mo =end_match(text,n)
if mo is not None:
l = mo.end(0) - mo.start(0)
- end=strip(text[n:n+l])
+ end=text[n:n+l].strip()
n=n+l
else: end=''
elif text[s:s+6] == '<dtml-':
e=n=s+6
while 1:
- e=find(text,'>',e+1)
+ e=text.find('>',e+1)
if e < 0: return None
- if len(split(text[n:e],'"'))%2:
+ if len(text[n:e].split('"'))%2:
# check for even number of "s inside
break
@@ -135,9 +131,9 @@
elif text[s:s+7] == '</dtml-':
e=n=s+7
while 1:
- e=find(text,'>',e+1)
+ e=text.find('>',e+1)
if e < 0: return None
- if len(split(text[n:e],'"'))%2:
+ if len(text[n:e].split('"'))%2:
# check for even number of "s inside
break
@@ -147,7 +143,7 @@
else:
if text[s:s+5] == '&dtml' and text[s+5] in '.-':
n=s+6
- e=find(text,';',n)
+ e=text.find(';',n)
if e >= 0:
args=text[n:e]
l=len(args)
@@ -163,13 +159,13 @@
self._start = s
return self
else:
- nn=find(args,'-')
+ nn=args.find('-')
if nn >= 0 and nn < l-1:
d[1]=d['end']=''
d[2]=d['name']='var'
d[0]=text[s:e+1]
- args=(args[nn+1:]+' '+
- replace(args[:nn],'.',' '))
+ args=args[nn+1:]+' '+ \
+ args[:nn].replace('.',' ')
d[3]=d['args']=args
self._start = s
return self
@@ -184,9 +180,9 @@
l = mo.end(0) - mo.start(0)
a=n+l
- name=strip(text[n:a])
+ name=text[n:a].strip()
- args=strip(text[a:e])
+ args=text[a:e].strip()
d=self.__dict__
d[0]=text[s:e+en]
@@ -238,7 +234,7 @@
or None otherwise
"""
tag, end, name, args = match_ob.group(0, 'end', 'name', 'args')
- args=strip(args)
+ args=args.strip()
if end:
if not command or name != command.name:
raise ParseError, ('unexpected end tag', tag)
@@ -282,7 +278,7 @@
(('"'), '"'))): #"
if text is None: text=self.read_raw()
for re,name in character_entities:
- if find(text, re) >= 0: text=join(split(text,re),name)
+ if text.find(re) >= 0: text=name.join(text.split(re))
return text
errQuote__roles__=()
@@ -327,7 +323,7 @@
def manage_edit(self,data,PARENTS,URL1,REQUEST):
'edit a template'
newHTML=self.copy_class(data,self.globals,self.__name__)
- setattr(PARENTS[1],URL1[rfind(URL1,'/')+1:],newHTML)
+ setattr(PARENTS[1],URL1[URL1.rfind('/')+1:],newHTML)
return self.editConfirmation(self,REQUEST)
@@ -375,9 +371,9 @@
PARENTS=[],URL1='',URL2='',REQUEST='', SUBMIT=''):
'edit a template'
if SUBMIT==FactoryDefaultString: return self.manage_default(REQUEST)
- if find(data,'\r'):
- data=join(split(data,'\r\n'),'\n\r')
- data=join(split(data,'\n\r'),'\n')
+ if data.find('\r'):
+ data='\n\r'.join(data.split('\r\n'))
+ data='\n'.join(data.split('\n\r'))
if self.edited_source:
self.edited_source=data
@@ -387,5 +383,5 @@
newHTML=self.__class__()
newHTML.__setstate__(self.__getstate__())
newHTML.edited_source=data
- setattr(PARENTS[1],URL1[rfind(URL1,'/')+1:],newHTML)
+ setattr(PARENTS[1],URL1[URL1.rfind('/')+1:],newHTML)
if REQUEST: return self.editConfirmation(self,REQUEST)
=== Zope/lib/python/DocumentTemplate/DT_Return.py 1.3 => 1.4 ===
from DT_Util import parse_params, name_param, str
import string, sys
-from string import find, split, join, atoi, rfind
class ReturnTag:
name='return'
=== Zope/lib/python/DocumentTemplate/DT_String.py 1.47 => 1.48 ===
"$Id$"
-from string import split, strip
import thread,re,exceptions,os
from DT_Util import ParseError, InstanceDict, TemplateDict, render_blocks, str
@@ -129,7 +128,7 @@
parse_error__roles__=()
def parse_error(self, mess, tag, text, start):
raise ParseError, "%s, for tag %s, on line %s of %s<p>" % (
- mess, self.errQuote(tag), len(split(text[:start],'\n')),
+ mess, self.errQuote(tag), len(text[:start].split('\n')),
self.errQuote(self.__name__))
commands__roles__=()
@@ -192,7 +191,7 @@
or None otherwise
"""
tag, name, args, fmt = match_ob.group(0, 'name', 'args', 'fmt')
- args=args and strip(args) or ''
+ args=args and args.strip() or ''
if fmt==']':
if not command or name != command.name:
=== Zope/lib/python/DocumentTemplate/DT_Try.py 1.8 => 1.9 ===
'in a try tag', self.name)
- for errname in string.split(nargs):
+ for errname in nargs.split():
self.handlers.append((errname,nsection.blocks))
- if string.strip(nargs)=='':
+ if nargs.split()=='':
if defaultHandlerFound:
raise ParseError, (
'Only one default exception handler '
=== Zope/lib/python/DocumentTemplate/DT_Var.py 1.42 => 1.43 ===
from DT_Util import parse_params, name_param, str
import re, string, sys
-from string import find, split, join, atoi, rfind
from urllib import quote, quote_plus
from cgi import escape
from html_quote import html_quote # for import by other modules, dont remove!
@@ -330,7 +329,7 @@
tag with a non-integer value.''')
if len(val) > size:
val=val[:size]
- l=rfind(val,' ')
+ l=val.rfind(' ')
if l > size/2:
val=val[:l+1]
if have_arg('etc'): l=args['etc']
@@ -362,8 +361,8 @@
def newline_to_br(v, name='(Unknown name)', md={}):
v=str(v)
- if find(v,'\r') >= 0: v=join(split(v,'\r'),'')
- if find(v,'\n') >= 0: v=join(split(v,'\n'),'<br>\n')
+ if v.find('\r') >= 0: v=''.join(v.split('\r'))
+ if v.find('\n') >= 0: v='<br>\n'.join(v.split('\n'))
return v
def whole_dollars(v, name='(Unknown name)', md={}):
@@ -378,11 +377,11 @@
thou=re.compile(
r"([0-9])([0-9][0-9][0-9]([,.]|$))").search):
v=str(v)
- vl=split(v,'.')
+ vl=v.split('.')
if not vl: return v
v=vl[0]
del vl[0]
- if vl: s='.'+join(vl,'.')
+ if vl: s='.'+'.'.join(vl)
else: s=''
mo=thou(v)
while mo is not None:
@@ -419,7 +418,7 @@
This is needed to securely insert values into sql
string literals in templates that generate sql.
"""
- if find(v,"'") >= 0: return join(split(v,"'"),"''")
+ if v.find("'") >= 0: return "''".join(v.split("'"))
return v
special_formats={
@@ -440,7 +439,7 @@
}
def spacify(val):
- if find(val,'_') >= 0: val=join(split(val,'_'))
+ if val.find('_') >= 0: val=" ".join(val.split('_'))
return val
modifiers=(html_quote, url_quote, url_quote_plus, newline_to_br,
=== Zope/lib/python/DocumentTemplate/pDocumentTemplate.py 1.31 => 1.32 ===
import string, sys, types
-from string import join
ClassTypes = [types.ClassType]
@@ -301,5 +300,5 @@
l=len(rendered)
if l==0: return ''
elif l==1: return rendered[0]
- return join(rendered, '')
+ return ''.join(rendered)
return rendered