X-Git-Url: http://dolda2000.com/gitweb/?p=wrw.git;a=blobdiff_plain;f=wrw%2Futil.py;h=cfc2c8cedf5920f8fa8ee6ce5c83d5338826621d;hp=64b820fa88752b90645a5f778db87b07e6b605a2;hb=525d7938bc668f6079f0fd00a0baad75b1aebe24;hpb=b239aa235034b2d44c9f8948503cc2c59f747ed1 diff --git a/wrw/util.py b/wrw/util.py index 64b820f..cfc2c8c 100644 --- a/wrw/util.py +++ b/wrw/util.py @@ -22,6 +22,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):