Mercurial > hg > webob_view
annotate webob_view/template/+package+/dispatcher.py @ 2:4ebaf68f2272
moving to dispatcher as that's what it is now
author | k0s <k0scist@gmail.com> |
---|---|
date | Thu, 29 Oct 2009 15:11:05 -0400 |
parents | webob_view/template/+package+/+package+.py_tmpl@eb2cb7ebc849 |
children | 4dcb932065e4 |
rev | line source |
---|---|
0
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
1 """ |
2
4ebaf68f2272
moving to dispatcher as that's what it is now
k0s <k0scist@gmail.com>
parents:
1
diff
changeset
|
2 request dispatcher |
0
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
3 """ |
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
4 |
1 | 5 from handlers import Get, Post |
6 from webob import Request, exc | |
0
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
7 |
1 | 8 class Dispatcher(object): |
0
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
9 |
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
10 ### class level variables |
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
11 defaults = {} |
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
12 |
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
13 def __init__(self, **kw): |
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
14 for key in self.defaults: |
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
15 setattr(self, key, kw.get(key, self.defaults[key])) |
1 | 16 self.handlers = [ Get, Post ] |
0
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
17 |
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
18 ### methods dealing with HTTP |
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
19 def __call__(self, environ, start_response): |
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
20 request = Request(environ) |
1 | 21 for h in self.handlers: |
22 if h.match(request): | |
23 handler = h(request) | |
24 break | |
25 res = handler() | |
0
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
26 return res(environ, start_response) |