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