From: Fredrik Tolf Date: Tue, 23 Apr 2013 03:56:52 +0000 (+0200) Subject: Merge branch 'master' into python3 X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=8fec8547c47c0452333972f554f328d0c8e61be2;hp=cc1126892c7148faadc7b6781acce6a4a99ede5c;p=wrw.git Merge branch 'master' into python3 Conflicts: wrw/__init__.py --- diff --git a/wrw/__init__.py b/wrw/__init__.py index acf7f64..eb4a0a0 100644 --- a/wrw/__init__.py +++ b/wrw/__init__.py @@ -1,7 +1,7 @@ __all__ = ["wsgiwrap", "restart", "cookie", "formdata"] from . import proto -from .util import wsgiwrap, stringwrap, formparams, persession, sessiondata, autodirty, manudirty, specdirty +from .util import wsgiwrap, stringwrap, formparams, funplex, persession, sessiondata, autodirty, manudirty, specdirty from .dispatch import restart from . import cookie from .form import formdata 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):