Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: multiplexer.py

Issue 6209629180657664: Issue 2169 - Unify development and production implementation of multiplexer (Closed)
Patch Set: Created March 23, 2015, 4:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « multiplexer.fcgi ('k') | sitescripts/web.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 3
4 # This file is part of the Adblock Plus web scripts, 4 # This file is part of the Adblock Plus web scripts,
5 # Copyright (C) 2006-2015 Eyeo GmbH 5 # Copyright (C) 2006-2015 Eyeo GmbH
6 # 6 #
7 # Adblock Plus is free software: you can redistribute it and/or modify 7 # Adblock Plus is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 3 as 8 # it under the terms of the GNU General Public License version 3 as
9 # published by the Free Software Foundation. 9 # published by the Free Software Foundation.
10 # 10 #
11 # Adblock Plus is distributed in the hope that it will be useful, 11 # Adblock Plus is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details. 14 # GNU General Public License for more details.
15 # 15 #
16 # You should have received a copy of the GNU General Public License 16 # You should have received a copy of the GNU General Public License
17 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 17 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
18 18
19 import re 19 from sitescripts.web import multiplex
20 import flask
21 from sitescripts.web import handlers
22 from urlparse import urlparse
23 20
24 app = flask.Flask(__name__) 21 try:
22 from werkzeug.serving import run_simple
23 except ImportError:
24 from wsgiref.simple_server import make_server
25 25
26 @app.route("/<path:path>", methods = ["GET", "POST"]) 26 def run_simple(host, port, app, **kwargs):
27 def multiplex(path): 27 server = make_server(host, port, wrapper)
28 request_url = urlparse(flask.request.url) 28 print " * Running on http://%s:%i/" % server.server_address
29 if 'SERVER_ADDR' not in flask.request.environ: 29 server.serve_forever()
30 flask.request.environ['SERVER_ADDR'] = flask.request.environ['SERVER_NAME']
31 if 'REQUEST_URI' not in flask.request.environ:
32 flask.request.environ['REQUEST_URI'] = flask.request.url
33
34 request_path = request_url.path
35 if request_path in handlers:
36 return handlers[request_path]
37 request_dir = re.sub(r'[^/]+$', '', request_path)
38 if request_dir in handlers:
39 return handlers[request_dir]
40 return flask.abort(404)
41 30
42 if __name__ == "__main__": 31 if __name__ == "__main__":
43 app.run(debug=True) 32 run_simple("localhost", 5000, multiplex, use_reloader=True, use_debugger=True)
OLDNEW
« no previous file with comments | « multiplexer.fcgi ('k') | sitescripts/web.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld