author | Tero Marttila <terom@fixme.fi> |
Fri, 05 Jun 2009 19:30:28 +0300 | |
changeset 58 | 188a469792c2 |
parent 44 | 533b7e8b5d3b |
permissions | -rw-r--r-- |
20
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
1 |
import cgi |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
2 |
import Cookie |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
3 |
import os |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
4 |
|
44
533b7e8b5d3b
strip copyright/license boilerplate from modules, except dexif and formatbytes
Tero Marttila <terom@fixme.fi>
parents:
41
diff
changeset
|
5 |
""" |
533b7e8b5d3b
strip copyright/license boilerplate from modules, except dexif and formatbytes
Tero Marttila <terom@fixme.fi>
parents:
41
diff
changeset
|
6 |
XXX: legacy CGI crap |
533b7e8b5d3b
strip copyright/license boilerplate from modules, except dexif and formatbytes
Tero Marttila <terom@fixme.fi>
parents:
41
diff
changeset
|
7 |
""" |
533b7e8b5d3b
strip copyright/license boilerplate from modules, except dexif and formatbytes
Tero Marttila <terom@fixme.fi>
parents:
41
diff
changeset
|
8 |
|
20
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
9 |
vars = cgi.FieldStorage() |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
10 |
|
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
11 |
# the cookie with the user's current series |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
12 |
cookie = Cookie.SimpleCookie(os.environ.get('HTTP_COOKIE', None)) |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
13 |
|
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
14 |
class token (object) : |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
15 |
pass |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
16 |
|
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
17 |
REQUIRED_PARAM = token() |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
18 |
|
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
19 |
def get_str (key, default=REQUIRED_PARAM) : |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
20 |
if key in vars : |
23 | 21 |
return vars[key].value.decode('utf8', 'replace') |
20
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
22 |
elif default is REQUIRED_PARAM : |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
23 |
raise ValueError("Required param %s" % key) |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
24 |
else : |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
25 |
return default |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
26 |
|
25
4b3cf12848c2
tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents:
24
diff
changeset
|
27 |
def get_str_list (key, default=REQUIRED_PARAM) : |
4b3cf12848c2
tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents:
24
diff
changeset
|
28 |
if key in vars : |
4b3cf12848c2
tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents:
24
diff
changeset
|
29 |
return [val.decode('utf8', 'replace') for val in vars.getlist(key)] |
4b3cf12848c2
tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents:
24
diff
changeset
|
30 |
elif default is REQUIRED_PARAM : |
4b3cf12848c2
tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents:
24
diff
changeset
|
31 |
raise ValueError("Required param %s" % key) |
4b3cf12848c2
tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents:
24
diff
changeset
|
32 |
else : |
4b3cf12848c2
tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents:
24
diff
changeset
|
33 |
return default |
4b3cf12848c2
tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents:
24
diff
changeset
|
34 |
|
20
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
35 |
def get_int (key, default=REQUIRED_PARAM) : |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
36 |
if key in vars : |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
37 |
return int(vars[key].value) |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
38 |
elif default is REQUIRED_PARAM : |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
39 |
raise ValueError("Required param %s" % key) |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
40 |
else : |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
41 |
return default |
6c774496bb00
a rather silly shelve-based tagging thing, commiting before I scrap the code and start over with SQLite
terom
parents:
diff
changeset
|
42 |
|
24 | 43 |
def get_int_list (key, default=REQUIRED_PARAM) : |
44 |
if key in vars : |
|
45 |
return [int(val) for val in vars.getlist(key)] |
|
46 |
elif default is REQUIRED_PARAM : |
|
47 |
raise ValueError("Required param %s" % key) |
|
48 |
else : |
|
49 |
return default |