summaryrefslogtreecommitdiff
path: root/repoze/bfg/interfaces.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-01-12 05:12:57 +0000
committerChris McDonough <chrism@agendaless.com>2009-01-12 05:12:57 +0000
commita0b40cc8aa58c557c30840c906fcba3401bb91cf (patch)
tree9c1b94a971f7394f42aed7e16b7ba49248bb7d47 /repoze/bfg/interfaces.py
parentb16527306a1ddd0ed5c0a9db78a8ffa64c42ae2e (diff)
downloadpyramid-a0b40cc8aa58c557c30840c906fcba3401bb91cf.tar.gz
pyramid-a0b40cc8aa58c557c30840c906fcba3401bb91cf.tar.bz2
pyramid-a0b40cc8aa58c557c30840c906fcba3401bb91cf.zip
- 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 <http://pypi.python.org/pypi/repoze.bfg.restrequest/1.0.1>`_ . That package is no longer required, but still functions fine.
Diffstat (limited to 'repoze/bfg/interfaces.py')
-rw-r--r--repoze/bfg/interfaces.py25
1 files changed, 24 insertions, 1 deletions
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,
+ }
+