X-Git-Url: http://dolda2000.com/gitweb/?p=wrw.git;a=blobdiff_plain;f=wrw%2Futil.py;h=eb2768319804b40caa2f78765fbb78661263187c;hp=eaa6a6280ffdcf90d79d086e72efb416d1213b49;hb=8fec8547c47c0452333972f554f328d0c8e61be2;hpb=cc1126892c7148faadc7b6781acce6a4a99ede5c diff --git a/wrw/util.py b/wrw/util.py index eaa6a62..eb27683 100644 --- a/wrw/util.py +++ b/wrw/util.py @@ -31,6 +31,27 @@ def formparams(callable): return callable(**args) return wrapper +def funplex(*funs, **nfuns): + dir = {} + dir.update(((fun.__name__, fun) for fun in funs)) + dir.update(nfuns) + def handler(req): + if req.pathinfo == "": + raise resp.redirect(req.uriname + "/") + if req.pathinfo[:1] != "/": + raise resp.notfound() + p = req.pathinfo[1:] + if p == "": + p = "__index__" + bi = 1 + else: + p = p.partition("/")[0] + bi = len(p) + 1 + if p in dir: + return dir[p](req.shift(bi)) + raise resp.notfound() + return handler + def persession(data = None): def dec(callable): def wrapper(req):