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. """ assert isinstance(status, str) assert isinstance(headers, list) assert hasattr(content, "__iter__") 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""" assert isinstance(environ, dict) start_response(self.status, self.headers) if environ["REQUEST_METHOD"].upper() == "HEAD": return [] return self.content