Created
February 3, 2010 09:38
-
-
Save vasc/293507 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
#routes like dispatcher to work on plain cgi | |
#request url looks like this 'paths.py?path=/abc/def/ghj/;' after mod_rewrite | |
import re | |
import cgi | |
import cgitb | |
def dispatch(path, rules): | |
for rule in rules: | |
dest = rule['dest'] | |
r = re.search(rule['re'], path) | |
if(r): | |
dest(**r.groupdict()) | |
return | |
page_404(path) | |
def page_404(path): | |
print 'Content-type: text/plain' | |
print '404' | |
cgitb.enable() | |
form = cgi.FieldStorage() | |
dispatch(form['path'][1].value, []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment