Commit 375e6b69 authored by Andreas Jung's avatar Andreas Jung

pt_edit() now has an optional 'keep_output_encoding' flag that is

necessary for pt_edit() calls where the encoding should not be changed
by sniffing inside the content (used by pt_editAction(), ZMI and by
the constructor)
parent 3baa6989
...@@ -122,17 +122,16 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -122,17 +122,16 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
self.id = id self.id = id
self.expand = 0 self.expand = 0
self.ZBindings_edit(self._default_bindings) self.ZBindings_edit(self._default_bindings)
self.output_encoding = encoding self.output_encoding = 'utf-8'
# default content # default content
if not text: if not text:
text = open(self._default_content_fn).read() text = open(self._default_content_fn).read()
encoding = 'utf-8'
content_type = 'text/html' content_type = 'text/html'
self.pt_edit(text, content_type) self.pt_edit(text, content_type, True)
security.declareProtected(change_page_templates, 'pt_edit') security.declareProtected(change_page_templates, 'pt_edit')
def pt_edit(self, text, content_type): def pt_edit(self, text, content_type, keep_output_encoding=False):
text = text.strip() text = text.strip()
...@@ -142,11 +141,14 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -142,11 +141,14 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
(guessed_content_type, content_type)) (guessed_content_type, content_type))
encoding = sniffEncoding(text) encoding = sniffEncoding(text)
if not keep_output_encoding:
if content_type == 'text/xml': if content_type == 'text/xml':
self.output_encoding = 'utf-8' self.output_encoding = 'utf-8'
else: else:
self.output_encoding = encoding self.output_encoding = encoding
encoding = self.output_encoding
if not isinstance(text, unicode): if not isinstance(text, unicode):
text = unicode(text, encoding) text = unicode(text, encoding)
...@@ -161,16 +163,16 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -161,16 +163,16 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
source_dot_xml = Src() source_dot_xml = Src()
security.declareProtected(change_page_templates, 'pt_editAction') security.declareProtected(change_page_templates, 'pt_editAction')
def pt_editAction(self, REQUEST, title, text, content_type, encoding, expand): def pt_editAction(self, REQUEST, title, text, content_type, expand):
"""Change the title and document.""" """Change the title and document."""
if self.wl_isLocked(): if self.wl_isLocked():
raise ResourceLockedError("File is locked via WebDAV") raise ResourceLockedError("File is locked via WebDAV")
self.expand = expand self.expand = expand
self.pt_setTitle(title, encoding) self.pt_setTitle(title, self.output_encoding)
self.pt_edit(text, content_type, encoding) self.pt_edit(text, content_type, True)
REQUEST.set('text', self.read()) # May not equal 'text'! REQUEST.set('text', self.read()) # May not equal 'text'!
REQUEST.set('title', self.title) REQUEST.set('title', self.title)
message = "Saved changes." message = "Saved changes."
......
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