[Zope-Checkins] CVS: Zope2 - ts_regex.py:1.7.158.3 ts_regex_new.py:1.1.2.2

andreas@serenade.digicool.com andreas@serenade.digicool.com
Tue, 17 Apr 2001 15:12:02 -0400


Update of /cvs-repository/Zope2/lib/python
In directory serenade.digicool.com:/tmp/cvs-serv26305

Modified Files:
      Tag: ajung-2_4-ts_regex-exterminiation-branch
	ts_regex.py ts_regex_new.py 
Log Message:
update



--- Updated File ts_regex.py in package Zope2 --
--- ts_regex.py	2001/04/17 14:39:05	1.7.158.2
+++ ts_regex.py	2001/04/17 19:12:02	1.7.158.3
@@ -87,49 +87,70 @@
 """
 
 import re,reconvert
-_rcCV = reconvert.convert
+import sys
 
+import ts_regex_old as OLD
+import ts_regex_new as NEW
 
-def sub(pat,repl,str):
-    return re.sub(_rcCV(pat) , repl , str, count=1)
 
+def _rcCV(s):
 
-def gsub(pat,repl,str):
-    return re.sub(_rcCV(pat) , repl , str )
+    cs = reconvert.convert(s)
+    if cs != s:
+        print 'Warning: "%s" must be converted to "%s"' % (s,cs)
 
+    return cs
 
 
-def split(str,pat,maxsplit=0):
-    return re.split(_rcCV(pat) , str , maxsplit)
+def sub(pat,repl,str):
+    x = OLD.sub(pat,repl,str)
+    y = NEW.sub(pat,repl,str)
+    if x!=y: print 'Warning: sub():',pat,repl,str
+    return x
 
+def gsub(pat,repl,str):
+    x = OLD.gsub(pat,repl,str)
+    y = NEW.gsub(pat,repl,str)
+    if x!=y: print 'Warning: subg():',pat,repl,str
+    return x
 
-def splitx(str,pat,maxsplit=0):
-    return re.split('(' + _rcCV(pat) + ')' , str , maxsplit)
 
+def split(str,pat,maxsplit=0):
+    x = OLD.split(str,pat,maxsplit)
+    y = NEW.split(str,pat,maxsplit)
+    if x!=y: print 'Warning: split():',str,pat,maxsplit
+    return x
 
 
+def splitx(str,pat,maxsplit=0):
+    x = OLD.splitx(str,pat,maxsplit)
+    y = NEW.splitx(str,pat,maxsplit)
+    if x!=y: print 'Warning: splitx():',str,pat,maxsplit
+    return x
+    
+
 
 class compile:
 
     def __init__(self, *args):
+        print>>sys.stderr, args
+        self._old = apply(OLD.compile,args)
+        self._new = apply(NEW.compile,args)
 
-        if len(args)==1:
-            self._re = re.compile(_rcCV(args[0]))
-        else: 
-            self._re = re.compile(_rcCV(args[0]), args[1:])
-        
 
     def match(self, string, pos=0):
-        mo = self._re.match(string, pos)
-        if mo==None: return -1
-        else:        return mo.end(0) 
+        x = self._old.match(string,pos)
+        y = self._new.match(string,pos)
+        if x!=y: print 'Warning: match():',string,pos
+        return x
 
 
     def search(self, string, pos=0):
-        mo = self._re.search(string, pos)
-        if mo==None: return -1
-        else:        return mo.start(0) 
-        
+        x = self._old.search(string,pos)
+        y = self._new.search(string,pos)
+        if x!=y: print 'Warning: search():',string,pos
+        return x
+ 
     def search_group(self, str, group, pos=0):
         """Search a string for a pattern.
 
@@ -137,15 +158,11 @@
         otherwise, the location where the pattern was found,
         as well as any specified group are returned.
         """
-        mo = self._re.search(str, pos)
-        if mo==None : return None
-        l=[]
-        for g in group:
-            try: l.append(mo.group(g))
-            except: l.append(None)      
- 
-        if len(l) >1: return mo.end(0), tuple(l)
-        else: return mo.end(0), l[0]
+        x = self._old.search_group(str,group,pos)
+        y = self._new.search_group(str,group,pos)
+        if x!=y: print 'Warning: seach_group(%s,%s,%s) %s vs %s' % (str,group,pos,x,y)
+        return x
+
 
     def match_group(self, str, group, pos=0):
         """Match a pattern against a string
@@ -154,76 +171,50 @@
         returned, otherwise, the length of the match, as well
         as any specified group are returned.
         """
+        x = self._old.match_group(str,group,pos)
+        y = self._new.match_group(str,group,pos)
+        if x!=y: print 'Warning: match_group(%s,%s,%s) %s vs %s' % (str,group,pos,x,y)
+        return x
 
-        mo = self._re.search(str, pos)
-        if mo==None : return None
-        l=[]
-        for g in group:
-            try: l.append(mo.group(g))
-            except: l.append(None)      
-
-        if len(l) >1: return mo.end(0), tuple(l)
-        else: return mo.end(0), l[0]
-
       
 
-
 if __name__=='__main__':
 
-    import sys,ts_regex_old as TRO
+    import sys
 
     s1 = 'The quick brown fox jumps of The lazy dog'
     s2 = '892 The quick brown 123 fox jumps over  3454 21 The lazy dog'
 
     r1 = ' [a-zA-Z][a-zA-Z] '
     r2 = '[0-9][0-9]'
-
     print 'new:',split(s1,' ')
-    print 'old:',TRO.split(s1,' ')
-
     print 'new:',splitx(s2,' ')
-    print 'old:',TRO.splitx(s2,' ')
-
     print 'new:',split(s2,' ',2)
-    print 'old:',TRO.split(s2,' ',2)
-
     print 'new:',splitx(s2,' ',2)
-    print 'old:',TRO.splitx(s2,' ',2)
-
-
     print 'new:',sub('The','###',s1)
-    print 'old:',TRO.sub('The','###',s1)
-
     print 'new:',gsub('The','###',s1)
-    print 'old:',TRO.gsub('The','###',s1)
 
+    p1 = compile(r1)
+    p2 = compile(r2)
 
-
     for s in [s1,s2]:
+
+
+      print 'search' 
 
-        for r in [r1,r2]:
+      print 'new:',p1.search(s)
+      print 'new:',p2.search(s)
 
-            pat1 = compile(r)
-            pat2 = TRO.compile(r)
-          
-            print '-'*78
-            print '"%s" "%s"' % (s,r)
-
-            print 'search' 
-            print 'new:',pat1.search(s)
-            print 'old:',pat2.search(s)
-
-        
-            print 'match' 
-            print 'new:',pat1.match(s)
-            print 'old:',pat2.match(s)
+      print 'match' 
+      print 'new:',p1.match(s)
+      print 'new:',p2.match(s)
  
 
-            print 'match_group'
-            print 'new:',pat1.match_group(s,(0,))
-            print 'old:',pat2.match_group(s,(0,))
+      print 'match_group'
+      print 'new:',p1.match_group(s,(0,))
+      print 'new:',p2.match_group(s,(0,))
 
 
-            print 'search_group'
-            print 'new:',pat1.match_group(s,(0,1))
-            print 'old:',pat2.match_group(s,(0,1))
+      print 'search_group'
+      print 'new:',p1.match_group(s,(0,1))
+      print 'new:',p2.match_group(s,(0,1))

--- Updated File ts_regex_new.py in package Zope2 --
--- ts_regex_new.py	2001/04/17 17:46:56	1.1.2.1
+++ ts_regex_new.py	2001/04/17 19:12:02	1.1.2.2
@@ -155,7 +155,7 @@
         as any specified group are returned.
         """
 
-        mo = self._re.search(str, pos)
+        mo = self._re.match(str, pos)
         if mo==None : return None
         l=[]
         for g in group:
@@ -224,6 +224,16 @@
             print 'old:',pat2.match_group(s,(0,))
 
 
-            print 'search_group'
+            print 'match_group'
             print 'new:',pat1.match_group(s,(0,1))
             print 'old:',pat2.match_group(s,(0,1))
+
+            print 'search_group'
+            print 'new:',pat1.search_group(s,(0,))
+            print 'old:',pat2.search_group(s,(0,))
+
+
+            print 'search_group'
+            print 'new:',pat1.search_group(s,(0,1))
+            print 'old:',pat2.search_group(s,(0,1))
+