From 77a146c26fab9594b4a401fc44f1ee5b8373bbea Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 11 Apr 2009 18:35:40 +0000 Subject: - The default request charset encoding is now ``utf-8``. As a result, the request machinery will attempt to decode values from the utf-8 encoding to Unicode automatically when they are obtained via ``request.params``, ``request.GET``, and ``request.POST``. The previous behavior of BFG was to return a bytestring when a value was accessed in this manner. This change will break form handling code in apps that rely on values from those APIs being considered bytestrings. If you are manually decoding values from form submissions in your application, you'll either need to change the code that does that to expect Unicode values from ``request.params``, ``request.GET`` and ``request.POST``, or you'll need to explicitly reenable the previous behavior. To reenable the previous behavior, add the following to your application's ``configure.zcml``:: See also the documentation in the "Views" chapter of the BFG docs entitled "Using Views to Handle Form Submissions (Unicode and Character Set Issues)". --- repoze/bfg/request.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'repoze/bfg/request.py') diff --git a/repoze/bfg/request.py b/repoze/bfg/request.py index 8d938e974..de5711e0a 100644 --- a/repoze/bfg/request.py +++ b/repoze/bfg/request.py @@ -3,6 +3,17 @@ from webob import Request as WebobRequest import repoze.bfg.interfaces +def make_request_ascii(event): + """ An event handler that causes the request charset to be ASCII; + used as an INewRequest subscriber so code written before 0.7.0 can + continue to work without a change""" + request = event.request + request.charset = None + +class Request(WebobRequest): + implements(repoze.bfg.interfaces.IRequest) + charset = 'utf-8' + # We use 'precooked' Request subclasses that correspond to HTTP # request methods within ``router.py`` when constructing a request # object rather than using ``alsoProvides`` to attach the proper @@ -13,23 +24,25 @@ import repoze.bfg.interfaces # ``HTTP_METHOD_FACTORIES`` lookup dict should be imported directly by # user code. -class Request(WebobRequest): - implements(repoze.bfg.interfaces.IRequest) - class GETRequest(WebobRequest): implements(repoze.bfg.interfaces.IGETRequest) + charset = 'utf-8' class POSTRequest(WebobRequest): implements(repoze.bfg.interfaces.IPOSTRequest) + charset = 'utf-8' class PUTRequest(WebobRequest): implements(repoze.bfg.interfaces.IPUTRequest) + charset = 'utf-8' class DELETERequest(WebobRequest): implements(repoze.bfg.interfaces.IDELETERequest) + charset = 'utf-8' class HEADRequest(WebobRequest): implements(repoze.bfg.interfaces.IHEADRequest) + charset = 'utf-8' HTTP_METHOD_FACTORIES = { 'GET':GETRequest, -- cgit v1.2.3