Commit c2e643f9 authored by 's avatar

- Marked `processInputs` and `setPageEncoding` as deprecated.

parent 92047edf
......@@ -54,6 +54,10 @@ Features Added
Restructuring
+++++++++++++
- Five.browser: Marked `processInputs` and `setPageEncoding` as deprecated.
`processInputs` was replaced by the `postProcessInputs` request method and
the charset negotiation done by `setPageEncoding` was never fully supported.
- Factored out the `Products.ZCatalog` and `Products.PluginIndexes` packages
into a new `Products.ZCatalog` distribution.
......
......@@ -15,6 +15,8 @@
encoding.
"""
from warnings import warn
from zope.publisher.browser import isCGI_NAME
from zope.i18n.interfaces import IUserPreferredCharsets
......@@ -34,7 +36,10 @@ def processInputValue(value, charsets):
"""Recursively look for values (e.g. elements of lists, tuples or dicts)
and attempt to decode.
"""
warn(u'processInputValue() is deprecated and will be removed in Zope '
u'2.16.',
DeprecationWarning, stacklevel=2)
if isinstance(value, list):
return [processInputValue(v, charsets) for v in value]
elif isinstance(value, tuple):
......@@ -53,14 +58,18 @@ def processInputs(request, charsets=None):
the passed-in list of charsets. If none are passed in, look up the user's
preferred charsets. The default is to use utf-8.
"""
warn(u'processInputs() is deprecated and will be removed in Zope 2.16. If '
u'your view implements IBrowserPage, similar processing is now '
u'executed automatically.',
DeprecationWarning, stacklevel=2)
if charsets is None:
envadapter = IUserPreferredCharsets(request, None)
if envadapter is None:
charsets = ['utf-8']
else:
charsets = envadapter.getPreferredCharsets() or ['utf-8']
for name, value in request.form.items():
if not (isCGI_NAME(name) or name.startswith('HTTP_')):
request.form[name] = processInputValue(value, charsets)
......@@ -70,6 +79,10 @@ def setPageEncoding(request):
ZPublisher uses the value of this header to determine how to
encode unicode data for the browser.
"""
warn(u'setPageEncoding() is deprecated and will be removed in Zope 2.16. '
u'It is recommended to let the ZPublisher use the default_encoding. '
u'Please consider setting default-zpublisher-encoding to utf-8.',
DeprecationWarning, stacklevel=2)
envadapter = IUserPreferredCharsets(request)
charsets = envadapter.getPreferredCharsets() or ['utf-8']
request.RESPONSE.setHeader(
......
......@@ -18,7 +18,9 @@ def test_processInputs():
"""
Testing processInputs
>>> import warnings
>>> from Products.Five.browser.decode import processInputs
>>> charsets = ['iso-8859-1']
>>> class DummyRequest:
... form = {}
......@@ -27,59 +29,75 @@ def test_processInputs():
Strings are converted to unicode::
>>> request.form['foo'] = u'f\xf6\xf6'.encode('iso-8859-1')
>>> processInputs(request, charsets)
>>> with warnings.catch_warnings():
... warnings.simplefilter('ignore')
... processInputs(request, charsets)
>>> request.form['foo'] == u'f\xf6\xf6'
True
Strings in lists are converted to unicode::
>>> request.form['foo'] = [u'f\xf6\xf6'.encode('iso-8859-1')]
>>> processInputs(request, charsets)
>>> with warnings.catch_warnings():
... warnings.simplefilter('ignore')
... processInputs(request, charsets)
>>> request.form['foo'] == [u'f\xf6\xf6']
True
Strings in tuples are converted to unicode::
>>> request.form['foo'] = (u'f\xf6\xf6'.encode('iso-8859-1'),)
>>> processInputs(request, charsets)
>>> with warnings.catch_warnings():
... warnings.simplefilter('ignore')
... processInputs(request, charsets)
>>> request.form['foo'] == (u'f\xf6\xf6',)
True
Ints in lists are not lost::
>>> request.form['foo'] = [1, 2, 3]
>>> processInputs(request, charsets)
>>> with warnings.catch_warnings():
... warnings.simplefilter('ignore')
... processInputs(request, charsets)
>>> request.form['foo'] == [1, 2, 3]
True
Ints in tuples are not lost::
>>> request.form['foo'] = (1, 2, 3,)
>>> processInputs(request, charsets)
>>> with warnings.catch_warnings():
... warnings.simplefilter('ignore')
... processInputs(request, charsets)
>>> request.form['foo'] == (1, 2, 3)
True
Mixed lists work:
>>> request.form['foo'] = [u'f\xf6\xf6'.encode('iso-8859-1'), 2, 3]
>>> processInputs(request, charsets)
>>> with warnings.catch_warnings():
... warnings.simplefilter('ignore')
... processInputs(request, charsets)
>>> request.form['foo'] == [u'f\xf6\xf6', 2, 3]
True
Mixed dicts work:
>>> request.form['foo'] = {'foo': u'f\xf6\xf6'.encode('iso-8859-1'), 'bar': 2}
>>> processInputs(request, charsets)
>>> with warnings.catch_warnings():
... warnings.simplefilter('ignore')
... processInputs(request, charsets)
>>> request.form['foo'] == {'foo': u'f\xf6\xf6', 'bar': 2}
True
Deep recursion works:
>>> request.form['foo'] = [{'foo': u'f\xf6\xf6'.encode('iso-8859-1'), 'bar': 2}, {'foo': u"one", 'bar': 3}]
>>> processInputs(request, charsets)
>>> with warnings.catch_warnings():
... warnings.simplefilter('ignore')
... processInputs(request, charsets)
>>> request.form['foo'] == [{'foo': u'f\xf6\xf6', 'bar': 2}, {'foo': u"one", 'bar': 3}]
True
"""
def test_suite():
......
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