[CMF-checkins] CVS: CMF/CMFDefault - Document.py:1.52.10.3 utils.py:1.16.4.1
Yvo Schubbe
schubbe@web.de
Sun, 2 Feb 2003 17:09:59 -0500
Update of /cvs-repository/CMF/CMFDefault
In directory cvs.zope.org:/tmp/cvs-serv16420/CMFDefault
Modified Files:
Tag: yuppie-collector041-branch
Document.py utils.py
Log Message:
second step:
- cleaned up code
- added some tests
=== CMF/CMFDefault/Document.py 1.52.10.2 => 1.52.10.3 ===
--- CMF/CMFDefault/Document.py:1.52.10.2 Sun Feb 2 10:47:41 2003
+++ CMF/CMFDefault/Document.py Sun Feb 2 17:09:27 2003
@@ -16,7 +16,6 @@
$Id$
"""
-import Globals, StructuredText, string, utils, re
from StructuredText.HTMLWithImages import HTMLWithImages
from Globals import DTMLFile, InitializeClass
from AccessControl import ClassSecurityInfo, getSecurityManager
@@ -30,6 +29,7 @@
from DublinCore import DefaultDublinCoreImpl
from utils import parseHeadersBody, formatRFC822Headers
from utils import SimpleHTMLParser, bodyfinder, _dtmldir
+from utils import html_headcheck
from DocumentTemplate.DT_Util import html_quote
factory_type_information = ( { 'id' : 'Document'
@@ -168,7 +168,7 @@
if contents:
text = self.text = contents
text = bodyfinder(text)
- self.setFormat(value=text_format)
+ self.setFormat(text_format)
self._edit(text=text, text_format=text_format, safety_belt=safety_belt)
self.reindexObject()
@@ -195,14 +195,13 @@
security.declarePrivate('guessFormat')
def guessFormat(self, text):
""" Simple stab at guessing the inner format of the text """
- if utils.html_headcheck(text): return 'html'
+ if html_headcheck(text): return 'html'
else: return 'structured-text'
security.declarePrivate('handleText')
def handleText(self, text, format=None, stx_level=None):
- """ Handles the raw text, returning headers, body, cooked, format """
+ """ Handles the raw text, returning headers, body, format """
headers = {}
- level = stx_level or self._stx_level
if not format:
format = self.guessFormat(text)
if format == 'html':
@@ -214,10 +213,10 @@
body = bodyfinder(text)
else:
headers, body = parseHeadersBody(text, headers)
- self._stx_level = level
-
+ if stx_level:
+ self._stx_level = stx_level
return headers, body, format
-
+
security.declarePublic( 'getMetadataHeaders' )
def getMetadataHeaders(self):
"""Return RFC-822-style header spec."""
@@ -326,8 +325,8 @@
security.declareProtected(ModifyPortalContent, 'setFormat')
- def setFormat(self, value):
- value = str(value)
+ def setFormat(self, format):
+ value = str(format)
if value == 'text/html' or value == 'html':
self.text_format = 'html'
elif value == 'plain':
@@ -353,7 +352,7 @@
text_format = 'html'
else:
text_format = format
- self.setFormat(value=text_format)
+ self.setFormat(text_format)
self.setMetadata(headers)
self._edit(text=body, safety_belt=safety_belt)
except 'EditingConflict', msg:
@@ -384,13 +383,11 @@
security.declareProtected(View, 'manage_FTPget')
def manage_FTPget(self):
"Get the document body for FTP download (also used for the WebDAV SRC)"
- join = string.join
- lower = string.lower
hdrlist = self.getMetadataHeaders()
if self.Format() == 'text/html':
hdrtext = ''
for name, content in hdrlist:
- if lower(name) == 'title':
+ if name.lower() == 'title':
continue
else:
hdrtext = '%s\n <meta name="%s" content="%s" />' % (
=== CMF/CMFDefault/utils.py 1.16 => 1.16.4.1 ===
--- CMF/CMFDefault/utils.py:1.16 Thu Dec 19 00:34:55 2002
+++ CMF/CMFDefault/utils.py Sun Feb 2 17:09:27 2003
@@ -1,6 +1,21 @@
+##############################################################################
+#
+# Copyright (c) 2001-2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
+""" Utility functions.
+
+$Id$
"""
- Utility functions.
-"""
+
from sgmllib import SGMLParser
import re
import os
@@ -378,15 +393,12 @@
else:
return text[bod.end():end.start()]
-security.declarePrivate('_htfinder')
-_htfinder = re.compile( r'<html', re.DOTALL | re.I )
-
security.declarePublic('html_headcheck')
def html_headcheck( html ):
-
""" Return 'true' if document looks HTML-ish enough.
"""
- if not _htfinder.search(html):
+ lowerhtml = html.lower()
+ if lowerhtml.find('<html') == -1:
return 0
lines = re.split(r'[\n\r]+?', html)