Chris McDonough
2011-06-20 d69ae60b9a195c7cb72122b59335ba886bfffe50
- Register the default exception view for context of
webob.exc.WSGIHTTPException (convenience).

- Use ``exc.message`` in docs rather than ``exc.args[0]`` now that
we control this.
5 files modified
20 ■■■■■ changed files
TODO.txt 5 ●●●●● patch | view | raw | blame | history
docs/narr/hooks.rst 7 ●●●●● patch | view | raw | blame | history
pyramid/config.py 3 ●●●●● patch | view | raw | blame | history
pyramid/httpexceptions.py 2 ●●● patch | view | raw | blame | history
pyramid/tests/test_config.py 3 ●●●●● patch | view | raw | blame | history
TODO.txt
@@ -4,11 +4,6 @@
Must-Have
---------
- Grep for IExceptionResponse, forgot what it does.
- Docs mention ``exception.args[0]`` as a way to get messages; check that
  this works.
- Deprecate response_foo attrs on request at attribute set time rather than
  lookup time.
docs/narr/hooks.rst
@@ -59,7 +59,7 @@
   :term:`request`.  The ``exception`` attribute of the request will be an
   instance of the :exc:`~pyramid.httpexceptions.HTTPNotFound` exception that
   caused the not found view to be called.  The value of
   ``request.exception.args[0]`` will be a value explaining why the not found
   ``request.exception.message`` will be a value explaining why the not found
   error was raised.  This message will be different when the
   ``debug_notfound`` environment setting is true than it is when it is
   false.
@@ -125,8 +125,9 @@
   :term:`request`.  The ``exception`` attribute of the request will be an
   instance of the :exc:`~pyramid.httpexceptions.HTTPForbidden` exception
   that caused the forbidden view to be called.  The value of
   ``request.exception.args[0]`` will be a value explaining why the forbidden
   was raised.  This message will be different when the
   ``request.exception.message`` will be a value explaining why the forbidden
   was raised and ``request.exception.result`` will be extended information
   about the forbidden exception.  These messages will be different when the
   ``debug_authorization`` environment setting is true than it is when it is
   false.
pyramid/config.py
@@ -713,6 +713,8 @@
        self._set_root_factory(root_factory)
        # cope with WebOb response objects that aren't decorated with IResponse
        from webob import Response as WebobResponse
        # cope with WebOb exc objects not decoratored with IExceptionResponse
        from webob.exc import WSGIHTTPException as WebobWSGIHTTPException
        registry.registerSelfAdapter((WebobResponse,), IResponse)
        debug_logger = self.maybe_dotted(debug_logger)
        if debug_logger is None:
@@ -726,6 +728,7 @@
        if exceptionresponse_view is not None:
            exceptionresponse_view = self.maybe_dotted(exceptionresponse_view)
            self.add_view(exceptionresponse_view, context=IExceptionResponse)
            self.add_view(exceptionresponse_view,context=WebobWSGIHTTPException)
        if locale_negotiator:
            locale_negotiator = self.maybe_dotted(locale_negotiator)
            registry.registerUtility(locale_negotiator, ILocaleNegotiator)
pyramid/httpexceptions.py
@@ -994,7 +994,7 @@
        # config.set_notfound_view or config.set_forbidden_view
        # instead of as a proper exception view
        context = request.exception or context
    return context
    return context # assumed to be an IResponse
status_map={}
code = None
pyramid/tests/test_config.py
@@ -339,6 +339,7 @@
        self.assertEqual(reg.has_listeners, True)
    def test_setup_registry_registers_default_exceptionresponse_view(self):
        from webob.exc import WSGIHTTPException
        from pyramid.interfaces import IExceptionResponse
        from pyramid.view import default_exceptionresponse_view
        reg = DummyRegistry()
@@ -348,6 +349,8 @@
        config.setup_registry()
        self.assertEqual(views[0], ((default_exceptionresponse_view,),
                                    {'context':IExceptionResponse}))
        self.assertEqual(views[1], ((default_exceptionresponse_view,),
                                    {'context':WSGIHTTPException}))
    def test_setup_registry_registers_default_webob_iresponse_adapter(self):
        from webob import Response