[Zope-Checkins] CVS: Zope2 - DT_HTML.py:1.24.84.1
Andreas Jung
andreas@dhcp165.digicool.com
Thu, 19 Apr 2001 14:02:12 -0400
Update of /cvs-repository/Zope2/lib/python/DocumentTemplate
In directory yetix:/work/sandboxes/ajung-2_4-ts_regex-exterminiation-branch/lib/python/DocumentTemplate
Modified Files:
Tag: ajung-2_4-ts_regex-exterminiation-branch
DT_HTML.py
Log Message:
regex free - another one bites the dust
--- Updated File DT_HTML.py in package Zope2 --
--- DT_HTML.py 2000/08/17 14:03:42 1.24
+++ DT_HTML.py 2001/04/19 18:00:56 1.24.84.1
@@ -87,34 +87,35 @@
$Id$"""
from DT_String import String, FileMixin
-import DT_String, regex
+import DT_String, re
from DT_Util import ParseError, str
from string import strip, find, split, join, rfind, replace
class dtml_re_class:
def search(self, text, start=0,
- name_match=regex.compile('[\0- ]*[a-zA-Z]+[\0- ]*').match,
- end_match=regex.compile('[\0- ]*\(/\|end\)',
- regex.casefold).match,
- start_search=regex.compile('[<&]').search,
- ent_name=regex.compile('[-a-zA-Z0-9_.]+').match,
+ name_match=re.compile('[\0- ]*[a-zA-Z]+[\0- ]*').match,
+ end_match=re.compile('[\0- ]*(/\|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:
- s=start_search(text, start)
- if s < 0: return -1
+ mo = start_search(text,start)
+ if mo is None: return -1
+ s = mo.start(0)
if text[s:s+5] == '<!--#':
n=s+5
e=find(text,'-->',n)
if e < 0: return -1
en=3
- l=end_match(text,n)
- if l > 0:
+ mo =end_match(text,n)
+ if mo is not None:
+ l = mo.end(0) - mo.start(0)
end=strip(text[n:n+l])
n=n+l
else: end=''
@@ -150,32 +151,36 @@
if e >= 0:
args=text[n:e]
l=len(args)
- if ent_name(args) == l:
- d=self.__dict__
- if text[s+5]=='-':
- d[1]=d['end']=''
- d[2]=d['name']='var'
- d[0]=text[s:e+1]
- d[3]=d['args']=args+' html_quote'
- return s
- else:
- nn=find(args,'-')
- if nn >= 0 and nn < l-1:
+ mo = ent_name(args)
+ if mo is not None:
+ if mo.end(0)-mo.start(0) == l:
+ d=self.__dict__
+ if text[s+5]=='-':
d[1]=d['end']=''
d[2]=d['name']='var'
d[0]=text[s:e+1]
- args=(args[nn+1:]+' '+
- replace(args[:nn],'.',' '))
- d[3]=d['args']=args
+ d[3]=d['args']=args+' html_quote'
return s
+ else:
+ nn=find(args,'-')
+ 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],'.',' '))
+ d[3]=d['args']=args
+ return s
start=s+1
continue
break
- l=name_match(text,n)
- if l < 0: return l
+ mo = name_match(text,n)
+ if mo is None: return -1
+ l = mo.end(0) - mo.start(0)
+
a=n+l
name=strip(text[n:a])