OLD | NEW |
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) |
OLD | NEW |