Commit a281c8bb authored by Andreas Jung's avatar Andreas Jung

removed content-type restrictions (text/html, text/xml only)

parent 0d930600
...@@ -126,7 +126,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -126,7 +126,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
encoding = None encoding = None
output_encoding = None output_encoding = None
if content_type == 'text/xml': if content_type in ('text/xml',):
if is_unicode: if is_unicode:
encoding = None encoding = None
...@@ -136,7 +136,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -136,7 +136,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
output_encoding = 'utf-8' output_encoding = 'utf-8'
elif content_type == 'text/html': elif content_type in ('text/html',) :
charset = charsetFromMetaEquiv(text) charset = charsetFromMetaEquiv(text)
...@@ -156,7 +156,10 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -156,7 +156,10 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
output_encoding = 'iso-8859-15' output_encoding = 'iso-8859-15'
else: else:
raise ValueError('Unsupported content-type %s' % content_type) utext, encoding = convertToUnicode(text,
content_type,
preferred_encodings)
output_encoding = encoding
# for content updated through WebDAV, FTP # for content updated through WebDAV, FTP
if not keep_output_encoding: if not keep_output_encoding:
...@@ -228,8 +231,8 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -228,8 +231,8 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
text = file.read() text = file.read()
content_type = guess_type(filename, text) content_type = guess_type(filename, text)
if not content_type in ('text/html', 'text/xml'): # if not content_type in ('text/html', 'text/xml'):
raise ValueError('Unsupported mimetype: %s' % content_type) # raise ValueError('Unsupported mimetype: %s' % content_type)
self.pt_edit(text, content_type) self.pt_edit(text, content_type)
return self.pt_editForm(manage_tabs_message='Saved changes') return self.pt_editForm(manage_tabs_message='Saved changes')
......
...@@ -70,20 +70,19 @@ def convertToUnicode(source, content_type, preferred_encodings): ...@@ -70,20 +70,19 @@ def convertToUnicode(source, content_type, preferred_encodings):
elif content_type.startswith('text/html'): elif content_type.startswith('text/html'):
encoding = charsetFromMetaEquiv(source) encoding = charsetFromMetaEquiv(source)
if encoding:
return unicode(source, encoding), encoding
# Try to detect the encoding by converting it unicode without raising # Try to detect the encoding by converting it unicode without raising
# exceptions. There are some smarter Python-based sniffer methods # exceptions. There are some smarter Python-based sniffer methods
# available however we have to check their licenses first before # available however we have to check their licenses first before
# including them into the Zope 2 core # including them into the Zope 2 core
if not encoding: for enc in preferred_encodings:
for enc in preferred_encodings: try:
try: return unicode(source, enc), enc
return unicode(source, enc), enc except UnicodeDecodeError:
except UnicodeDecodeError: continue
continue
raise TypeError('Could not auto-detect encoding') return unicode(source), None
else:
raise ValueError('Unsupported content-type: %s' % content_type)
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