Mercurial > hg > webob_view
annotate webob_view/template/+package+/+package+.py_tmpl @ 1:eb2cb7ebc849
moving to a handler architecture
author | k0s <k0scist@gmail.com> |
---|---|
date | Thu, 29 Oct 2009 15:08:54 -0400 |
parents | 72cb6dc31e3f |
children |
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 """ |
72cb6dc31e3f
initial commit of webob_view from https://svn.openplans.org/svn/standalone/templates/webob_view/trunk/
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
2 ${repr(project)}: a view with webob |
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) |