shorturl.cgi
author terom
Thu, 20 Dec 2007 17:42:04 +0000
changeset 11 27dac27d1a58
parent 9 a0a13d5e406c
child 12 c2d8e9a754a1
permissions -rwxr-xr-x
merge the prepare stage into the index/render stages
#!/usr/bin/env python2.5

import shelve
import cgi
import os, os.path

vars = cgi.FieldStorage()

key = vars['key'].value

if 'index' in vars :
    index = int(vars['index'].value.lstrip('/'))
else :
    index = None

db = shelve.open('shorturls2', 'r')

try :
    type, dirpath, fname = db[key]

    if type == 'img' :
        fname += '.html'
    elif type == 'dir' :
        fname = ''

    if index :
        if index > 1 : 
            fname = 'index_%s.html' % (index - 1)

        dirpath = '../%s' % dirpath

    path = os.path.join(dirpath, fname)
finally :
    db.close()

print "Status: 302"
print "Location: ../%s" % path
print
print "../%s" % path