[Zope-Checkins] CVS: Zope2 - DT_Util.py:1.72.16.1

Andreas Jung andreas@dhcp165.digicool.com
Thu, 19 Apr 2001 14:37:10 -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_Util.py 
Log Message:
regex free



--- Updated File DT_Util.py in package Zope2 --
--- DT_Util.py	2001/01/22 16:36:16	1.72
+++ DT_Util.py	2001/04/19 18:35:54	1.72.16.1
@@ -85,7 +85,8 @@
 '''$Id$''' 
 __version__='$Revision$'[11:-2]
 
-import regex, string, math, os
+import  string, math, os
+import re
 from string import strip, join, atoi, lower, split, find
 import VSEval
 
@@ -449,14 +450,14 @@
 def parse_params(text,
                  result=None,
                  tag='',
-                 unparmre=regex.compile(
-                     '\([\0- ]*\([^\0- =\"]+\)\)'),
-                 qunparmre=regex.compile(
-                     '\([\0- ]*\("[^"]*"\)\)'),
-                 parmre=regex.compile(
-                     '\([\0- ]*\([^\0- =\"]+\)=\([^\0- =\"]+\)\)'),
-                 qparmre=regex.compile(
-                     '\([\0- ]*\([^\0- =\"]+\)="\([^"]*\)\"\)'),
+                 unparmre=re.compile(
+                     '([\0- ]*([^\0- =\"]+))'),
+                 qunparmre=re.compile(
+                     '([\0- ]*("[^"]*"))'),
+                 parmre=re.compile(
+                     '([\0- ]*([^\0- =\"]+)=([^\0- =\"]+))'),
+                 qparmre=re.compile(
+                     '([\0- ]*([^\0- =\"]+)="([^"]*)\")'),
                  **parms):
 
     """Parse tag parameters
@@ -482,17 +483,25 @@
 
     result=result or {}
 
-    if parmre.match(text) >= 0:
-        name=lower(parmre.group(2))
-        value=parmre.group(3)
-        l=len(parmre.group(1))
-    elif qparmre.match(text) >= 0:
-        name=lower(qparmre.group(2))
-        value=qparmre.group(3)
-        l=len(qparmre.group(1))
-    elif unparmre.match(text) >= 0:
-        name=unparmre.group(2)
-        l=len(unparmre.group(1))
+    # HACK - we precalculate all matches. Maybe we don't need them 
+    # all. This should be fixed for performance issues
+
+    mo_p = parmre.match(text)
+    mo_q = qparmre.match(text)
+    mo_unp = unparmre.match(text)
+    mo_unq = qunparmre.match(text)
+
+    if mo_p:
+        name=lower(mo_p.group(2))
+        value=mo_p.group(3)
+        l=len(mo_p.group(1))
+    elif mo_q:
+        name=lower(mo_q.group(2))
+        value=mo_q.group(3)
+        l=len(mo_q.group(1))
+    elif mo_unp:
+        name=mo_unp.group(2)
+        l=len(mo_unp.group(1))
         if result:
             if parms.has_key(name):
                 if parms[name] is None: raise ParseError, (
@@ -504,9 +513,9 @@
         else:
             result['']=name
         return apply(parse_params,(text[l:],result),parms)
-    elif qunparmre.match(text) >= 0:
-        name=qunparmre.group(2)
-        l=len(qunparmre.group(1))
+    elif mo_unq:
+        name=mo_unq.group(2)
+        l=len(mo_unq.group(1))
         if result: raise ParseError, (
             'Invalid attribute name, "%s"' % name, tag)
         else: result['']=name