Commit 124cdb8b authored by Hanno Schlichting's avatar Hanno Schlichting

Changed the value for `default-zpublisher-encoding` and `management_page_charset` to `utf-8`.

parent c2dba5e7
...@@ -31,6 +31,9 @@ Features Added ...@@ -31,6 +31,9 @@ Features Added
Restructuring Restructuring
+++++++++++++ +++++++++++++
- Changed the value for `default-zpublisher-encoding` and
`management_page_charset` to `utf-8`.
- Removed the `enable-ms-author-via` directive which was only required for - Removed the `enable-ms-author-via` directive which was only required for
very old web folder implementations from before 2007. very old web folder implementations from before 2007.
......
...@@ -791,7 +791,6 @@ def xml_escape(value): ...@@ -791,7 +791,6 @@ def xml_escape(value):
if not isinstance(value, basestring): if not isinstance(value, basestring):
value = unicode(value) value = unicode(value)
if not isinstance(value, unicode): if not isinstance(value, unicode):
# XXX It really shouldn't be hardcoded to latin-1 here. value = value.decode('utf-8')
value = value.decode('latin-1')
value = escape(value) value = escape(value)
return value.encode('utf-8') return value.encode('utf-8')
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
""" """
import os import os
import re
from AccessControl.class_init import InitializeClass from AccessControl.class_init import InitializeClass
from AccessControl.Permissions import change_page_templates from AccessControl.Permissions import change_page_templates
...@@ -23,7 +22,6 @@ from AccessControl.Permissions import view ...@@ -23,7 +22,6 @@ from AccessControl.Permissions import view
from AccessControl.Permissions import view_management_screens from AccessControl.Permissions import view_management_screens
from AccessControl.SecurityManagement import getSecurityManager from AccessControl.SecurityManagement import getSecurityManager
from AccessControl.SecurityInfo import ClassSecurityInfo from AccessControl.SecurityInfo import ClassSecurityInfo
from AccessControl.ZopeGuards import safe_builtins
from Acquisition import Acquired from Acquisition import Acquired
from Acquisition import Explicit from Acquisition import Explicit
from Acquisition import aq_get from Acquisition import aq_get
...@@ -51,7 +49,6 @@ from Products.PageTemplates.utils import convertToUnicode ...@@ -51,7 +49,6 @@ from Products.PageTemplates.utils import convertToUnicode
preferred_encodings = ['utf-8', 'iso-8859-15'] preferred_encodings = ['utf-8', 'iso-8859-15']
if os.environ.has_key('ZPT_PREFERRED_ENCODING'): if os.environ.has_key('ZPT_PREFERRED_ENCODING'):
preferred_encodings.insert(0, os.environ['ZPT_PREFERRED_ENCODING']) preferred_encodings.insert(0, os.environ['ZPT_PREFERRED_ENCODING'])
class Src(Explicit): class Src(Explicit):
...@@ -73,7 +70,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -73,7 +70,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
"Zope wrapper for Page Template using TAL, TALES, and METAL" "Zope wrapper for Page Template using TAL, TALES, and METAL"
meta_type = 'Page Template' meta_type = 'Page Template'
output_encoding = 'iso-8859-15' # provide default for old instances output_encoding = 'utf-8' # provide default for old instances
func_defaults = None func_defaults = None
func_code = FuncCode((), 0) func_code = FuncCode((), 0)
...@@ -147,14 +144,14 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -147,14 +144,14 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
output_encoding = charset output_encoding = charset
else: else:
encoding = None encoding = None
output_encoding = 'iso-8859-15' output_encoding = 'utf-8'
else: else:
if charset: if charset:
encoding = charset encoding = charset
output_encoding = charset output_encoding = charset
else: else:
encoding = 'iso-8859-15' encoding = 'utf-8'
output_encoding = 'iso-8859-15' output_encoding = 'utf-8'
else: else:
utext, encoding = convertToUnicode(text, utext, encoding = convertToUnicode(text,
......
# *-* coding: iso-8859-15 -*- # *-* coding: iso-8859-1 -*-
import unittest import unittest
...@@ -26,7 +26,7 @@ class EngineTestsBase(PlacelessSetup): ...@@ -26,7 +26,7 @@ class EngineTestsBase(PlacelessSetup):
def __call__(self): def __call__(self):
return 'dummy' return 'dummy'
management_page_charset = 'iso-8859-15' management_page_charset = 'utf-8'
class DummyDocumentTemplate: class DummyDocumentTemplate:
__allow_access_to_unprotected_subobjects__ = 1 __allow_access_to_unprotected_subobjects__ = 1
...@@ -184,8 +184,8 @@ class EngineTestsBase(PlacelessSetup): ...@@ -184,8 +184,8 @@ class EngineTestsBase(PlacelessSetup):
import StrictUnicodeEncodingConflictResolver import StrictUnicodeEncodingConflictResolver
from Products.PageTemplates.interfaces \ from Products.PageTemplates.interfaces \
import IUnicodeEncodingConflictResolver import IUnicodeEncodingConflictResolver
provideUtility(StrictUnicodeEncodingConflictResolver, provideUtility(StrictUnicodeEncodingConflictResolver,
IUnicodeEncodingConflictResolver) IUnicodeEncodingConflictResolver)
self.assertEqual(ec.evaluate(expr), u'') self.assertEqual(ec.evaluate(expr), u'')
class UntrustedEngineTests(EngineTestsBase, unittest.TestCase): class UntrustedEngineTests(EngineTestsBase, unittest.TestCase):
...@@ -229,8 +229,8 @@ class UnicodeEncodingConflictResolverTests(PlacelessSetup, unittest.TestCase): ...@@ -229,8 +229,8 @@ class UnicodeEncodingConflictResolverTests(PlacelessSetup, unittest.TestCase):
provideUtility(StrictUnicodeEncodingConflictResolver, provideUtility(StrictUnicodeEncodingConflictResolver,
IUnicodeEncodingConflictResolver) IUnicodeEncodingConflictResolver)
resolver = getUtility(IUnicodeEncodingConflictResolver) resolver = getUtility(IUnicodeEncodingConflictResolver)
self.assertRaises(UnicodeDecodeError, text = u'\xe4\xfc\xe4'
resolver.resolve, None, '', None) self.assertEqual(resolver.resolve(None, text, None), text)
def testIgnoringResolver(self): def testIgnoringResolver(self):
from zope.component import getUtility from zope.component import getUtility
......
...@@ -13,7 +13,7 @@ import Zope2 ...@@ -13,7 +13,7 @@ import Zope2
import transaction import transaction
import zope.component.testing import zope.component.testing
from zope.traversing.adapters import DefaultTraversable, Traverser from zope.traversing.adapters import DefaultTraversable
from zope.publisher.http import HTTPCharsets from zope.publisher.http import HTTPCharsets
from Testing.makerequest import makerequest from Testing.makerequest import makerequest
...@@ -200,7 +200,7 @@ class ZPTUnicodeEncodingConflictResolution(ZopeTestCase): ...@@ -200,7 +200,7 @@ class ZPTUnicodeEncodingConflictResolution(ZopeTestCase):
output_encoding='ascii', output_encoding='ascii',
) )
state = cPickle.dumps(empty, protocol=1) state = cPickle.dumps(empty, protocol=1)
clone = cPickle.loads(state) cPickle.loads(state)
def testBug246983(self): def testBug246983(self):
# See https://bugs.launchpad.net/bugs/246983 # See https://bugs.launchpad.net/bugs/246983
...@@ -250,7 +250,7 @@ class ZopePageTemplateFileTests(ZopeTestCase): ...@@ -250,7 +250,7 @@ class ZopePageTemplateFileTests(ZopeTestCase):
result = zpt.pt_render() result = zpt.pt_render()
# use startswith() because the renderer appends a trailing \n # use startswith() because the renderer appends a trailing \n
self.assertEqual(result.encode('ascii').startswith(ascii_str), True) self.assertEqual(result.encode('ascii').startswith(ascii_str), True)
self.assertEqual(zpt.output_encoding, 'iso-8859-15') self.assertEqual(zpt.output_encoding, 'utf-8')
def testPT_RenderUnicodeExpr(self): def testPT_RenderUnicodeExpr(self):
# Check workaround for unicode incompatibility of ZRPythonExpr. # Check workaround for unicode incompatibility of ZRPythonExpr.
...@@ -260,7 +260,7 @@ class ZopePageTemplateFileTests(ZopeTestCase): ...@@ -260,7 +260,7 @@ class ZopePageTemplateFileTests(ZopeTestCase):
'unicode(\'\xfe\', \'iso-8859-15\')" />'), 'unicode(\'\xfe\', \'iso-8859-15\')" />'),
encoding='iso-8859-15') encoding='iso-8859-15')
zpt = self.app['test'] zpt = self.app['test']
result = zpt.pt_render() # should not raise a UnicodeDecodeError zpt.pt_render() # should not raise a UnicodeDecodeError
def testPT_RenderWithISO885915(self): def testPT_RenderWithISO885915(self):
manage_addPageTemplate(self.app, 'test', manage_addPageTemplate(self.app, 'test',
...@@ -270,7 +270,7 @@ class ZopePageTemplateFileTests(ZopeTestCase): ...@@ -270,7 +270,7 @@ class ZopePageTemplateFileTests(ZopeTestCase):
# use startswith() because the renderer appends a trailing \n # use startswith() because the renderer appends a trailing \n
self.assertTrue(result.encode('iso-8859-15' self.assertTrue(result.encode('iso-8859-15'
).startswith(iso885915_str)) ).startswith(iso885915_str))
self.assertEqual(zpt.output_encoding, 'iso-8859-15') self.assertEqual(zpt.output_encoding, 'utf-8')
def testPT_RenderWithUTF8(self): def testPT_RenderWithUTF8(self):
manage_addPageTemplate(self.app, 'test', manage_addPageTemplate(self.app, 'test',
...@@ -279,7 +279,7 @@ class ZopePageTemplateFileTests(ZopeTestCase): ...@@ -279,7 +279,7 @@ class ZopePageTemplateFileTests(ZopeTestCase):
result = zpt.pt_render() result = zpt.pt_render()
# use startswith() because the renderer appends a trailing \n # use startswith() because the renderer appends a trailing \n
self.assertEqual(result.encode('utf-8').startswith(utf8_str), True) self.assertEqual(result.encode('utf-8').startswith(utf8_str), True)
self.assertEqual(zpt.output_encoding, 'iso-8859-15') self.assertEqual(zpt.output_encoding, 'utf-8')
def testWriteAcceptsUnicode(self): def testWriteAcceptsUnicode(self):
manage_addPageTemplate(self.app, 'test', '', encoding='utf-8') manage_addPageTemplate(self.app, 'test', '', encoding='utf-8')
...@@ -323,14 +323,9 @@ class ZopePageTemplateFileTests(ZopeTestCase): ...@@ -323,14 +323,9 @@ class ZopePageTemplateFileTests(ZopeTestCase):
self.assertEqual(zpt.output_encoding, 'utf-8') self.assertEqual(zpt.output_encoding, 'utf-8')
self.assertEqual(zpt.content_type, 'text/html') self.assertEqual(zpt.content_type, 'text/html')
def testPutHTMLIso8859_15WithoutCharsetInfo(self):
zpt = self._put(html_iso_8859_15_wo_header)
self.assertEqual(zpt.output_encoding, 'iso-8859-15')
self.assertEqual(zpt.content_type, 'text/html')
def testPutHTMLUTF8_WithoutCharsetInfo(self): def testPutHTMLUTF8_WithoutCharsetInfo(self):
zpt = self._put(html_utf8_wo_header) zpt = self._put(html_utf8_wo_header)
self.assertEqual(zpt.output_encoding, 'iso-8859-15') self.assertEqual(zpt.output_encoding, 'utf-8')
self.assertEqual(zpt.content_type, 'text/html') self.assertEqual(zpt.content_type, 'text/html')
def testPutXMLIso8859_15(self): def testPutXMLIso8859_15(self):
...@@ -338,20 +333,20 @@ class ZopePageTemplateFileTests(ZopeTestCase): ...@@ -338,20 +333,20 @@ class ZopePageTemplateFileTests(ZopeTestCase):
zpt = self._put(xml_iso_8859_15) zpt = self._put(xml_iso_8859_15)
self.assertEqual(zpt.output_encoding, 'utf-8') self.assertEqual(zpt.output_encoding, 'utf-8')
self.assertEqual(zpt.content_type, 'text/xml') self.assertEqual(zpt.content_type, 'text/xml')
result = zpt.pt_render() # should not raise an exception zpt.pt_render() # should not raise an exception
def testPutXMLUTF8(self): def testPutXMLUTF8(self):
""" XML: use always UTF-8 als output encoding """ """ XML: use always UTF-8 als output encoding """
zpt = self._put(xml_utf8) zpt = self._put(xml_utf8)
self.assertEqual(zpt.output_encoding, 'utf-8') self.assertEqual(zpt.output_encoding, 'utf-8')
self.assertEqual(zpt.content_type, 'text/xml') self.assertEqual(zpt.content_type, 'text/xml')
result = zpt.pt_render() # should not raise an exception zpt.pt_render() # should not raise an exception
def testXMLAttrsMustNotBeLowercased(self): def testXMLAttrsMustNotBeLowercased(self):
zpt = self._put(xml_with_upper_attr) zpt = self._put(xml_with_upper_attr)
self.assertEqual(zpt.content_type, 'text/xml') self.assertEqual(zpt.content_type, 'text/xml')
result = zpt.pt_render() result = zpt.pt_render()
self.assertEqual('ATTR' in result, True) self.assertEqual('ATTR' in result, True)
def testHTMLAttrsAreLowerCased(self): def testHTMLAttrsAreLowerCased(self):
zpt = self._put(html_with_upper_attr) zpt = self._put(html_with_upper_attr)
...@@ -372,9 +367,9 @@ class PreferredCharsetUnicodeResolverTests(unittest.TestCase): ...@@ -372,9 +367,9 @@ class PreferredCharsetUnicodeResolverTests(unittest.TestCase):
# This test checks the edgecase where the unicode conflict resolver # This test checks the edgecase where the unicode conflict resolver
# is called with a context object having no REQUEST # is called with a context object having no REQUEST
class ContextMock: class ContextMock:
management_page_charset = 'iso-8859-15' management_page_charset = 'utf-8'
result = PreferredCharsetResolver.resolve(ContextMock(), '', None) result = PreferredCharsetResolver.resolve(ContextMock(), '', None)
self.assertEqual(result, u'') self.assertEqual(result, '')
class ZPTRegressions(unittest.TestCase): class ZPTRegressions(unittest.TestCase):
......
...@@ -54,7 +54,11 @@ class Z2UnicodeEncodingConflictResolver: ...@@ -54,7 +54,11 @@ class Z2UnicodeEncodingConflictResolver:
return unicode(text) return unicode(text)
except UnicodeDecodeError: except UnicodeDecodeError:
encoding = getattr(context, 'management_page_charset', default_encoding) encoding = getattr(context, 'management_page_charset', default_encoding)
return unicode(text, encoding, self.mode) try:
return unicode(text, encoding, self.mode)
except UnicodeDecodeError:
# finally try the old management_page_charset default
return unicode(text, 'iso-8859-15', self.mode)
class PreferredCharsetResolver: class PreferredCharsetResolver:
......
. charset configuration, defaulting to 'latin-1'
. add "level" and "header" args to render / as_html
- level indicates the header level to start at
- header boolean turns page header tags on/off
...@@ -73,8 +73,8 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent): ...@@ -73,8 +73,8 @@ class ZReST(Item, PropertyManager, Historical, Implicit, Persistent):
{'id':'stylesheet', 'type': 'string', 'mode': 'w', {'id':'stylesheet', 'type': 'string', 'mode': 'w',
'default': ''}, 'default': ''},
{'id':'report_level', 'type': 'string', 'mode': 'w', 'default': '2'}, {'id':'report_level', 'type': 'string', 'mode': 'w', 'default': '2'},
{'id':'input_encoding', 'type': 'string', 'mode': 'w', 'default': 'iso-8859-15'}, {'id':'input_encoding', 'type': 'string', 'mode': 'w', 'default': 'utf-8'},
{'id':'output_encoding', 'type': 'string', 'mode': 'w', 'default': 'iso-8859-15'}, {'id':'output_encoding', 'type': 'string', 'mode': 'w', 'default': 'utf-8'},
) )
property_extensible_schema__ = 0 property_extensible_schema__ = 0
......
# -*- coding: iso-8859-15 -*- # -*- coding: utf-8 -*-
""" Unit tests for ZReST objects """ Unit tests for ZReST objects
""" """
...@@ -12,7 +12,7 @@ txt = """Hello World ...@@ -12,7 +12,7 @@ txt = """Hello World
text text text text
Von Vgeln und fen Von V\xc3\xb6geln und \xc3\x96fen
=================== ===================
- some - some
...@@ -62,15 +62,15 @@ class TestZReST(unittest.TestCase): ...@@ -62,15 +62,15 @@ class TestZReST(unittest.TestCase):
def testConversion(self): def testConversion(self):
resty = self._makeOne() resty = self._makeOne()
resty.source = txt resty.source = txt
resty.input_encoding = 'iso-8859-15' resty.input_encoding = 'utf-8'
resty.output_encoding = 'iso-8859-15' resty.output_encoding = 'utf-8'
resty.render() resty.render()
html = resty.index_html() html = resty.index_html()
s = '<h1>Hello World</h1>' s = '<h1>Hello World</h1>'
self.assertEqual(s in html, True) self.assertEqual(s in html, True)
s = '<h1>Von Vgeln und fen</h1>' s = '<h1>Von V\xc3\xb6geln und \xc3\x96fen</h1>'
self.assertEqual(s in html, True) self.assertEqual(s in html, True)
# ZReST should render a complete HTML document # ZReST should render a complete HTML document
......
...@@ -86,7 +86,7 @@ Test parameter containing an additional '?' ...@@ -86,7 +86,7 @@ Test parameter containing an additional '?'
... """) ... """)
HTTP/1.1 200 OK HTTP/1.1 200 OK
Content-Length: 5 Content-Length: 5
Content-Type: text/plain; charset=iso-8859-15 Content-Type: text/plain; charset=utf-8
<BLANKLINE> <BLANKLINE>
index index
......
...@@ -18,7 +18,7 @@ from DateTime.interfaces import SyntaxError ...@@ -18,7 +18,7 @@ from DateTime.interfaces import SyntaxError
from cgi import escape from cgi import escape
# This may get overwritten during configuration # This may get overwritten during configuration
default_encoding = 'iso-8859-15' default_encoding = 'utf-8'
def field2string(v): def field2string(v):
if hasattr(v,'read'): return v.read() if hasattr(v,'read'): return v.read()
......
...@@ -56,7 +56,7 @@ xmlrpc = None ...@@ -56,7 +56,7 @@ xmlrpc = None
base64 = None base64 = None
# This may get overwritten during configuration # This may get overwritten during configuration
default_encoding = 'iso-8859-15' default_encoding = 'utf-8'
isCGI_NAMEs = { isCGI_NAMEs = {
'SERVER_SOFTWARE' : 1, 'SERVER_SOFTWARE' : 1,
...@@ -642,7 +642,7 @@ class HTTPRequest(BaseRequest): ...@@ -642,7 +642,7 @@ class HTTPRequest(BaseRequest):
# We have a string with a specified character # We have a string with a specified character
# encoding. This gets passed to the converter # encoding. This gets passed to the converter
# either as unicode, if it can handle it, or # either as unicode, if it can handle it, or
# crunched back down to latin-1 if it can not. # crunched back down to utf-8 if it can not.
item = unicode(item,character_encoding) item = unicode(item,character_encoding)
if hasattr(converter,'convert_unicode'): if hasattr(converter,'convert_unicode'):
item = converter.convert_unicode(item) item = converter.convert_unicode(item)
......
...@@ -36,7 +36,7 @@ from ZPublisher.pubevents import PubBeforeStreaming ...@@ -36,7 +36,7 @@ from ZPublisher.pubevents import PubBeforeStreaming
nl2sp = maketrans('\n', ' ') nl2sp = maketrans('\n', ' ')
# This may get overwritten during configuration # This may get overwritten during configuration
default_encoding = 'iso-8859-15' default_encoding = 'utf-8'
# 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.
......
...@@ -158,7 +158,7 @@ And the same with unicode error value. ...@@ -158,7 +158,7 @@ And the same with unicode error value.
HTTPError: HTTP Error 401: Unauthorized HTTPError: HTTP Error 401: Unauthorized
>>> 'Error Type: Unauthorized' in browser.contents >>> 'Error Type: Unauthorized' in browser.contents
True True
>>> 'Error Value: ERROR VALUE ?' in browser.contents >>> 'Error Value: ERROR VALUE \xce\xa9' in browser.contents
True True
>>> browser.headers['WWW-Authenticate'] >>> browser.headers['WWW-Authenticate']
'basic realm="Zope2"' 'basic realm="Zope2"'
......
...@@ -205,7 +205,6 @@ class HTTPRequestTests(unittest.TestCase): ...@@ -205,7 +205,6 @@ class HTTPRequestTests(unittest.TestCase):
('utext:utext:utf8', 'test\xc2\xae\ntest\xc2\xae\n'), ('utext:utext:utf8', 'test\xc2\xae\ntest\xc2\xae\n'),
('utokens:utokens:utf8', 'test\xc2\xae test\xc2\xae'), ('utokens:utokens:utf8', 'test\xc2\xae test\xc2\xae'),
('ulines:ulines:utf8', 'test\xc2\xae\ntest\xc2\xae'), ('ulines:ulines:utf8', 'test\xc2\xae\ntest\xc2\xae'),
('nouconverter:string:utf8', 'test\xc2\xae')) ('nouconverter:string:utf8', 'test\xc2\xae'))
req = self._processInputs(inputs) req = self._processInputs(inputs)
...@@ -219,8 +218,8 @@ class HTTPRequestTests(unittest.TestCase): ...@@ -219,8 +218,8 @@ class HTTPRequestTests(unittest.TestCase):
self.assertEquals(req['utokens'], [u'test\u00AE', u'test\u00AE']) self.assertEquals(req['utokens'], [u'test\u00AE', u'test\u00AE'])
self.assertEquals(req['ulines'], [u'test\u00AE', u'test\u00AE']) self.assertEquals(req['ulines'], [u'test\u00AE', u'test\u00AE'])
# expect a latin1 encoded version # expect a utf-8 encoded version
self.assertEquals(req['nouconverter'], 'test\xae') self.assertEquals(req['nouconverter'], 'test\xc2\xae')
self._noTaintedValues(req) self._noTaintedValues(req)
self._onlyTaintedformHoldsTaintedStrings(req) self._onlyTaintedformHoldsTaintedStrings(req)
......
# -*- coding: iso-8859-15 -*- # -*- coding: utf-8 -*-
import unittest import unittest
import sys import sys
...@@ -68,13 +68,13 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -68,13 +68,13 @@ class HTTPResponseTests(unittest.TestCase):
def test_ctor_charset_no_content_type_header(self): def test_ctor_charset_no_content_type_header(self):
response = self._makeOne(body='foo') response = self._makeOne(body='foo')
self.assertEqual(response.headers.get('content-type'), self.assertEqual(response.headers.get('content-type'),
'text/plain; charset=iso-8859-15') 'text/plain; charset=utf-8')
def test_ctor_charset_text_header_no_charset_defaults_latin1(self): def test_ctor_charset_text_header_no_charset_defaults_latin1(self):
response = self._makeOne(body='foo', response = self._makeOne(body='foo',
headers={'content-type': 'text/plain'}) headers={'content-type': 'text/plain'})
self.assertEqual(response.headers.get('content-type'), self.assertEqual(response.headers.get('content-type'),
'text/plain; charset=iso-8859-15') 'text/plain; charset=utf-8')
def test_ctor_charset_application_header_no_header(self): def test_ctor_charset_application_header_no_header(self):
response = self._makeOne(body='foo', response = self._makeOne(body='foo',
...@@ -90,15 +90,15 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -90,15 +90,15 @@ class HTTPResponseTests(unittest.TestCase):
'application/foo; charset: something') 'application/foo; charset: something')
def test_ctor_charset_unicode_body_application_header(self): def test_ctor_charset_unicode_body_application_header(self):
BODY = unicode('rger', 'iso-8859-15') BODY = u'\xe4rger'
response = self._makeOne(body=BODY, response = self._makeOne(body=BODY,
headers={'content-type': 'application/foo'}) headers={'content-type': 'application/foo'})
self.assertEqual(response.headers.get('content-type'), self.assertEqual(response.headers.get('content-type'),
'application/foo; charset=iso-8859-15') 'application/foo; charset=utf-8')
self.assertEqual(response.body, 'rger') self.assertEqual(response.body, BODY.encode('utf-8'))
def test_ctor_charset_unicode_body_application_header_diff_encoding(self): def test_ctor_charset_unicode_body_application_header_diff_encoding(self):
BODY = unicode('rger', 'iso-8859-15') BODY = u'\xe4rger'
response = self._makeOne(body=BODY, response = self._makeOne(body=BODY,
headers={'content-type': headers={'content-type':
'application/foo; charset=utf-8'}) 'application/foo; charset=utf-8'})
...@@ -562,7 +562,7 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -562,7 +562,7 @@ class HTTPResponseTests(unittest.TestCase):
self.assertTrue(result) self.assertTrue(result)
self.assertEqual(response.body, EXPECTED) self.assertEqual(response.body, EXPECTED)
self.assertEqual(response.getHeader('Content-Type'), self.assertEqual(response.getHeader('Content-Type'),
'text/html; charset=iso-8859-15') 'text/html; charset=utf-8')
self.assertEqual(response.getHeader('Content-Length'), self.assertEqual(response.getHeader('Content-Length'),
str(len(EXPECTED))) str(len(EXPECTED)))
...@@ -576,7 +576,7 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -576,7 +576,7 @@ class HTTPResponseTests(unittest.TestCase):
self.assertTrue('TITLE' in response.body) self.assertTrue('TITLE' in response.body)
self.assertTrue('BODY' in response.body) self.assertTrue('BODY' in response.body)
self.assertEqual(response.getHeader('Content-Type'), self.assertEqual(response.getHeader('Content-Type'),
'text/html; charset=iso-8859-15') 'text/html; charset=utf-8')
def test_setBody_string_not_HTML(self): def test_setBody_string_not_HTML(self):
response = self._makeOne() response = self._makeOne()
...@@ -584,7 +584,7 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -584,7 +584,7 @@ class HTTPResponseTests(unittest.TestCase):
self.assertTrue(result) self.assertTrue(result)
self.assertEqual(response.body, 'BODY') self.assertEqual(response.body, 'BODY')
self.assertEqual(response.getHeader('Content-Type'), self.assertEqual(response.getHeader('Content-Type'),
'text/plain; charset=iso-8859-15') 'text/plain; charset=utf-8')
self.assertEqual(response.getHeader('Content-Length'), '4') self.assertEqual(response.getHeader('Content-Length'), '4')
def test_setBody_string_HTML(self): def test_setBody_string_HTML(self):
...@@ -594,7 +594,7 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -594,7 +594,7 @@ class HTTPResponseTests(unittest.TestCase):
self.assertTrue(result) self.assertTrue(result)
self.assertEqual(response.body, HTML) self.assertEqual(response.body, HTML)
self.assertEqual(response.getHeader('Content-Type'), self.assertEqual(response.getHeader('Content-Type'),
'text/html; charset=iso-8859-15') 'text/html; charset=utf-8')
self.assertEqual(response.getHeader('Content-Length'), str(len(HTML))) self.assertEqual(response.getHeader('Content-Length'), str(len(HTML)))
def test_setBody_object_with_asHTML(self): def test_setBody_object_with_asHTML(self):
...@@ -607,18 +607,18 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -607,18 +607,18 @@ class HTTPResponseTests(unittest.TestCase):
self.assertTrue(result) self.assertTrue(result)
self.assertEqual(response.body, HTML) self.assertEqual(response.body, HTML)
self.assertEqual(response.getHeader('Content-Type'), self.assertEqual(response.getHeader('Content-Type'),
'text/html; charset=iso-8859-15') 'text/html; charset=utf-8')
self.assertEqual(response.getHeader('Content-Length'), str(len(HTML))) self.assertEqual(response.getHeader('Content-Length'), str(len(HTML)))
def test_setBody_object_with_unicode(self): def test_setBody_object_with_unicode(self):
HTML = u'<html><head></head><body><h1>Tr\u0039s Bien</h1></body></html>' HTML = u'<html><head></head><body><h1>Tr\u0039s Bien</h1></body></html>'
ENCODED = HTML.encode('iso-8859-15') ENCODED = HTML.encode('utf-8')
response = self._makeOne() response = self._makeOne()
result = response.setBody(HTML) result = response.setBody(HTML)
self.assertTrue(result) self.assertTrue(result)
self.assertEqual(response.body, ENCODED) self.assertEqual(response.body, ENCODED)
self.assertEqual(response.getHeader('Content-Type'), self.assertEqual(response.getHeader('Content-Type'),
'text/html; charset=iso-8859-15') 'text/html; charset=utf-8')
self.assertEqual(response.getHeader('Content-Length'), self.assertEqual(response.getHeader('Content-Length'),
str(len(ENCODED))) str(len(ENCODED)))
...@@ -737,7 +737,7 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -737,7 +737,7 @@ class HTTPResponseTests(unittest.TestCase):
def test_redirect_explicit_status(self): def test_redirect_explicit_status(self):
URL = 'http://example.com' URL = 'http://example.com'
response = self._makeOne() response = self._makeOne()
result = response.redirect(URL, status=307) response.redirect(URL, status=307)
self.assertEqual(response.status, 307) self.assertEqual(response.status, 307)
self.assertEqual(response.getHeader('Location'), URL) self.assertEqual(response.getHeader('Location'), URL)
self.assertFalse(response._locked_status) self.assertFalse(response._locked_status)
...@@ -745,7 +745,7 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -745,7 +745,7 @@ class HTTPResponseTests(unittest.TestCase):
def test_redirect_w_lock(self): def test_redirect_w_lock(self):
URL = 'http://example.com' URL = 'http://example.com'
response = self._makeOne() response = self._makeOne()
result = response.redirect(URL, lock=True) response.redirect(URL, lock=True)
self.assertEqual(response.status, 302) self.assertEqual(response.status, 302)
self.assertEqual(response.getHeader('Location'), URL) self.assertEqual(response.getHeader('Location'), URL)
self.assertTrue(response._locked_status) self.assertTrue(response._locked_status)
...@@ -1100,7 +1100,7 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -1100,7 +1100,7 @@ class HTTPResponseTests(unittest.TestCase):
[('X-Powered-By', 'Zope (www.zope.org), ' [('X-Powered-By', 'Zope (www.zope.org), '
'Python (www.python.org)'), 'Python (www.python.org)'),
('Content-Length', '4'), ('Content-Length', '4'),
('Content-Type', 'text/plain; charset=iso-8859-15'), ('Content-Type', 'text/plain; charset=utf-8'),
]) ])
def test___str__already_wrote(self): def test___str__already_wrote(self):
...@@ -1251,7 +1251,7 @@ class HTTPResponseTests(unittest.TestCase): ...@@ -1251,7 +1251,7 @@ class HTTPResponseTests(unittest.TestCase):
'Python (www.python.org)') 'Python (www.python.org)')
self.assertEqual(lines[2], 'Content-Length: 4') self.assertEqual(lines[2], 'Content-Length: 4')
self.assertEqual(lines[3], self.assertEqual(lines[3],
'Content-Type: text/plain; charset=iso-8859-15') 'Content-Type: text/plain; charset=utf-8')
self.assertEqual(lines[4], '') self.assertEqual(lines[4], '')
self.assertEqual(lines[5], 'BLAH') self.assertEqual(lines[5], 'BLAH')
......
...@@ -24,7 +24,7 @@ class ConvertersTests(unittest.TestCase): ...@@ -24,7 +24,7 @@ class ConvertersTests(unittest.TestCase):
from ZPublisher.Converters import field2string from ZPublisher.Converters import field2string
to_convert = u'to_convert' to_convert = u'to_convert'
self.assertEqual(field2string(to_convert), self.assertEqual(field2string(to_convert),
to_convert.encode('iso-8859-15')) to_convert.encode('utf-8'))
def test_field2string_with_filelike_object(self): def test_field2string_with_filelike_object(self):
from ZPublisher.Converters import field2string from ZPublisher.Converters import field2string
......
...@@ -152,7 +152,7 @@ class ZopeStarter: ...@@ -152,7 +152,7 @@ class ZopeStarter:
# workaround to allow unicode encoding conversions in DTML # workaround to allow unicode encoding conversions in DTML
import codecs import codecs
dummy = codecs.lookup('iso-8859-1') dummy = codecs.lookup('utf-8')
locale_id = self.cfg.locale locale_id = self.cfg.locale
......
...@@ -202,13 +202,13 @@ class StartupTestCase(unittest.TestCase): ...@@ -202,13 +202,13 @@ class StartupTestCase(unittest.TestCase):
conf, dummy = self.load_config_text("""\ conf, dummy = self.load_config_text("""\
instancehome <<INSTANCE_HOME>> instancehome <<INSTANCE_HOME>>
""") """)
self.assertEqual(conf.default_zpublisher_encoding, 'iso-8859-15') self.assertEqual(conf.default_zpublisher_encoding, 'utf-8')
conf, dummy = self.load_config_text("""\ conf, dummy = self.load_config_text("""\
instancehome <<INSTANCE_HOME>> instancehome <<INSTANCE_HOME>>
default-zpublisher-encoding utf-8 default-zpublisher-encoding iso-8859-15
""") """)
self.assertEqual(conf.default_zpublisher_encoding, 'utf-8') self.assertEqual(conf.default_zpublisher_encoding, 'iso-8859-15')
def test_suite(): def test_suite():
......
...@@ -841,7 +841,7 @@ ...@@ -841,7 +841,7 @@
<key name="default-zpublisher-encoding" <key name="default-zpublisher-encoding"
datatype=".default_zpublisher_encoding" datatype=".default_zpublisher_encoding"
default="iso-8859-15"> default="utf-8">
<description> <description>
This key controls what character set is used to encode unicode This key controls what character set is used to encode unicode
data that reaches ZPublisher without any other specified encoding. data that reaches ZPublisher without any other specified encoding.
......
...@@ -355,104 +355,6 @@ instancehome $INSTANCE ...@@ -355,104 +355,6 @@ instancehome $INSTANCE
# verbose-security on # verbose-security on
# Directive: maximum-number-of-session-objects
#
# Description:
# An integer value representing the number of items to use as a
# "maximum number of subobjects" value of the
# '/temp_folder/session_data' transient object container.
#
# Default: 1000
#
# Example:
#
# maximum-number-of-session-objects 10000
# Directive: session-add-notify-script-path
#
# Description:
# An optional fill Zope path name of a callable object to be set as the
# "script to call on object addition" of the sessioN_data transient
# object container created in the /temp_folder folder at startup.
#
# Default: unset
#
# Example:
#
# session-add-notify-script-path /scripts/add_notifier
# Directive: session-delete-notify-script-path
#
# Description:
# An optional fill Zope path name of a callable object to be set as the
# "script to call on object deletion" of the sessioN_data transient
# object container created in the /temp_folder folder at startup.
#
# Default: unset
#
# Example:
#
# session-delete-notify-script-path /scripts/del_notifier
# Directive: session-timeout-minutes
#
# Description:
# An integer value representing the number of minutes to be used as the
# "data object timeout" of the '/temp_folder/session_data' transient
# object container.
#
# Default: 20
#
# Example:
#
# session-timeout-minutes 30
# Directive: session-resolution-seconds
#
# Description:
# An integer value representing the number of seconds to be used as the
# "timeout resolution" of the '/temp_folder/session_data' transient
# object container.
#
# Default: 20
#
# Example:
#
# session-resolution-seconds 60
# Directive: suppress-all-access-rules
#
# Description:
# If this directive is set to on, no access rules in your Zope site
# will be executed. This is useful if you "lock yourself out" of a
# particular part of your site by setting an improper access rule.
#
# Default: off
#
# Example:
#
# suppress-all-access-rules on
# Directive: suppress-all-site-roots
#
# Description:
# If this directive is set to on, no site roots in your Zope site will
# be effective. This is useful if you "lock yourself out" of a
# particular part of your site by setting an improper site root.
#
# Default: off
#
# Example:
#
# suppress-all-site-roots on
# Directives: logger # Directives: logger
# #
# Description: # Description:
...@@ -627,17 +529,6 @@ instancehome $INSTANCE ...@@ -627,17 +529,6 @@ 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
# #
......
# -*- coding: iso-8859-15 -*- # -*- coding: utf-8 -*-
import unittest import unittest
import cgi import cgi
...@@ -11,7 +11,7 @@ txt = """Hello World ...@@ -11,7 +11,7 @@ txt = """Hello World
text text text text
Von Vgeln und fen Von V\xc3\xb6geln und \xc3\x96fen
=================== ===================
- some - some
...@@ -43,26 +43,25 @@ class TestReST(unittest.TestCase): ...@@ -43,26 +43,25 @@ class TestReST(unittest.TestCase):
input_encoding=in_enc, input_encoding=in_enc,
output_encoding=out_enc) output_encoding=out_enc)
encoding = 'iso-8859-15' encoding = 'utf-8'
html = _test(txt, encoding, encoding) html = _test(txt, encoding, encoding)
self.assertEqual('Vgel' in html, True) self.assertEqual('V\xc3\xb6gel' in html, True)
self.assertEqual('fen' in html, True) self.assertEqual('\xc3\x96fen' in html, True)
html = _test(txt, encoding, 'unicode') html = _test(txt, encoding, 'unicode')
self.assertEqual(unicode('Vgel', encoding) in html, True) self.assertEqual(unicode('V\xc3\xb6gel', encoding) in html, True)
self.assertEqual(unicode('fen', encoding) in html, True) self.assertEqual(unicode('\xc3\x96fen', encoding) in html, True)
html = _test(unicode(txt, encoding), 'unicode', encoding) html = _test(unicode(txt, encoding), 'unicode', encoding)
self.assertEqual('Vgel' in html, True) self.assertEqual('V\xc3\xb6gel' in html, True)
self.assertEqual('fen' in html, True) self.assertEqual('\xc3\x96fen' in html, True)
html = _test(unicode(txt, encoding), 'unicode', 'unicode') html = _test(unicode(txt, encoding), 'unicode', 'unicode')
self.assertEqual(unicode('Vgel', encoding) in html, True) self.assertEqual(unicode('V\xc3\xb6gel', encoding) in html, True)
self.assertEqual(unicode('fen', encoding) in html, True) self.assertEqual(unicode('\xc3\x96fen', encoding) in html, True)
def testHeaderLevel(self): def testHeaderLevel(self):
encoding = 'utf-8'
encoding = 'iso-8859-15'
for level in range(0, 5): for level in range(0, 5):
html = HTML(txt, input_encoding=encoding, html = HTML(txt, input_encoding=encoding,
output_encoding=encoding, output_encoding=encoding,
...@@ -71,7 +70,8 @@ class TestReST(unittest.TestCase): ...@@ -71,7 +70,8 @@ class TestReST(unittest.TestCase):
expected = '<h%d>Hello World</h%d>' % (level+1, level+1) expected = '<h%d>Hello World</h%d>' % (level+1, level+1)
self.assertEqual(expected in html, True) self.assertEqual(expected in html, True)
expected = '<h%d>Von Vgeln und fen</h%d>' % (level+1, level+1) expected = '<h%d>Von V\xc3\xb6geln und \xc3\x96fen</h%d>' % (
level+1, level+1)
self.assertEqual(expected in html, True) self.assertEqual(expected in html, True)
def testWithSingleSubtitle(self): def testWithSingleSubtitle(self):
......
...@@ -158,7 +158,7 @@ analyses: ...@@ -158,7 +158,7 @@ analyses:
Zope responds to this with a success response like this: Zope responds to this with a success response like this:
<?xml version="1.0" encoding="iso-8859-15" ?> <?xml version="1.0" encoding="utf-8" ?>
<d:prop xmlns:d="DAV:"> <d:prop xmlns:d="DAV:">
<d:lockdiscovery> <d:lockdiscovery>
<d:activelock> <d:activelock>
......
...@@ -26,7 +26,7 @@ TODO: ...@@ -26,7 +26,7 @@ TODO:
NOTE: So far i didn't have any problems. NOTE: So far i didn't have any problems.
If you have problems please report them. If you have problems please report them.
- We are using a hardcoded default of latin-1 for encoding unicode - We are using a hardcoded default of utf-8 for encoding unicode
strings. While this is suboptimal, it does match the expected strings. While this is suboptimal, it does match the expected
encoding from OFS.PropertySheet. We need to find a the encoding encoding from OFS.PropertySheet. We need to find a the encoding
somehow, maybe use the same encoding as the ZMI is using? somehow, maybe use the same encoding as the ZMI is using?
...@@ -59,11 +59,11 @@ def unescape(value, entities=None): ...@@ -59,11 +59,11 @@ def unescape(value, entities=None):
_ent.update(entities) _ent.update(entities)
return _unescape(value, entities) return _unescape(value, entities)
# XXX latin-1 is hardcoded on OFS.PropertySheets as the expected # utf-8 is hardcoded on OFS.PropertySheets as the expected
# encoding properties will be stored in. Optimally, we should use the # encoding properties will be stored in. Optimally, we should use the
# same encoding as the 'default_encoding' property that is used for # same encoding as the 'default_encoding' property that is used for
# the ZMI. # the ZMI.
zope_encoding = 'latin-1' zope_encoding = 'utf-8'
class Node: class Node:
""" Our nodes no matter what type """ Our nodes no matter what 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