comparison simplewiki/handlers.py @ 4:dd1c4916cbcd

[mq]: fileserver
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 07 Sep 2010 22:39:15 -0700
parents 56ab6b90cd1a
children b2fbb4f982da
comparison
equal deleted inserted replaced
3:56ab6b90cd1a 4:dd1c4916cbcd
2 request handlers: 2 request handlers:
3 these are instantiated for every request, then called 3 these are instantiated for every request, then called
4 """ 4 """
5 5
6 import os 6 import os
7 from paste.fileapp import FileApp
7 from urlparse import urlparse 8 from urlparse import urlparse
8 from webob import Response, exc 9 from webob import Response, exc
9 10
10 class HandlerMatchException(Exception): 11 class HandlerMatchException(Exception):
11 """the handler doesn't match the request""" 12 """the handler doesn't match the request"""
140 f.write(self.file.file.read()) 141 f.write(self.file.file.read())
141 f.close() 142 f.close()
142 143
143 def __call__(self): 144 def __call__(self):
144 self.redirect(self.location) 145 self.redirect(self.location)
146
147 class FileServer(Handler):
148 methods = set(['GET']) # methods to listen to
149
150 def __init__(self, app, request):
151 Handler.__init__(self, app, request)
152 self.file = os.path.join(self.app.directory, *request.environ['path'])
153 if not os.path.exists(self.file):
154 raise HandlerMatchException
155
156 def __call__(self):
157 return FileApp(self.file)
158