Commit 9e1a6f45 authored by Andreas Jung's avatar Andreas Jung

a less restrictive implementation whose default behaviour

is the same as in all current Zope 2 implementation. Restrictive 
unicode usage can be enforced by setting strict=True. 
The code needs some more work concerning the encoding handling.
parent 0c594874
...@@ -90,7 +90,7 @@ def guess_type(filename, text): ...@@ -90,7 +90,7 @@ def guess_type(filename, text):
_default_content_fn = os.path.join(package_home(globals()), 'pt', 'default.html') _default_content_fn = os.path.join(package_home(globals()), 'pt', 'default.html')
class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
Traversable, PropertyManager): Traversable, PropertyManager):
...@@ -124,9 +124,10 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -124,9 +124,10 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
security.declareObjectProtected(view) security.declareObjectProtected(view)
security.declareProtected(view, '__call__') security.declareProtected(view, '__call__')
def __init__(self, id, text=None, content_type=None, encoding='utf-8'): def __init__(self, id, text=None, content_type=None, encoding='utf-8', strict=False):
self.id = id self.id = id
self.expand = 0 self.expand = 0
self.strict = strict
self.ZBindings_edit(self._default_bindings) self.ZBindings_edit(self._default_bindings)
self.pt_edit(text, content_type, encoding) self.pt_edit(text, content_type, encoding)
...@@ -134,7 +135,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -134,7 +135,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
def pt_edit(self, text, content_type, encoding='utf-8'): def pt_edit(self, text, content_type, encoding='utf-8'):
text = text.strip() text = text.strip()
if not isinstance(text, unicode): if self.strict and not isinstance(text, unicode):
text = unicode(text, encoding) text = unicode(text, encoding)
self.ZCacheable_invalidate() self.ZCacheable_invalidate()
...@@ -162,7 +163,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -162,7 +163,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
security.declareProtected(change_page_templates, 'pt_setTitle') security.declareProtected(change_page_templates, 'pt_setTitle')
def pt_setTitle(self, title, encoding='utf-8'): def pt_setTitle(self, title, encoding='utf-8'):
if not isinstance(title, unicode): if self.strict and not isinstance(title, unicode):
title = unicode(title, encoding) title = unicode(title, encoding)
self._setPropValue('title', title) self._setPropValue('title', title)
...@@ -368,6 +369,13 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -368,6 +369,13 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
def wl_isLocked(self): def wl_isLocked(self):
return 0 return 0
security.declareProtected(view, 'strictUnicode')
def strictUnicode(self):
""" Return True if the ZPT enforces the use of unicode,
False otherwise.
"""
return self.strict
def manage_convertUnicode(self, preferred_encodings=preferred_encodings, RESPONSE=None): def manage_convertUnicode(self, preferred_encodings=preferred_encodings, RESPONSE=None):
""" convert non-unicode templates to unicode """ """ convert non-unicode templates to unicode """
...@@ -430,7 +438,7 @@ ZopePageTemplate.manage = ZopePageTemplate.pt_editForm ...@@ -430,7 +438,7 @@ ZopePageTemplate.manage = ZopePageTemplate.pt_editForm
manage_addPageTemplateForm= FSZPT('manage_addPageTemplateForm', os.path.join(package_home(globals()), 'pt', 'ptAdd.pt')) manage_addPageTemplateForm= FSZPT('manage_addPageTemplateForm', os.path.join(package_home(globals()), 'pt', 'ptAdd.pt'))
def manage_addPageTemplate(self, id, title='', text=None, encoding='utf-8', submit=None, REQUEST=None, RESPONSE=None): def manage_addPageTemplate(self, id, title='', text='', encoding='utf-8', submit=None, REQUEST=None, RESPONSE=None):
"Add a Page Template with optional file content." "Add a Page Template with optional file content."
filename = '' filename = ''
......
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