OLD | NEW |
1 from flask import Flask, request | 1 #!/usr/bin/env python |
| 2 # coding: utf-8 |
| 3 |
| 4 # This Source Code is subject to the terms of the Mozilla Public License |
| 5 # version 2.0 (the "License"). You can obtain a copy of the License at |
| 6 # http://mozilla.org/MPL/2.0/. |
| 7 |
| 8 import flask |
2 from sitescripts.web import handlers | 9 from sitescripts.web import handlers |
3 from urlparse import urlparse | 10 from urlparse import urlparse |
4 | 11 |
5 app = Flask(__name__) | 12 app = flask.Flask(__name__) |
6 | 13 |
7 @app.route("/<path:path>") | 14 @app.route("/<path:path>", methods = ["GET", "POST"]) |
8 def multiplex(path): | 15 def multiplex(path): |
9 requestUrl = urlparse(request.url) | 16 request_url = urlparse(flask.request.url) |
10 print requestUrl.query | 17 request_path = request_url.path |
11 requestPath = requestUrl.path | 18 if request_path in handlers: |
12 if requestPath in handlers: | 19 if 'SERVER_ADDR' not in flask.request.environ: |
13 # TODO: Some more environ entries are required for all scripts to work. | 20 flask.request.environ['SERVER_ADDR'] = flask.request.environ['SERVER_NAME'
] |
14 environ = {"QUERY_STRING": requestUrl.query} | 21 return handlers[request_path] |
15 # TODO: Actually return the supplied status/headers. | 22 return flask.abort(404) |
16 start_response = lambda status, headers: None | |
17 return handlers[requestPath](environ, start_response) | |
18 return "" | |
19 | 23 |
20 if __name__ == "__main__": | 24 if __name__ == "__main__": |
21 app.run(debug=True) | 25 app.run(debug=True) |
OLD | NEW |