| Index: multiplexer.py |
| =================================================================== |
| old mode 100644 |
| new mode 100755 |
| --- a/multiplexer.py |
| +++ b/multiplexer.py |
| @@ -1,21 +1,25 @@ |
| -from flask import Flask, request |
| +#!/usr/bin/env python |
| +# coding: utf-8 |
| + |
| +# This Source Code is subject to the terms of the Mozilla Public License |
| +# version 2.0 (the "License"). You can obtain a copy of the License at |
| +# http://mozilla.org/MPL/2.0/. |
| + |
| +import flask |
| from sitescripts.web import handlers |
| from urlparse import urlparse |
| -app = Flask(__name__) |
| +app = flask.Flask(__name__) |
| -@app.route("/<path:path>") |
| +@app.route("/<path:path>", methods = ["GET", "POST"]) |
| def multiplex(path): |
| - requestUrl = urlparse(request.url) |
| - print requestUrl.query |
| - requestPath = requestUrl.path |
| - if requestPath in handlers: |
| - # TODO: Some more environ entries are required for all scripts to work. |
| - environ = {"QUERY_STRING": requestUrl.query} |
| - # TODO: Actually return the supplied status/headers. |
| - start_response = lambda status, headers: None |
| - return handlers[requestPath](environ, start_response) |
| - return "" |
| + request_url = urlparse(flask.request.url) |
| + request_path = request_url.path |
| + if request_path in handlers: |
| + if 'SERVER_ADDR' not in flask.request.environ: |
| + flask.request.environ['SERVER_ADDR'] = flask.request.environ['SERVER_NAME'] |
| + return handlers[request_path] |
| + return flask.abort(404) |
| if __name__ == "__main__": |
| app.run(debug=True) |