Commit c2e643f9 authored by 's avatar

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

parent 92047edf
...@@ -54,6 +54,10 @@ Features Added ...@@ -54,6 +54,10 @@ Features Added
Restructuring 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 - Factored out the `Products.ZCatalog` and `Products.PluginIndexes` packages
into a new `Products.ZCatalog` distribution. into a new `Products.ZCatalog` distribution.
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
encoding. encoding.
""" """
from warnings import warn
from zope.publisher.browser import isCGI_NAME from zope.publisher.browser import isCGI_NAME
from zope.i18n.interfaces import IUserPreferredCharsets from zope.i18n.interfaces import IUserPreferredCharsets
...@@ -34,7 +36,10 @@ def processInputValue(value, charsets): ...@@ -34,7 +36,10 @@ def processInputValue(value, charsets):
"""Recursively look for values (e.g. elements of lists, tuples or dicts) """Recursively look for values (e.g. elements of lists, tuples or dicts)
and attempt to decode. 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): if isinstance(value, list):
return [processInputValue(v, charsets) for v in value] return [processInputValue(v, charsets) for v in value]
elif isinstance(value, tuple): elif isinstance(value, tuple):
...@@ -53,14 +58,18 @@ def processInputs(request, charsets=None): ...@@ -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 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. 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: if charsets is None:
envadapter = IUserPreferredCharsets(request, None) envadapter = IUserPreferredCharsets(request, None)
if envadapter is None: if envadapter is None:
charsets = ['utf-8'] charsets = ['utf-8']
else: else:
charsets = envadapter.getPreferredCharsets() or ['utf-8'] charsets = envadapter.getPreferredCharsets() or ['utf-8']
for name, value in request.form.items(): for name, value in request.form.items():
if not (isCGI_NAME(name) or name.startswith('HTTP_')): if not (isCGI_NAME(name) or name.startswith('HTTP_')):
request.form[name] = processInputValue(value, charsets) request.form[name] = processInputValue(value, charsets)
...@@ -70,6 +79,10 @@ def setPageEncoding(request): ...@@ -70,6 +79,10 @@ def setPageEncoding(request):
ZPublisher uses the value of this header to determine how to ZPublisher uses the value of this header to determine how to
encode unicode data for the browser. 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) envadapter = IUserPreferredCharsets(request)
charsets = envadapter.getPreferredCharsets() or ['utf-8'] charsets = envadapter.getPreferredCharsets() or ['utf-8']
request.RESPONSE.setHeader( request.RESPONSE.setHeader(
......
...@@ -18,7 +18,9 @@ def test_processInputs(): ...@@ -18,7 +18,9 @@ def test_processInputs():
""" """
Testing processInputs Testing processInputs
>>> import warnings
>>> from Products.Five.browser.decode import processInputs >>> from Products.Five.browser.decode import processInputs
>>> charsets = ['iso-8859-1'] >>> charsets = ['iso-8859-1']
>>> class DummyRequest: >>> class DummyRequest:
... form = {} ... form = {}
...@@ -27,59 +29,75 @@ def test_processInputs(): ...@@ -27,59 +29,75 @@ def test_processInputs():
Strings are converted to unicode:: Strings are converted to unicode::
>>> request.form['foo'] = u'f\xf6\xf6'.encode('iso-8859-1') >>> 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' >>> request.form['foo'] == u'f\xf6\xf6'
True True
Strings in lists are converted to unicode:: Strings in lists are converted to unicode::
>>> request.form['foo'] = [u'f\xf6\xf6'.encode('iso-8859-1')] >>> 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'] >>> request.form['foo'] == [u'f\xf6\xf6']
True True
Strings in tuples are converted to unicode:: Strings in tuples are converted to unicode::
>>> request.form['foo'] = (u'f\xf6\xf6'.encode('iso-8859-1'),) >>> 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',) >>> request.form['foo'] == (u'f\xf6\xf6',)
True True
Ints in lists are not lost:: Ints in lists are not lost::
>>> request.form['foo'] = [1, 2, 3] >>> 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] >>> request.form['foo'] == [1, 2, 3]
True True
Ints in tuples are not lost:: Ints in tuples are not lost::
>>> request.form['foo'] = (1, 2, 3,) >>> 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) >>> request.form['foo'] == (1, 2, 3)
True True
Mixed lists work: Mixed lists work:
>>> request.form['foo'] = [u'f\xf6\xf6'.encode('iso-8859-1'), 2, 3] >>> 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] >>> request.form['foo'] == [u'f\xf6\xf6', 2, 3]
True True
Mixed dicts work: Mixed dicts work:
>>> request.form['foo'] = {'foo': u'f\xf6\xf6'.encode('iso-8859-1'), 'bar': 2} >>> 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} >>> request.form['foo'] == {'foo': u'f\xf6\xf6', 'bar': 2}
True True
Deep recursion works: Deep recursion works:
>>> request.form['foo'] = [{'foo': u'f\xf6\xf6'.encode('iso-8859-1'), 'bar': 2}, {'foo': u"one", 'bar': 3}] >>> 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}] >>> request.form['foo'] == [{'foo': u'f\xf6\xf6', 'bar': 2}, {'foo': u"one", 'bar': 3}]
True True
""" """
def test_suite(): 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