Dolda2000 GitWeb
/
wrw.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
d22f348
)
Replaced funplex with a more flexible class implementation.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Tue, 4 Jun 2013 14:11:37 +0000
(16:11 +0200)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Tue, 4 Jun 2013 14:11:37 +0000
(16:11 +0200)
wrw/util.py
patch
|
blob
|
blame
|
history
diff --git
a/wrw/util.py
b/wrw/util.py
index
4306e9b
..
759c295
100644
(file)
--- a/
wrw/util.py
+++ b/
wrw/util.py
@@
-24,15
+24,19
@@
def formparams(callable):
wrapper.__wrapped__ = callable
return wrapper
wrapper.__wrapped__ = callable
return wrapper
-def funplex(*funs, **nfuns):
+class funplex(object):
+ def __init__(self, *funs, **nfuns):
+ self.dir = {}
+ self.dir.update(((self.unwrap(fun).__name__, fun) for fun in funs))
+ self.dir.update(nfuns)
+
+ @staticmethod
def unwrap(fun):
while hasattr(fun, "__wrapped__"):
fun = fun.__wrapped__
return fun
def unwrap(fun):
while hasattr(fun, "__wrapped__"):
fun = fun.__wrapped__
return fun
- dir = {}
- dir.update(((unwrap(fun).__name__, fun) for fun in funs))
- dir.update(nfuns)
- def handler(req):
+
+ def __call__(self, req):
if req.pathinfo == "":
raise resp.redirect(req.uriname + "/")
if req.pathinfo[:1] != "/":
if req.pathinfo == "":
raise resp.redirect(req.uriname + "/")
if req.pathinfo[:1] != "/":
@@
-44,10
+48,19
@@
def funplex(*funs, **nfuns):
else:
p = p.partition("/")[0]
bi = len(p) + 1
else:
p = p.partition("/")[0]
bi = len(p) + 1
- if p in dir:
- return dir[p](req.shift(bi))
+ if p in
self.
dir:
+ return
self.
dir[p](req.shift(bi))
raise resp.notfound()
raise resp.notfound()
- return handler
+
+ def add(self, fun):
+ self.dir[self.unwrap(fun).__name__] = fun
+ return fun
+
+ def name(self, name):
+ def dec(fun):
+ self.dir[name] = fun
+ return fun
+ return dec
def persession(data = None):
def dec(callable):
def persession(data = None):
def dec(callable):