09b9e36cd98ab3ff09f68835c7fe587909e6d5d8
[wrw.git] / wrw / util.py
1 import req, dispatch, session
2
3 def wsgiwrap(callable):
4     def wrapper(env, startreq):
5         return dispatch.handle(req.origrequest(env), startreq, callable)
6     return wrapper
7
8 def persession(data = None):
9     def dec(callable):
10         def wrapper(req):
11             sess = session.get(req)
12             if callable not in sess:
13                 if data is None:
14                     sess[callable] = callable()
15                 else:
16                     if data not in sess:
17                         sess[data] = data()
18                     sess[callable] = callable(data)
19             return sess[callable].handle(req)
20         return wrapper
21     return dec