diff options
author | Helmut Grohne <helmut@subdivi.de> | 2007-04-14 22:37:26 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2007-04-14 22:37:26 +0200 |
commit | 2435f82361f6bc4dcd51e1305905ecbbb5757f50 (patch) | |
tree | df738a4ffdbd212383b6d8df22cb3b74e1fc83f9 /wsgitools/applications.py | |
download | wsgitools-2435f82361f6bc4dcd51e1305905ecbbb5757f50.tar.gz |
initial tree
Diffstat (limited to 'wsgitools/applications.py')
-rw-r--r-- | wsgitools/applications.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/wsgitools/applications.py b/wsgitools/applications.py new file mode 100644 index 0000000..1e2b435 --- /dev/null +++ b/wsgitools/applications.py @@ -0,0 +1,27 @@ +class StaticContent: + """This wsgi application provides static content on whatever request it + receives.""" + def __init__(self, status, headers, content): + """status is the HTTP status returned to the browser (ex: "200 OK") + headers is a list of (header, value) pairs being delivered as HTTP + headers + content contains the data to be delivered to the client. It is either a + string or some kind of iterable yielding strings. + """ + self.status = status + self.headers = headers + length = -1 + if isinstance(content, basestring): + self.content = [content] + length = len(content) + else: + self.content = content + if isinstance(self.content, list): + length = sum(map(len, self.content)) + if length >= 0: + if not [v for h, v in headers if h.lower() == "content-length"]: + headers.append(("Content-length", str(length))) + def __call__(self, environ, start_response): + """wsgi interface""" + start_response(self.status, self.headers) + return self.content |