[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/ZPTPage - ZPTPage.py:1.16

Fred L. Drake, Jr. fred@zope.com
Thu, 5 Dec 2002 12:37:32 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/ZPTPage
In directory cvs.zope.org:/tmp/cvs-serv16326

Modified Files:
	ZPTPage.py 
Log Message:
setSource() now requires the source text to be Unicode.  This takes
care of the encoding issue previously noted in SearchableText
comments.


=== Zope3/lib/python/Zope/App/OFS/Content/ZPTPage/ZPTPage.py 1.15 => 1.16 ===
--- Zope3/lib/python/Zope/App/OFS/Content/ZPTPage/ZPTPage.py:1.15	Thu Dec  5 10:52:44 2002
+++ Zope3/lib/python/Zope/App/OFS/Content/ZPTPage/ZPTPage.py	Thu Dec  5 12:37:31 2002
@@ -36,7 +36,10 @@
     """
 
     def setSource(text, content_type='text/html'):
-        """Save the source of the page template."""
+        """Save the source of the page template.
+
+        'text' must be Unicode.
+        """
 
     def getSource():
         """Get the source of the page template."""
@@ -72,10 +75,10 @@
 
     def setSource(self, text, content_type='text/html'):
         '''See interface Zope.App.OFS.ZPTPage.ZPTPage.IZPTPage'''
-        if isinstance(text, unicode):
-            text = text.encode('utf-8')
+        if not isinstance(text, unicode):
+            raise TypeError("source text must be Unicode")
 
-        self.pt_edit(text, content_type)
+        self.pt_edit(text.encode('utf-8'), content_type)
 
     def pt_getContext(self, instance, request, **_kw):
         # instance is a View component
@@ -85,7 +88,6 @@
         return namespace
 
     def render(self, request, *args, **keywords):
-
         instance = getWrapperContainer(self)
 
         request = ProxyFactory(request)
@@ -116,11 +118,11 @@
         self.page = page
 
     def getSearchableText(self):
-        try:
-            # XXX check about encoding here and in the ZPTPage.read
-            #     the exception should go away when we know how this
-            #     works in terms of conversion, for now on problems
-            #     don't index the object
-            return [unicode(self.page.source)]
-        except:
-            return None
+        text = self.page.getSource()
+        if isinstance(text, str):
+            text = unicode(self.page.source, 'utf-8')
+        # else:
+        #   text was already Unicode, which happens, but unclear how it
+        #   gets converted to Unicode since the ZPTPage stores UTF-8 as
+        #   an 8-bit string.
+        return [text]