[Zope-Checkins] SVN: Zope/trunk/lib/python/Products/PageTemplates/ merge -r25111:25112 $ZOPESVN/branches/stub-unicode-zpt

Stuart Bishop zen at shangri-la.dropbear.id.au
Sat Jun 12 10:12:52 EDT 2004


Log message for revision 25396:
merge -r25111:25112 $ZOPESVN/branches/stub-unicode-zpt


-=-
Modified: Zope/trunk/lib/python/Products/PageTemplates/PageTemplate.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/PageTemplate.py	2004-06-12 14:09:57 UTC (rev 25395)
+++ Zope/trunk/lib/python/Products/PageTemplates/PageTemplate.py	2004-06-12 14:12:52 UTC (rev 25396)
@@ -17,7 +17,7 @@
 
 __version__='$Revision: 1.31 $'[11:-2]
 
-import sys
+import sys, types
 
 from TAL.TALParser import TALParser
 from TAL.HTMLTALParser import HTMLTALParser
@@ -57,6 +57,12 @@
             self.content_type = str(content_type)
         if hasattr(text, 'read'):
             text = text.read()
+        charset = getattr(self, 'management_page_charset', None)
+        if charset and type(text) == types.StringType:
+            try:
+                unicode(text,'us-ascii')
+            except UnicodeDecodeError:
+                text = unicode(text, charset)
         self.write(text)
 
     def pt_getContext(self):
@@ -130,7 +136,7 @@
         return None  # Unknown.
 
     def write(self, text):
-        assert type(text) is type('')
+        assert type(text) in types.StringTypes
         if text[:len(self._error_start)] == self._error_start:
             errend = text.find('-->')
             if errend >= 0:

Modified: Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py	2004-06-12 14:09:57 UTC (rev 25395)
+++ Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py	2004-06-12 14:12:52 UTC (rev 25396)
@@ -17,7 +17,7 @@
 
 __version__='$Revision: 1.48 $'[11:-2]
 
-import os, AccessControl, Acquisition, sys
+import os, AccessControl, Acquisition, sys, types
 from types import StringType
 from Globals import DTMLFile, ImageFile, MessageDialog, package_home
 from zLOG import LOG, ERROR, INFO
@@ -134,6 +134,7 @@
         self.pt_setTitle(title)
         self.pt_edit(text, content_type)
         REQUEST.set('text', self.read()) # May not equal 'text'!
+        REQUEST.set('title', self.title)
         message = "Saved changes."
         if getattr(self, '_v_warnings', None):
             message = ("<strong>Warning:</strong> <i>%s</i>"
@@ -141,9 +142,18 @@
         return self.pt_editForm(manage_tabs_message=message)
 
     def pt_setTitle(self, title):
-        self._setPropValue('title', str(title))
+        charset = getattr(self, 'management_page_charset', None)
+        if type(title) == types.StringType and charset:
+            try:
+                title.decode('us-ascii')
+                title = str(title)
+            except UnicodeError:
+                title = unicode(title, charset)
+        elif type(title) != types.UnicodeType:
+            title = str(title)
+        self._setPropValue('title', title)
 
-    def pt_upload(self, REQUEST, file=''):
+    def pt_upload(self, REQUEST, file='', charset=None):
         """Replace the document with the text in file."""
         if SUPPORTS_WEBDAV_LOCKS and self.wl_isLocked():
             raise ResourceLockedError, "File is locked via WebDAV"
@@ -151,7 +161,12 @@
         if type(file) is not StringType:
             if not file: raise ValueError, 'File not specified'
             file = file.read()
-
+        if charset:
+            try:
+                unicode(file, 'us-ascii')
+                file = str(file)
+            except UnicodeDecodeError:
+                file = unicode(file, charset)
         self.write(file)
         message = 'Saved changes.'
         return self.pt_editForm(manage_tabs_message=message)

Modified: Zope/trunk/lib/python/Products/PageTemplates/www/ptEdit.zpt
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/www/ptEdit.zpt	2004-06-12 14:09:57 UTC (rev 25395)
+++ Zope/trunk/lib/python/Products/PageTemplates/www/ptEdit.zpt	2004-06-12 14:12:52 UTC (rev 25396)
@@ -121,6 +121,17 @@
   <input type="file" name="file" size="25" value="">
   </td>
 </tr>
+<tr tal:condition="context/management_page_charset|nothing">
+  <td align="left" valign="top">
+    <div class="form-label">
+      Encoding &nbsp;
+    </div>
+  </td>
+  <td align="left" valign="top">
+    <input name="charset" value=""
+      tal:attributes="value here/management_page_charset|default" />
+  </td>
+</tr>
 <tr>
   <td></td>
   <td align="left" valign="top">




More information about the Zope-Checkins mailing list