summaryrefslogtreecommitdiff
path: root/pecan/hooks.py
diff options
context:
space:
mode:
authorJonathan LaCour <jonathan@cleverdevil.org>2010-09-30 10:11:21 -0400
committerJonathan LaCour <jonathan@cleverdevil.org>2010-09-30 10:11:21 -0400
commitccde2c07c88c26526384d2f7ed885add29756278 (patch)
treef1454830ab1f0e2940dadc5df015d580750d880f /pecan/hooks.py
parent31c2d315659d987eb2399b5b80b16d26df552ce7 (diff)
downloadpecan-ccde2c07c88c26526384d2f7ed885add29756278.tar.gz
Some reorganization, more tests, improved handling of errors, and
support for prioritized hooks.
Diffstat (limited to 'pecan/hooks.py')
-rw-r--r--pecan/hooks.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/pecan/hooks.py b/pecan/hooks.py
index d742ac3..9b52aa4 100644
--- a/pecan/hooks.py
+++ b/pecan/hooks.py
@@ -1,4 +1,39 @@
+from inspect import getmembers, ismethod
+from routing import iscontroller
+
+
+__all__ = ['PecanHook', 'TransactionHook', 'HookController']
+
+
+def walk_controller(root_class, controller, hooks):
+ if hasattr(controller, '_lookup'):
+ # TODO: what about this?
+ pass
+
+ if not isinstance(controller, (int, dict)):
+ for name, value in controller.__dict__.iteritems():
+ if name == 'controller': continue
+ if name.startswith('__') and name.endswith('__'): continue
+
+ if iscontroller(value):
+ for hook in hooks:
+ value.pecan.setdefault('hooks', []).append(hook)
+ elif hasattr(value, '__class__'):
+ if name.startswith('__') and name.endswith('__'): continue
+ walk_controller(root_class, value, hooks)
+
+
+class HookController(object):
+ __hooks__ = []
+
+ class __metaclass__(type):
+ def __init__(cls, name, bases, dict_):
+ walk_controller(cls, cls, dict_['__hooks__'])
+
+
class PecanHook(object):
+ priority = 100
+
def before(self, state):
pass