[CMF-checkins] CVS: CMF/CMFDefault - Document.py:1.28 utils.py:1.7

Jeffrey P Shell jeffrey@zope.com
Mon, 13 Aug 2001 17:00:19 -0400


Update of /cvs-repository/CMF/CMFDefault
In directory cvs.zope.org:/tmp/cvs-serv1690

Modified Files:
	Document.py utils.py 
Log Message:
Fixed issue with CMFDefault.utils.bodyfinder - it was previously a full regex that could cause a Runtime error - recursion limit exceeded;  Now it is a function that uses regex match objects start() and end() data, rather than trying to swallow up the text between body tags inside the regex itself

=== CMF/CMFDefault/Document.py 1.27 => 1.28 ===
             if parser.title:
                 headers['Title'] = parser.title
-            bodyfound = bodyfinder.search(text)
+            bodyfound = bodyfinder(text)
             if bodyfound:
-                cooked = body = bodyfound.group('bodycontent')
+                cooked = body = bodyfound
         else:
             headers, body = parseHeadersBody(text, headers)
             cooked = _format_stx(text=body, level=level)


=== CMF/CMFDefault/utils.py 1.6 => 1.7 ===
     
 
-bodyfinder = re.compile(r'<body.*?>(?P<bodycontent>.*?)</body>',
-                        re.DOTALL|re.I)
-htfinder = re.compile(r'<html', re.DOTALL|re.I)
+_bodyre = re.compile(r'<body.*?>', re.DOTALL|re.I)
+_endbodyre = re.compile(r'</body', re.DOTALL|re.I)
+
+def bodyfinder(text):
+    bod = _bodyre.search(text)
+    if not bod: return ''
 
+    end = _endbodyre.search(text)
+    if not end: return ''
+    else: return text[bod.end():end.start()]
+
+htfinder = re.compile(r'<html', re.DOTALL|re.I)
 def html_headcheck(html):
     """ Returns 'true' if document looks HTML-ish enough """
     if not htfinder.search(html):
@@ -156,5 +164,5 @@
             continue
         elif lower(line[:5]) == '<html':
             return 1
-        elif line[:2] not in ('<!', '<?'):
+        elif line[0] != '<':
             return 0