Skip to content

Instantly share code, notes, and snippets.

@vasc
Created February 3, 2010 09:38
Show Gist options
  • Save vasc/293507 to your computer and use it in GitHub Desktop.
Save vasc/293507 to your computer and use it in GitHub Desktop.
#! /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
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