Mercurial > hg > uploader
annotate uploader/dispatcher.py @ 6:d2990750e5d6
fix the way query string works
author | k0s <k0scist@gmail.com> |
---|---|
date | Sun, 27 Dec 2009 16:35:48 -0500 |
parents | e5efa999911a |
children | f60ad139acc1 |
rev | line source |
---|---|
0 | 1 """ |
2 request dispatcher | |
3 """ | |
4 | |
5 import os | |
2 | 6 from handlers import Get, Post, SubpathGet, SubpathPost |
0 | 7 from webob import Request, exc |
8 | |
9 class Dispatcher(object): | |
10 | |
11 ### class level variables | |
1 | 12 defaults = { 'directory': None, |
2 | 13 'auth': 'False', |
14 'query_string': None, | |
3 | 15 'subpath': 'False', |
16 'app': None} | |
0 | 17 |
18 def __init__(self, **kw): | |
19 for key in self.defaults: | |
20 setattr(self, key, kw.get(key, self.defaults[key])) | |
21 assert os.path.exists(self.directory) | |
4
e5efa999911a
make sure self.app is actually callable
k0s <k0scist@gmail.com>
parents:
3
diff
changeset
|
22 if self.app: |
e5efa999911a
make sure self.app is actually callable
k0s <k0scist@gmail.com>
parents:
3
diff
changeset
|
23 assert hasattr(self.app, '__call__') |
1 | 24 self.auth = self.auth.lower() == 'true' |
2 | 25 self.subpath = self.subpath.lower() == 'true' |
26 if self.subpath: | |
6 | 27 self.handlers = [ SubpathGet, SubpathPost ] |
2 | 28 else: |
29 self.handlers = [ Get, Post ] | |
0 | 30 |
31 ### methods dealing with HTTP | |
32 def __call__(self, environ, start_response): | |
33 request = Request(environ) | |
1 | 34 if self.auth and not request.remote_user: |
35 return exc.HTTPUnauthorized()(environ, start_response) | |
0 | 36 for h in self.handlers: |
2 | 37 if h.match(self, request): |
0 | 38 handler = h(self, request) |
39 break | |
40 else: | |
3 | 41 if self.app: |
42 return self.app(environ, start_response) | |
0 | 43 handler = exc.HTTPNotFound |
44 res = handler() | |
45 return res(environ, start_response) |