# HG changeset patch # User Jeff Hammel # Date 1292434232 28800 # Node ID 613ffeec2be58b9103b0320a06828d9dc91c6ece # Parent 9c570aed2246a061e7b5d697fa2f0d81875fbef7 return exceptions rather than just raise them; needed for wsgiref and who knows what other servers diff -r 9c570aed2246 -r 613ffeec2be5 decoupage/web.py --- a/decoupage/web.py Tue Dec 14 22:03:50 2010 -0800 +++ b/decoupage/web.py Wed Dec 15 09:30:32 2010 -0800 @@ -96,19 +96,27 @@ ### methods dealing with HTTP + def __call__(self, environ, start_response): + + # boilerplate: request and filename request = Request(environ) filename = request.path_info.strip('/') path = os.path.join(self.directory, filename) - if os.path.exists(path): - if os.path.isdir(path): - if not request.path_info.endswith('/'): - raise exc.HTTPMovedPermanently(add_slash=True) + # check to see what we have to serve + if os.path.exists(path): + + if os.path.isdir(path): + # serve an index + if request.path_info.endswith('/'): + res = self.get(request) + else: + res = exc.HTTPMovedPermanently(add_slash=True) + return res(environ, start_response) - res = self.get(request) - return res(environ, start_response) else: + # serve a file conf = self.conf(request.path_info.rsplit('/',1)[0]) if '/transformer' in conf: args = [i.split('=', 1) for i in conf['/transformer'].split(',') if '=' in i] @@ -125,7 +133,9 @@ fileserver = fileserver(path) return fileserver(environ, start_response) else: - raise exc.HTTPNotFound() + # file does not exist + response = exc.HTTPNotFound() + return response(environ, start_response) def get(self, request):