From 07819487b653165bff4f48d160764d69d24e787b Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 25 Oct 2009 16:05:01 +0100 Subject: extended application.StaticContent It gained the capability to server content to unknown methods. For a backwards-compatible API this has to be enabled by an optional boolean. --- wsgitools/applications.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wsgitools/applications.py b/wsgitools/applications.py index 286ab9b..63ed63c 100644 --- a/wsgitools/applications.py +++ b/wsgitools/applications.py @@ -14,7 +14,7 @@ class StaticContent: receives with method GET or HEAD (content stripped). If not present, a content-length header is computed. """ - def __init__(self, status, headers, content): + def __init__(self, status, headers, content, anymethod=False): """ @type status: str @param status: is the HTTP status returned to the browser (ex: "200 OK") @@ -24,12 +24,16 @@ class StaticContent: @type content: basestring @param content: contains the data to be delivered to the client. It is either a string or some kind of iterable yielding strings. + @type anymethod: boolean + @param anymethod: determines whether any request method should be + answered with this response instead of a 501 """ assert isinstance(status, str) assert isinstance(headers, list) assert isinstance(content, basestring) or hasattr(content, "__iter__") self.status = status self.headers = headers + self.anymethod = anymethod length = -1 if isinstance(content, basestring): self.content = [content] @@ -44,7 +48,8 @@ class StaticContent: def __call__(self, environ, start_response): """wsgi interface""" assert isinstance(environ, dict) - if environ["REQUEST_METHOD"].upper() not in ["GET", "HEAD"]: + if environ["REQUEST_METHOD"].upper() not in ["GET", "HEAD"] and \ + not self.anymethod: resp = "Request method not implemented" start_response("501 Not Implemented", [("Content-length", str(len(resp)))]) -- cgit v1.2.3