[Zope-Checkins] CVS: Zope2 - ts_regex.py:1.7.158.2

andreas@serenade.digicool.com andreas@serenade.digicool.com
Tue, 17 Apr 2001 10:39:06 -0400


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

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



--- Updated File ts_regex.py in package Zope2 --
--- ts_regex.py	2001/04/17 14:14:24	1.7.158.1
+++ ts_regex.py	2001/04/17 14:39:05	1.7.158.2
@@ -139,8 +139,13 @@
         """
         mo = self._re.search(str, pos)
         if mo==None : return None
-        print 'groups:',mo.groups()
-        return mo.start(0), apply(mo.group,group)
+        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]
 
     def match_group(self, str, group, pos=0):
         """Match a pattern against a string
@@ -152,10 +157,14 @@
 
         mo = self._re.search(str, pos)
         if mo==None : return None
-        print 'groups:',mo.groups()
-        return 0
-#        return mo.end(0), apply(mo.group,group)
+        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]
+
       
 
 
@@ -188,7 +197,6 @@
     print 'new:',gsub('The','###',s1)
     print 'old:',TRO.gsub('The','###',s1)
 
-    sys.exit(1)
 
 
     for s in [s1,s2]:
@@ -199,16 +207,16 @@
             pat2 = TRO.compile(r)
           
             print '-'*78
-            print s,r
+            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 '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_group'