[Zope-Checkins] CVS: Zope2 - HTTPRequest.py:1.49

Andreas Jung andreas@dhcp165.digicool.com
Tue, 24 Apr 2001 18:46:51 -0400


Update of /cvs-repository/Zope2/lib/python/ZPublisher
In directory yetix:/work/sandboxes/Zope2/lib/python/ZPublisher

Modified Files:
	HTTPRequest.py 
Log Message:
regex free



--- Updated File HTTPRequest.py in package Zope2 --
--- HTTPRequest.py	2001/03/27 19:52:41	1.48
+++ HTTPRequest.py	2001/04/24 22:46:50	1.49
@@ -85,7 +85,7 @@
 
 __version__='$Revision$'[11:-2]
 
-import regex, re, sys, os, string, urllib, time, whrandom
+import  re, sys, os, string, urllib, time, whrandom
 from string import lower, atoi, rfind, split, strip, join, upper, find
 from BaseRequest import BaseRequest
 from HTTPResponse import HTTPResponse
@@ -383,7 +383,7 @@
         hasattr=hasattr,
         getattr=getattr,
         setattr=setattr,
-        search_type=regex.compile('\(:[a-zA-Z][a-zA-Z0-9_]+\|\.[xy]\)$').search,
+        search_type=re.compile('(:[a-zA-Z]\w+|\.[xy])$').search,
         rfind=string.rfind,
         ):
         """Process request inputs
@@ -448,11 +448,14 @@
                 # We'll search from the back to the front.
                 # We'll do the search in two steps.  First, we'll
                 # do a string search, and then we'll check it with
-                # a regex search.
+                # a re search.
                 
                 l=rfind(key,':')
                 if l >= 0:
-                    l=search_type(key,l)
+                    mo=search_type(key,l)
+                    if mo:   l = mo.start(0)
+                    else:    l = -1
+
                     while l >= 0:
                         type_name=key[l+1:]
                         key=key[:l]
@@ -486,7 +489,9 @@
     
                         l=rfind(key,':')
                         if l < 0: break
-                        l=search_type(key,l)
+                        mo = search_type(key,l)
+                        if mo: l = mo.start(0)
+                        else:  l = -1
              
                 # Filter out special names from form:
                 if CGI_name(key) or key[:5]=='HTTP_': continue
@@ -1050,16 +1055,10 @@
 parse_cookie_lock=allocate_lock()
 def parse_cookie(text,
                  result=None,
-                 qparmre=regex.compile(
-                     '\([\0- ]*'
-                     '\([^\0- ;,=\"]+\)="\([^"]*\)\"'
-                     '\([\0- ]*[;,]\)?[\0- ]*\)'
-                     ),
-                 parmre=regex.compile(
-                     '\([\0- ]*'
-                     '\([^\0- ;,=\"]+\)=\([^\0- ;,\"]*\)'
-                     '\([\0- ]*[;,]\)?[\0- ]*\)'
-                     ),
+                 qparmre=re.compile(
+                    '([\x00- ]*([^\x00- ;,="]+)="([^"]*)"([\x00- ]*[;,])?[\x00- ]*)'),
+                 parmre=re.compile(
+                    '([\x00- ]*([^\x00- ;,="]+)=([^\x00- ;,"]*)([\x00- ]*[;,])?[\x00- ]*)'),
                  acquire=parse_cookie_lock.acquire,
                  release=parse_cookie_lock.release,
                  ):
@@ -1069,16 +1068,20 @@
 
     acquire()
     try:
-        if qparmre.match(text) >= 0:
+
+        mo_q = qparmre.match(text)
+        mo_p = parmre.match(text)
+
+        if mo_q:
             # Match quoted correct cookies
-            name=qparmre.group(2)
-            value=qparmre.group(3)
-            l=len(qparmre.group(1))
-        elif parmre.match(text) >= 0:
+            name  = mo_q.group(2)
+            value = mo_q.group(3)
+            l     = len(mo_q.group(1))
+        elif mo_p:
             # Match evil MSIE cookies ;)
-            name=parmre.group(2)
-            value=parmre.group(3)
-            l=len(parmre.group(1))
+            name  = mo_p.group(2)
+            value = mo_p.group(3)
+            l     = len(mo_p.group(1))
         else:
             # this may be an invalid cookie.
             # We'll simply bail without raising an error