Created
November 16, 2010 16:19
-
-
Save alex/702001 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import traceback | |
class WebApp(object): | |
def __init__(self, obj): | |
self.obj = obj | |
def __call__(self, environ, start_response): | |
try: | |
path = filter(bool, environ["PATH_INFO"].split("/")) | |
try: | |
method = path.pop(0) | |
except IndexError: | |
res = self.obj | |
else: | |
res = getattr(self.obj, method)(*path) | |
start_response("200 OK", {}) | |
return [str(res)] | |
except Exception: | |
start_response("500 INTERNAL SERVER ERROR", {}) | |
return [traceback.format_exc()] | |
application = WebApp([]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment