summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-05-31 02:17:28 +0000
committerChris McDonough <chrism@agendaless.com>2009-05-31 02:17:28 +0000
commit964b7852d997f6c4aa4b04d54f2847095e4461e8 (patch)
treec03d316200f371f04e1c2c4618d64f860c808ed3
parentaf8cbacc5466fcf9eae84564b0fa891892a986bf (diff)
downloadpyramid-964b7852d997f6c4aa4b04d54f2847095e4461e8.tar.gz
pyramid-964b7852d997f6c4aa4b04d54f2847095e4461e8.tar.bz2
pyramid-964b7852d997f6c4aa4b04d54f2847095e4461e8.zip
- Renamed ``repoze.bfg.interfaces.IForbiddenResponseFactory`` to
``repoze.bfg.interfaces.IForbiddenView``.
-rw-r--r--CHANGES.txt6
-rw-r--r--docs/narr/hooks.rst37
-rw-r--r--repoze/bfg/interfaces.py18
-rw-r--r--repoze/bfg/router.py9
-rw-r--r--repoze/bfg/tests/test_router.py6
5 files changed, 40 insertions, 36 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 8fd38ba59..1547eeb97 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,9 @@
+Next release
+============
+
+- Renamed ``repoze.bfg.interfaces.IForbiddenResponseFactory`` to
+ ``repoze.bfg.interfaces.IForbiddenView``.
+
0.9a7 (2009-05-30)
==================
diff --git a/docs/narr/hooks.rst b/docs/narr/hooks.rst
index 657ad8a67..bc00b28a7 100644
--- a/docs/narr/hooks.rst
+++ b/docs/narr/hooks.rst
@@ -124,28 +124,28 @@ sample code that implements a minimal NotFound application factory:
``debug_notfound`` environment setting is true than it is when it
is false.
-Changing the Forbidden Response
--------------------------------
+Changing the Forbidden View
+---------------------------
When :mod:`repoze.bfg` can't authorize execution of a view based on
-the authorization policy in use, it invokes a "forbidden response
-factory". Usually this forbidden response factory is a default 401
-response, but it can be overridden as necessary by placing something
-like the following ZCML in your ``configure.zcml`` file.
+the authorization policy in use, it invokes a "forbidden view". The
+default forbidden response has a 401 status code and is very plain,
+but it can be overridden as necessary by placing something like the
+following ZCML in your ``configure.zcml`` file.
.. code-block:: xml
:linenos:
- <utility provides="repoze.bfg.interfaces.IForbiddenResponseFactory"
- component="helloworld.factories.forbidden_response_factory"/>
+ <utility provides="repoze.bfg.interfaces.IForbiddenView"
+ component="helloworld.views.forbidden_view"/>
Replace ``helloworld.factories.forbidden_app_factory`` with the Python
-dotted name to the forbidden response factory you want to use. The
-response factory must accept two parameters: ``context`` and
-``request``. The ``context`` is the context found by the router when
+dotted name to the forbidden view you want to use. Like any other
+view, the forbidden view must accept two parameters: ``context`` and
+``request`` . The ``context`` is the context found by the router when
the view invocation was denied. The ``request`` is the current
:term:`request` representing the denied action. Here's some sample
-code that implements a minimal forbidden response factory:
+code that implements a minimal forbidden view:
.. code-block:: python
@@ -154,7 +154,7 @@ code that implements a minimal forbidden response factory:
def forbidden_response_factory(context, request):
return render_template_to_response('templates/login_form.pt')
-.. note:: When an forbidden response factory is invoked, it is passed
+.. note:: When an forbidden view is invoked, it is passed
the request as the second argument. An attribute of the request is
``environ``, which is the WSGI environment. Within the WSGI
environ will be a key named ``repoze.bfg.message`` that has a value
@@ -162,12 +162,11 @@ code that implements a minimal forbidden response factory:
error will be different when the ``debug_authorization``
environment setting is true than it is when it is false.
-.. warning:: the default forbidden application factory sends a
- response with a ``401 Unauthorized`` status code for backwards
- compatibility reasons. You can influence the status code of
- Forbidden responses by using an alterate forbidden application
- factory. For example, it would make sense to return an forbidden
- application with a ``403 Forbidden`` status code.
+.. warning:: the default forbidden view sends a response with a ``401
+ Unauthorized`` status code for backwards compatibility reasons.
+ You can influence the status code of Forbidden responses by using
+ an alterate forbidden view. For example, it would make sense to
+ return a response with a ``403 Forbidden`` status code.
Changing the Default Routes Context Factory
-------------------------------------------
diff --git a/repoze/bfg/interfaces.py b/repoze/bfg/interfaces.py
index bc91c6b0e..8316c58bc 100644
--- a/repoze/bfg/interfaces.py
+++ b/repoze/bfg/interfaces.py
@@ -169,15 +169,7 @@ class IContextNotFound(Interface):
""" Interface implemented by contexts generated by code which
cannot find a context during root finding or traversal """
-class INotFoundAppFactory(Interface):
- """ A utility which returns a NotFound WSGI application factory """
- def __call__():
- """ Return a callable which returns a notfound WSGI
- application. When the WSGI application is invoked,
- a``message`` key in the WSGI environ provides information
- pertaining to the reason for the notfound."""
-
-class IForbiddenResponseFactory(Interface):
+class IForbiddenView(Interface):
""" A utility which returns an IResponse as the result of the
denial of a view invocation by a security policy."""
def __call__(context, request):
@@ -192,6 +184,14 @@ class IForbiddenResponseFactory(Interface):
repoze.bfg router during traversal or url dispatch. The
``request`` will be the request object which caused the deny."""
+class INotFoundAppFactory(Interface):
+ """ A utility which returns a NotFound WSGI application factory """
+ def __call__():
+ """ Return a callable which returns a notfound WSGI
+ application. When the WSGI application is invoked,
+ a``message`` key in the WSGI environ provides information
+ pertaining to the reason for the notfound."""
+
class IUnauthorizedAppFactory(Interface):
""" A utility which returns an Unauthorized WSGI application
factory (deprecated in repoze.bfg 0.8.2) in favor of
diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py
index 8549c63da..6e6477be1 100644
--- a/repoze/bfg/router.py
+++ b/repoze/bfg/router.py
@@ -23,7 +23,7 @@ from repoze.bfg.interfaces import IRootFactory
from repoze.bfg.interfaces import IRouter
from repoze.bfg.interfaces import IRoutesMapper
from repoze.bfg.interfaces import ISettings
-from repoze.bfg.interfaces import IForbiddenResponseFactory
+from repoze.bfg.interfaces import IForbiddenView
from repoze.bfg.interfaces import IUnauthorizedAppFactory
from repoze.bfg.interfaces import IView
from repoze.bfg.interfaces import IViewPermission
@@ -78,20 +78,19 @@ class Router(object):
'Instead of registering a utility against the '
'repoze.bfg.interfaces.IUnauthorizedAppFactory interface '
'to return a custom forbidden response, you should now '
- 'register a "repoze.interfaces.IForbiddenResponseFactory". '
+ 'register a "repoze.interfaces.IForbiddenView". '
'The IUnauthorizedAppFactory interface was deprecated in '
'repoze.bfg 0.9 and will be removed in a subsequent version '
'of repoze.bfg. See the "Hooks" chapter of the repoze.bfg '
'documentation for more information about '
- 'IForbiddenResponseFactory.')
+ 'IForbiddenView.')
self.logger and self.logger.warn(warning)
def forbidden(context, request):
app = unauthorized_app_factory()
response = request.get_response(app)
return response
- forbidden = registry.queryUtility(IForbiddenResponseFactory,
- default=forbidden)
+ forbidden = registry.queryUtility(IForbiddenView, default=forbidden)
self.forbidden_resp_factory = forbidden or default_forbidden_view
diff --git a/repoze/bfg/tests/test_router.py b/repoze/bfg/tests/test_router.py
index 9a29967a3..86d7d12cf 100644
--- a/repoze/bfg/tests/test_router.py
+++ b/repoze/bfg/tests/test_router.py
@@ -137,10 +137,10 @@ class RouterTests(unittest.TestCase):
self.assertEqual(router.notfound_app_factory, app)
def test_iforbidden_responsefactory_override(self):
- from repoze.bfg.interfaces import IForbiddenResponseFactory
+ from repoze.bfg.interfaces import IForbiddenView
def app():
""" """
- self.registry.registerUtility(app, IForbiddenResponseFactory)
+ self.registry.registerUtility(app, IForbiddenView)
self._registerRootFactory(None)
router = self._makeOne()
self.assertEqual(router.forbidden_resp_factory, app)
@@ -164,7 +164,7 @@ class RouterTests(unittest.TestCase):
self.registry.registerUtility(factory, IUnauthorizedAppFactory)
router = self._makeOne()
self.assertEqual(len(logger.messages), 1)
- self.failUnless('IForbiddenResponseFactory' in logger.messages[0])
+ self.failUnless('IForbiddenView' in logger.messages[0])
class DummyRequest:
def get_response(self, app):
return app