Skip to content

Instantly share code, notes, and snippets.

@alex
Created November 16, 2010 16:19
Show Gist options
  • Save alex/702001 to your computer and use it in GitHub Desktop.
Save alex/702001 to your computer and use it in GitHub Desktop.
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