summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2010-09-15 00:16:54 +0000
committerChris McDonough <chrism@agendaless.com>2010-09-15 00:16:54 +0000
commit2d79938483a98ce293f533d5258dbdc85b2d59a8 (patch)
tree72421c729d4ee874f7e0083c39fe8171b0376c83
parentb81374bf0295b1fb2e5b094f5fc64a7748be703c (diff)
downloadpyramid-2d79938483a98ce293f533d5258dbdc85b2d59a8.tar.gz
pyramid-2d79938483a98ce293f533d5258dbdc85b2d59a8.tar.bz2
pyramid-2d79938483a98ce293f533d5258dbdc85b2d59a8.zip
Features
-------- - Compatibility with WebOb 1.0. Requirements ------------ - Now requires WebOb >= 1.0. Backwards Incompatibilities --------------------------- - Due to changes introduced WebOb 1.0, the ``repoze.bfg.request.make_request_ascii`` event subscriber no longer works, so it has been removed. This subscriber was meant to be used in a deployment so that code written before BFG 0.7.0 could run unchanged. At this point, such code will need to be rewritten to expect Unicode from ``request.GET``, ``request.POST`` and ``request.params`` or it will need to be changed to use ``request.str_POST``, ``request.str_GET`` and/or ``request.str_params`` instead of the non-``str`` versions of same, as the non-``str`` versions of the same APIs always now perform decoding to Unicode.
-rw-r--r--CHANGES.txt25
-rw-r--r--docs/api/request.rst3
-rw-r--r--docs/narr/views.rst31
-rw-r--r--repoze/bfg/request.py10
-rw-r--r--repoze/bfg/tests/test_request.py23
-rw-r--r--setup.py2
6 files changed, 39 insertions, 55 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 695aca255..9dbb5a0cb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,31 @@ Bug Fixes
``set_notfound_view`` or ``set_forbidden_view`` APIs, the context
sent to the view was incorrect (could be ``None`` inappropriately).
+Features
+--------
+
+- Compatibility with WebOb 1.0.
+
+Requirements
+------------
+
+- Now requires WebOb >= 1.0.
+
+Backwards Incompatibilities
+---------------------------
+
+- Due to changes introduced WebOb 1.0, the
+ ``repoze.bfg.request.make_request_ascii`` event subscriber no longer
+ works, so it has been removed. This subscriber was meant to be used
+ in a deployment so that code written before BFG 0.7.0 could run
+ unchanged. At this point, such code will need to be rewritten to
+ expect Unicode from ``request.GET``, ``request.POST`` and
+ ``request.params`` or it will need to be changed to use
+ ``request.str_POST``, ``request.str_GET`` and/or
+ ``request.str_params`` instead of the non-``str`` versions of same,
+ as the non-``str`` versions of the same APIs always now perform
+ decoding to Unicode.
+
Errata
------
diff --git a/docs/api/request.rst b/docs/api/request.rst
index 08d8d76e1..c37565ccd 100644
--- a/docs/api/request.rst
+++ b/docs/api/request.rst
@@ -88,6 +88,3 @@
.. note:: The exception attribute is new in :mod:`repoze.bfg`
1.3.
-.. autofunction:: make_request_ascii
-
-
diff --git a/docs/narr/views.rst b/docs/narr/views.rst
index 5b55e7e12..1212d1a7f 100644
--- a/docs/narr/views.rst
+++ b/docs/narr/views.rst
@@ -1011,7 +1011,7 @@ decode already-decoded (``unicode``) values obtained from
firstname = request.params['firstname'].decode('utf-8')
lastname = request.params['lastname'].decode('utf-8')
-For implicit decoding to work reliably, you must ensure that every
+For implicit decoding to work reliably, youshould ensure that every
form you render that posts to a :mod:`repoze.bfg` view is rendered via
a response that has a ``;charset=UTF-8`` in its ``Content-Type``
header; or, as in the form above, with a ``meta http-equiv`` tag that
@@ -1041,25 +1041,16 @@ you for response content types that are textual (e.g. ``text/html``,
``application/xml``, etc) as it is rendered. If you are using your
own response object, you will need to ensure you do this yourself.
-To avoid implicit form submission value decoding, so that the values
-returned from ``request.params``, ``request.GET`` and ``request.POST``
-are returned as bytestrings rather than Unicode, add the following to
-your application's ``configure.zcml``::
-
- <subscriber for="repoze.bfg.interfaces.INewRequest"
- handler="repoze.bfg.request.make_request_ascii"/>
-
-You can then control form post data decoding "by hand" as necessary.
-For example, when this subscriber is active, the second example above
-will work unconditionally as long as you ensure that your forms are
-rendered in a request that has a ``;charset=utf-8`` stanza on its
-``Content-Type`` header.
-
-.. note:: The behavior that form values are decoded from UTF-8 to
- Unicode implicitly was introduced in :mod:`repoze.bfg` 0.7.0.
- Previous versions of :mod:`repoze.bfg` performed no implicit
- decoding of form values (the default was to treat values as
- bytestrings).
+.. note:: The behavior that form values are decoded to Unicode
+ implicitly when no content type header exists was introduced in
+ :mod:`repoze.bfg` 0.7.0. Previous versions of :mod:`repoze.bfg`
+ performed no implicit decoding of form values: it returned the
+ values from ``request.GET``, ``request.POST`` and
+ ``request.params`` as bytestrings. Code written before 0.7.0 that
+ depended on the values from ``request.params``, ``request.GET`` and
+ ``request.POST`` being returned as bytestrings must at this point
+ be rewritten to use ``request.str_params``, ``request.str_GET`` or
+ ``request.str_POST``, which indeed will return bytestrings.
.. note:: Only the *values* of request params obtained via
``request.params``, ``request.GET`` or ``request.POST`` are decoded
diff --git a/repoze/bfg/request.py b/repoze/bfg/request.py
index 851962446..f32a7a40c 100644
--- a/repoze/bfg/request.py
+++ b/repoze/bfg/request.py
@@ -6,15 +6,6 @@ from webob import Request as WebobRequest
from repoze.bfg.interfaces import IRequest
-def make_request_ascii(event):
- """ An function that is useful as a
- :class:`repoze.bfg.interfaces.INewRequest` :term:`event`
- :term:`subscriber` that causes the request charset to be ASCII so
- code written before :mod:`repoze.bfg` 0.7.0 can continue to work
- without a change"""
- request = event.request
- request.default_charset = None
-
class Request(WebobRequest):
"""
A subclass of the :term:`WebOb` Request class. An instance of
@@ -41,7 +32,6 @@ class Request(WebobRequest):
response_callbacks = ()
finished_callbacks = ()
exception = None
- default_charset = 'utf-8'
def add_response_callback(self, callback):
"""
diff --git a/repoze/bfg/tests/test_request.py b/repoze/bfg/tests/test_request.py
index 87585c301..d2b6679d3 100644
--- a/repoze/bfg/tests/test_request.py
+++ b/repoze/bfg/tests/test_request.py
@@ -1,16 +1,5 @@
import unittest
-class TestMakeRequestASCII(unittest.TestCase):
- def _callFUT(self, event):
- from repoze.bfg.request import make_request_ascii
- return make_request_ascii(event)
-
- def test_it(self):
- request = DummyRequest()
- event = DummyNewRequestEvent(request)
- self._callFUT(event)
- self.assertEqual(request.default_charset, None)
-
class TestRequest(unittest.TestCase):
def _makeOne(self, environ):
return self._getTargetClass()(environ)
@@ -21,7 +10,7 @@ class TestRequest(unittest.TestCase):
def test_charset_defaults_to_utf8(self):
r = self._makeOne({'PATH_INFO':'/'})
- self.assertEqual(r.charset, 'utf-8')
+ self.assertEqual(r.charset, 'UTF-8')
def test_exception_defaults_to_None(self):
r = self._makeOne({'PATH_INFO':'/'})
@@ -33,17 +22,9 @@ class TestRequest(unittest.TestCase):
'QUERY_STRING':'la=La%20Pe%C3%B1a'
}
request = self._makeOne(environ)
+ request.charset = None
self.assertEqual(request.GET['la'], u'La Pe\xf1a')
- def test_params_bystring_when_default_charset_is_None(self):
- environ = {
- 'PATH_INFO':'/',
- 'QUERY_STRING':'la=La%20Pe%C3%B1a'
- }
- request = self._makeOne(environ)
- request.default_charset = None
- self.assertEqual(request.GET['la'], 'La Pe\xc3\xb1a')
-
def test_class_implements(self):
from repoze.bfg.interfaces import IRequest
klass = self._getTargetClass()
diff --git a/setup.py b/setup.py
index 17db104cc..5ee71d6e9 100644
--- a/setup.py
+++ b/setup.py
@@ -32,7 +32,7 @@ install_requires=[
'Paste > 1.7', # temp version pin to prevent PyPi install failure :-(
'PasteDeploy',
'PasteScript',
- 'WebOb >= 0.9.7', # "default_charset"
+ 'WebOb >= 1.0', # no "default_charset"
'repoze.lru',
'setuptools',
'zope.component >= 3.6.0', # independent of zope.hookable