Commit 150adf04 authored by Stuart Bishop's avatar Stuart Bishop

merge -r25111:25112 $ZOPESVN/branches/stub-unicode-zpt

parent 3f36c64e
......@@ -17,7 +17,7 @@ HTML- and XML-based template objects using TAL, TALES, and METAL.
__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 @@ class PageTemplate(Base):
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 @@ class PageTemplate(Base):
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:
......
......@@ -17,7 +17,7 @@ Zope object encapsulating a Page Template.
__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 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
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 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
return self.pt_editForm(manage_tabs_message=message)
def pt_setTitle(self, title):
self._setPropValue('title', str(title))
def pt_upload(self, REQUEST, file=''):
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='', 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 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
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)
......
......@@ -121,6 +121,17 @@ to view or download the current text.
<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">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment