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

Unified Diff: multiplexer.py

Issue 8327353: Crawler backend (Closed)
Patch Set: Created Sept. 27, 2012, 6:22 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sitescripts/crashes/__init__.py » ('j') | sitescripts/crawler/bin/extract_crawler_sites.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « no previous file | sitescripts/crashes/__init__.py » ('j') | sitescripts/crawler/bin/extract_crawler_sites.py » ('J')

Powered by Google App Engine
This is Rietveld