[Zope-Checkins] CVS: Zope2 - HTTPServer.py:1.30.12.1

Andreas Jung andreas@dhcp165.digicool.com
Tue, 24 Apr 2001 08:30:58 -0400


Update of /cvs-repository/Zope2/ZServer
In directory yetix:/work/sandboxes/ajung-2_4-new-medusa/ZServer

Modified Files:
      Tag: ajung-2_4-new-medusa
	HTTPServer.py 
Log Message:
regex free, removed a minor Medusa dependancy for better migration
to new Medusa code



--- Updated File HTTPServer.py in package Zope2 --
--- HTTPServer.py	2001/04/05 23:49:13	1.30
+++ HTTPServer.py	2001/04/24 12:29:42	1.30.12.1
@@ -104,7 +104,7 @@
     
 """ 
 import sys
-import regex
+import re
 import string
 import os
 import types
@@ -120,7 +120,7 @@
 from medusa.http_server import http_server, http_channel, VERSION_STRING
 import asyncore
 from medusa import counter, producers, max_sockets
-from medusa.default_handler import split_path, unquote, get_header
+from medusa.default_handler import split_path, unquote
 from asyncore import compact_traceback, dispatcher
 
 from ZServer import CONNECTION_LIMIT, ZOPE_VERSION, ZSERVER_VERSION
@@ -131,8 +131,8 @@
 
 register_subsystem('ZServer HTTPServer')
 
-CONTENT_LENGTH = regex.compile('Content-Length: \([0-9]+\)',regex.casefold)
-CONNECTION = regex.compile ('Connection: \(.*\)', regex.casefold)
+CONTENT_LENGTH = re.compile('Content-Length: ([0-9]+)',re.I)
+CONNECTION     = re.compile('Connection: (.*)', re.I)
 
 # maps request some headers to environment variables.
 # (those that don't start with 'HTTP_')
@@ -141,6 +141,15 @@
             'connection'        : 'CONNECTION_TYPE',
             }
 
+
+# Code stolen from Medusa
+
+def get_header (head_reg, lines, group=1):
+    for line in lines:
+        if head_reg.match (line):
+            return head_reg.group(group)
+    return ''
+
 class zhttp_collector:
     def __init__(self, handler, request, size):
         self.handler = handler
@@ -201,14 +210,16 @@
               uri_base=uri_base[:-1]
         self.uri_base=uri_base
         uri_regex='%s.*' % self.uri_base
-        self.uri_regex = regex.compile(uri_regex)
+        self.uri_regex = re.compile(uri_regex)
 
     def match(self, request):
         uri = request.uri
-        if self.uri_regex.match(uri) == len(uri):
-            return 1
-        else:
-            return 0
+
+        mo = self.uri_regex.match(uri)
+        if mo:
+            if mo.end(0) == len(uri): 
+                return 1
+        return 0
 
     def handle_request(self,request):
         self.hits.increment()