From a0b40cc8aa58c557c30840c906fcba3401bb91cf Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 12 Jan 2009 05:12:57 +0000 Subject: - An interface specific to the HTTP verb (GET/PUT/POST/DELETE/HEAD) is attached to each request object on ingress. The HTTP-verb-related interfaces are defined in ``repoze.bfg.interfaces`` and are ``IGETRequest``, ``IPOSTRequest``, ``IPUTRequest``, ``IDELETERequest`` and ``IHEADRequest``. These interfaces can be specified as the ``request_type`` attribute of a bfg view declaration. A view naming a specific HTTP-verb-matching interface will be found only if the view is defined with a request_type that matches the HTTP verb in the incoming request. The more general ``IRequest`` interface can be used as the request_type to catch all requests (and this is indeed the default). All requests implement ``IRequest``. The HTTP-verb-matching idea was pioneered by `repoze.bfg.restrequest `_ . That package is no longer required, but still functions fine. --- repoze/bfg/router.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'repoze/bfg/router.py') diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py index ffbd853dc..8e1b998d8 100644 --- a/repoze/bfg/router.py +++ b/repoze/bfg/router.py @@ -7,6 +7,7 @@ from zope.component import queryUtility from zope.component.event import dispatch from zope.interface import directlyProvides +from zope.interface import alsoProvides from zope.interface import implements from webob import Request @@ -20,6 +21,8 @@ from repoze.bfg.events import WSGIApplicationCreatedEvent from repoze.bfg.interfaces import ILogger from repoze.bfg.interfaces import ITraverserFactory from repoze.bfg.interfaces import IRequest +from repoze.bfg.interfaces import HTTP_METHOD_INTERFACES + from repoze.bfg.interfaces import IRouter from repoze.bfg.interfaces import IRootFactory from repoze.bfg.interfaces import ISettings @@ -52,9 +55,13 @@ class Router(object): try: request = Request(environ) + directlyProvides(request, IRequest) - dispatch(NewRequest(request)) + also = HTTP_METHOD_INTERFACES.get(request.method) + if also is not None: + alsoProvides(request, also) + dispatch(NewRequest(request)) root_factory = getUtility(IRootFactory) root = root_factory(environ) traverser = getAdapter(root, ITraverserFactory) -- cgit v1.2.3