Mercurial > hg > wsgintegrate
annotate wsgintegrate/dispatcher.py @ 15:1a7bbd97dda4
work around a horrible downstream issue
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 17 Nov 2011 11:49:41 -0800 |
parents | e07b0f675c17 |
children | d742aff49859 |
rev | line source |
---|---|
0
ec815b7cb142
initial commit of wsgintegrate
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 """ |
ec815b7cb142
initial commit of wsgintegrate
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 multi-application dispatcher for WSGI apps |
ec815b7cb142
initial commit of wsgintegrate
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 """ |
ec815b7cb142
initial commit of wsgintegrate
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 |
ec815b7cb142
initial commit of wsgintegrate
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 from webob import Request |
ec815b7cb142
initial commit of wsgintegrate
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 from webob import exc |
ec815b7cb142
initial commit of wsgintegrate
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 |
ec815b7cb142
initial commit of wsgintegrate
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 class Dispatcher(object): |
ec815b7cb142
initial commit of wsgintegrate
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 |
14 | 10 def __init__(self, *apps): |
11 self.apps = apps | |
12 self.codes = set([404]) | |
0
ec815b7cb142
initial commit of wsgintegrate
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 |
14 | 14 def __call__(self, environ, start_response): |
15 request = Request(environ) | |
16 for app in self.apps: | |
17 try: | |
18 response = request.get_response(app) | |
19 if response.status_int in self.codes: | |
20 continue | |
21 break | |
22 except exc.HTTPNotFound: | |
23 continue | |
24 except: | |
25 print app | |
26 raise | |
27 else: | |
28 response = exc.HTTPNotFound() | |
15
1a7bbd97dda4
work around a horrible downstream issue
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
29 try: |
1a7bbd97dda4
work around a horrible downstream issue
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
30 return response(environ, start_response) |
1a7bbd97dda4
work around a horrible downstream issue
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
31 except: |
1a7bbd97dda4
work around a horrible downstream issue
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
32 response.headerlist = [(i,str(j)) for i, j in response.headerlist] |
1a7bbd97dda4
work around a horrible downstream issue
Jeff Hammel <jhammel@mozilla.com>
parents:
14
diff
changeset
|
33 return response(environ, start_response) |
14 | 34 |