degal/req.py
author Tero Marttila <terom@fixme.fi>
Wed, 10 Jun 2009 23:33:28 +0300
changeset 84 891545a38a2b
parent 44 533b7e8b5d3b
permissions -rw-r--r--
change utils.LazyProperty to store the cached value using obj.__dict__
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
10841abbc01f taggr2, which is starting to shape up
terom
parents: 20
diff changeset
    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
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    43
def get_int_list (key, default=REQUIRED_PARAM) :
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    44
    if key in vars :
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    45
      return [int(val) for val in vars.getlist(key)]
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    46
    elif default is REQUIRED_PARAM :
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    47
        raise ValueError("Required param %s" % key)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    48
    else :
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    49
        return default