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/interfaces.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'repoze/bfg/interfaces.py') diff --git a/repoze/bfg/interfaces.py b/repoze/bfg/interfaces.py index 70d6648e3..92e906e51 100644 --- a/repoze/bfg/interfaces.py +++ b/repoze/bfg/interfaces.py @@ -29,7 +29,22 @@ deprecated( ) class IRequest(Interface): - """ Marker interface for a request object """ + """ Request type interface attached to all request objects """ + +class IPOSTRequest(IRequest): + """ Request type interface attached to POST requests""" + +class IGETRequest(IRequest): + """ Request type interface attached to GET requests""" + +class IPUTRequest(IRequest): + """ Request type interface attached to PUT requests""" + +class IDELETERequest(IRequest): + """ Request type interface attached to DELETE requests""" + +class IHEADRequest(IRequest): + """ Request type interface attached to HEAD requests""" class IResponse(Interface): status = Attribute('WSGI status code of response') @@ -149,3 +164,11 @@ class ILocation(Interface): class ILogger(Interface): """ Interface representing a PEP 282 logger """ +HTTP_METHOD_INTERFACES = { + 'GET':IGETRequest, + 'POST':IPOSTRequest, + 'PUT':IPUTRequest, + 'DELETE':IDELETERequest, + 'HEAD':IHEADRequest, + } + -- cgit v1.2.3