diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-04-11 18:35:40 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-04-11 18:35:40 +0000 |
| commit | 77a146c26fab9594b4a401fc44f1ee5b8373bbea (patch) | |
| tree | be1270ae2f1b291760070a799d215175fa1230e7 /repoze/bfg/request.py | |
| parent | 012f0e34d6e2f3238b0e5d16d045f292579d3822 (diff) | |
| download | pyramid-77a146c26fab9594b4a401fc44f1ee5b8373bbea.tar.gz pyramid-77a146c26fab9594b4a401fc44f1ee5b8373bbea.tar.bz2 pyramid-77a146c26fab9594b4a401fc44f1ee5b8373bbea.zip | |
- 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``::
<subscriber for="repoze.bfg.interfaces.INewRequest"
handler="repoze.bfg.request.make_request_ascii"/>
See also the documentation in the "Views" chapter of the BFG docs
entitled "Using Views to Handle Form Submissions (Unicode and
Character Set Issues)".
Diffstat (limited to 'repoze/bfg/request.py')
| -rw-r--r-- | repoze/bfg/request.py | 19 |
1 files changed, 16 insertions, 3 deletions
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, |
