Commit 18e43813 authored by Chris Withers's avatar Chris Withers

Merge of fix for #1490 to 2.8 branch: new zope.conf option for controlling the...

Merge of fix for #1490 to 2.8 branch: new zope.conf option for controlling the encoding of data sent to ZPublisher without any specified encoding.
parent b441999e
...@@ -33,6 +33,10 @@ Zope Changes ...@@ -33,6 +33,10 @@ Zope Changes
Bugs Fixed Bugs Fixed
- Collector #1490: Added a new zope.conf option to control the
character set used to encode unicode data that reaches
ZPublisher without any specified encoding.
- disabled ".. include" directive for all the ZReST product and the - disabled ".. include" directive for all the ZReST product and the
reStructuredText package reStructuredText package
......
...@@ -17,10 +17,13 @@ from types import ListType, TupleType, UnicodeType ...@@ -17,10 +17,13 @@ from types import ListType, TupleType, UnicodeType
from DateTime import DateTime from DateTime import DateTime
from cgi import escape from cgi import escape
# This may get overwritten during configuration
default_encoding = 'iso-8859-15'
def field2string(v): def field2string(v):
if hasattr(v,'read'): return v.read() if hasattr(v,'read'): return v.read()
elif isinstance(v,UnicodeType) : elif isinstance(v,UnicodeType):
return v.encode('iso-8859-15') return v.encode(default_encoding)
else: else:
return str(v) return str(v)
......
...@@ -25,6 +25,9 @@ from TaintedString import TaintedString ...@@ -25,6 +25,9 @@ from TaintedString import TaintedString
from maybe_lock import allocate_lock from maybe_lock import allocate_lock
xmlrpc=None # Placeholder for module that we'll import if we have to. xmlrpc=None # Placeholder for module that we'll import if we have to.
# This may get overwritten during configuration
default_encoding = 'iso-8859-15'
isCGI_NAME = { isCGI_NAME = {
'SERVER_SOFTWARE' : 1, 'SERVER_SOFTWARE' : 1,
'SERVER_NAME' : 1, 'SERVER_NAME' : 1,
...@@ -522,7 +525,7 @@ class HTTPRequest(BaseRequest): ...@@ -522,7 +525,7 @@ class HTTPRequest(BaseRequest):
if hasattr(converter,'convert_unicode'): if hasattr(converter,'convert_unicode'):
item = converter.convert_unicode(item) item = converter.convert_unicode(item)
else: else:
item = converter(item.encode('iso-8859-15')) item = converter(item.encode(default_encoding))
else: else:
item=converter(item) item=converter(item)
......
...@@ -26,6 +26,8 @@ from cgi import escape ...@@ -26,6 +26,8 @@ from cgi import escape
nl2sp = maketrans('\n',' ') nl2sp = maketrans('\n',' ')
# This may get overwritten during configuration
default_encoding = 'iso-8859-15'
# Enable APPEND_TRACEBACKS to make Zope append tracebacks like it used to, # Enable APPEND_TRACEBACKS to make Zope append tracebacks like it used to,
# but a better solution is to make standard_error_message display error_tb. # but a better solution is to make standard_error_message display error_tb.
...@@ -444,7 +446,7 @@ class HTTPResponse(BaseResponse): ...@@ -444,7 +446,7 @@ class HTTPResponse(BaseResponse):
encoding = match.group(1) encoding = match.group(1)
return body.encode(encoding) return body.encode(encoding)
# Use the default character encoding # Use the default character encoding
return body.encode('iso-8859-15','replace') return body.encode(default_encoding,'replace')
def setBase(self,base): def setBase(self,base):
"""Set the base URL for the returned document. """Set the base URL for the returned document.
......
...@@ -211,3 +211,13 @@ class ZopeDatabase(ZODBDatabase): ...@@ -211,3 +211,13 @@ class ZopeDatabase(ZODBDatabase):
return (real_root, real_path, container_class) return (real_root, real_path, container_class)
raise LookupError('Nothing known about mount path %s' % mount_path) raise LookupError('Nothing known about mount path %s' % mount_path)
def default_zpublisher_encoding(value):
# This is a bit clunky but necessary :-(
# These modules are imported during the configuration process
# so a module-level call to getConfiguration in any of them
# results in getting config data structure without the necessary
# value in it.
from ZPublisher import Converters, HTTPRequest, HTTPResponse
Converters.default_encoding = value
HTTPRequest.default_encoding = value
HTTPResponse.default_encoding = value
...@@ -813,5 +813,13 @@ ...@@ -813,5 +813,13 @@
<section type="zoperunner" name="*" attribute="runner"/> <section type="zoperunner" name="*" attribute="runner"/>
<key name="default-zpublisher-encoding" datatype=".default_zpublisher_encoding">
<description>
This key controls what character set is used to encode unicode
data that reaches ZPublisher without any other specified encoding.
</description>
<metadefault>iso-8859-15</metadefault>
</key>
</schema> </schema>
...@@ -848,6 +848,17 @@ instancehome $INSTANCE ...@@ -848,6 +848,17 @@ instancehome $INSTANCE
# #
# large-file-threshold 1Mb # large-file-threshold 1Mb
# Directive: default_zpublisher_encoding
#
# Description:
# This controls what character set is used to encode unicode
# data that reaches ZPublisher without any other specified encoding.
#
# Default: iso-8859-15
#
# Example:
#
# default_zpublisher_encoding utf-8
# Directives: servers # Directives: servers
# #
......
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