Show More
@@ -94,3 +94,35 b' class funcregistrar(object):' | |||||
94 | """Execute exra action for registered function, if needed |
|
94 | """Execute exra action for registered function, if needed | |
95 | """ |
|
95 | """ | |
96 | pass |
|
96 | pass | |
|
97 | ||||
|
98 | class delayregistrar(object): | |||
|
99 | """Decorator to delay actual registration until uisetup or so | |||
|
100 | ||||
|
101 | For example, the decorator class to delay registration by | |||
|
102 | 'keyword' funcregistrar can be defined as below:: | |||
|
103 | ||||
|
104 | class extkeyword(delayregistrar): | |||
|
105 | registrar = keyword | |||
|
106 | """ | |||
|
107 | def __init__(self): | |||
|
108 | self._list = [] | |||
|
109 | ||||
|
110 | registrar = None | |||
|
111 | ||||
|
112 | def __call__(self, *args, **kwargs): | |||
|
113 | """Return the decorator to delay actual registration until setup | |||
|
114 | """ | |||
|
115 | assert self.registrar is not None | |||
|
116 | def decorator(func): | |||
|
117 | # invocation of self.registrar() here can detect argument | |||
|
118 | # mismatching immediately | |||
|
119 | self._list.append((func, self.registrar(*args, **kwargs))) | |||
|
120 | return func | |||
|
121 | return decorator | |||
|
122 | ||||
|
123 | def setup(self): | |||
|
124 | """Execute actual registration | |||
|
125 | """ | |||
|
126 | while self._list: | |||
|
127 | func, decorator = self._list.pop(0) | |||
|
128 | decorator(func) |
General Comments 0
You need to be logged in to leave comments.
Login now