shorturl.cgi
author terom
Thu, 08 Nov 2007 17:08:04 +0000
changeset 2 8b2b40a51098
parent 1 740133ab6353
child 3 9637b8f24005
permissions -rwxr-xr-x
modify shorturl.cgi to use the new shorturls2.db
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     1
#!/usr/bin/env python2.5
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     2
2
8b2b40a51098 modify shorturl.cgi to use the new shorturls2.db
terom
parents: 1
diff changeset
     3
import shelve
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     4
import cgi
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     5
import os, os.path
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     6
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     7
vars = cgi.FieldStorage()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     8
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
     9
key = vars['key'].value
2
8b2b40a51098 modify shorturl.cgi to use the new shorturls2.db
terom
parents: 1
diff changeset
    10
db = shelve.open('shorturls2', 'r')
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    11
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    12
try :
2
8b2b40a51098 modify shorturl.cgi to use the new shorturls2.db
terom
parents: 1
diff changeset
    13
    type, dirpath, fname = db[key]
8b2b40a51098 modify shorturl.cgi to use the new shorturls2.db
terom
parents: 1
diff changeset
    14
8b2b40a51098 modify shorturl.cgi to use the new shorturls2.db
terom
parents: 1
diff changeset
    15
    path = os.path.join(dirpath, fname)
1
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    16
finally :
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    17
    db.close()
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    18
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    19
print "Status: 302"
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    20
print "Location: ../%s" % path
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    21
print
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    22
print "../%s" % path
740133ab6353 initial code, somewhere between 0.2 and 0.5
terom
parents:
diff changeset
    23