Mercurial > hg > decoupage
changeset 64:613ffeec2be5
return exceptions rather than just raise them; needed for wsgiref and who knows what other servers
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 15 Dec 2010 09:30:32 -0800 |
parents | 9c570aed2246 |
children | ac1dc088e37e |
files | decoupage/web.py |
diffstat | 1 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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):