[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/zptpage/ Made UTF-8 the encoding that is assumed for FTP and other filesystem

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Jul 8 18:29:04 EDT 2004


Log message for revision 26250:
Made UTF-8 the encoding that is assumed for FTP and other filesystem 
sync, if we do not have encoding information.



-=-
Modified: Zope3/trunk/src/zope/app/zptpage/fssync/adapter.py
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/fssync/adapter.py	2004-07-08 22:27:36 UTC (rev 26249)
+++ Zope3/trunk/src/zope/app/zptpage/fssync/adapter.py	2004-07-08 22:29:04 UTC (rev 26250)
@@ -15,7 +15,6 @@
 
 $Id$
 """
-
 from zope.interface import implements
 from zope.fssync.server.entryadapter import ObjectEntryAdapter
 from zope.fssync.server.interfaces import IObjectFile
@@ -31,5 +30,7 @@
     def setBody(self, data):
         # Convert the data to Unicode, since that's what ZPTPage wants;
         # it's normally read from a file so it'll be bytes.
-        # XXX This will die if it's not ASCII.  Guess encoding???
-        self.context.setSource(unicode(data))
+
+        # Sometimes we cannot communicate an encoding. Zope's default is UTF-8,
+        # so use it.
+        self.context.setSource(data.decode('UTF-8'))

Modified: Zope3/trunk/src/zope/app/zptpage/zptpage.py
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/zptpage.py	2004-07-08 22:27:36 UTC (rev 26249)
+++ Zope3/trunk/src/zope/app/zptpage/zptpage.py	2004-07-08 22:29:04 UTC (rev 26250)
@@ -11,10 +11,10 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""
+"""ZPT Page (content object) implementation
+
 $Id$
 """
-
 from persistent import Persistent
 
 from zope.proxy import removeAllProxies
@@ -139,8 +139,9 @@
         self.context = context
 
     def write(self, data):
-        # XXX Hm, how does one figure out an ftp encoding. Waaa.
-        self.context.setSource(unicode(data), None)
+        # We cannot communicate an encoding via FTP. Zope's default is UTF-8,
+        # so use it.
+        self.context.setSource(data.decode('UTF-8'), None)
 
 class ZPTFactory:
 
@@ -151,10 +152,11 @@
         self.context = context
 
     def __call__(self, name, content_type, data):
-        r = ZPTPage()
-        # XXX Hm, how does one figure out an ftp encoding. Waaa.
-        r.setSource(unicode(data), content_type or 'text/html')
-        return r
+        page = ZPTPage()
+        # We cannot communicate an encoding via FTP. Zope's default is UTF-8,
+        # so use it.
+        page.setSource(data.decode('UTF-8'), content_type or 'text/html')
+        return page
 
 class ZPTSourceView:
 



More information about the Zope3-Checkins mailing list