request.args(0,default=0, cast=int, url_onerror=URL(...)), thanks Anthony

This commit is contained in:
Massimo Di Pierro
2012-04-30 11:39:37 -05:00
parent 85f8dc6d5b
commit fd82097bfc
3 changed files with 14 additions and 13 deletions
+13 -3
View File
@@ -25,11 +25,21 @@ class List(list):
instead of IndexOutOfBounds
"""
def __call__(self, i, default=None):
def __call__(self, i, default=None, cast=None, url_onerror=None):
if 0<=i<len(self):
return self[i]
value = self[i]
else:
return default
value = default
if cast:
try:
value = cast(value)
except (ValueError, TypeError):
from http import HTTP, redirect
if url_onerror:
redirect(url_onerror)
else:
raise HTTP(404)
return value
class Storage(dict):