@@ -74,8 +74,8 @@ def __init__(self, temp_entity):
74
74
# Add the current table to the properties...
75
75
self ._add_properties (prop .data_table )
76
76
77
- # Get a dictionary to store our hooks...
78
- self ._hooks = { HookType . PRE : list (), HookType . POST : list ()}
77
+ # Get a list to store our hooks...
78
+ self ._hooks = list ()
79
79
80
80
# Initialize the base class...
81
81
super ()._copy_base (temp_entity , self .size )
@@ -163,55 +163,39 @@ def _get_type_size(type_name):
163
163
# Raise an exception...
164
164
raise ValueError ('"{}" is not a supported type.' .format (type_name ))
165
165
166
- def add_hook (self , hook_type , callback ):
166
+ def add_hook (self , callback ):
167
167
"""Register a hook for this temp entity.
168
168
169
- :param HookType hook_type:
170
- The type of the hook to register.
171
169
:param function callback:
172
170
The callback function to register.
173
171
"""
174
- # Get the set associated with the given hook type...
175
- hooks = self .hooks .get (hook_type , None )
176
-
177
- # Was the given hook type invalid?
178
- if hooks is None :
179
- raise TypeError ('The given hook type is invalid.' )
180
-
181
172
# Is the given callback not callable?
182
173
if not callable (callback ):
183
174
raise TypeError ('The given callback is not callable.' )
184
175
185
176
# Is the callback already registered?
186
- if callback in hooks :
177
+ if callback in self . hooks :
187
178
raise ValueError ('The given callback is already registered.' )
188
179
189
180
# Register the hook...
190
- hooks .append (callback )
181
+ self . hooks .append (callback )
191
182
192
- def remove_hook (self , hook_type , callback ):
183
+ def remove_hook (self , callback ):
193
184
"""Unregister a hook for this temp entity.
194
185
195
- :param HookType hook_type:
196
- The type of the hook to unregister.
197
186
:param function callback:
198
187
The callback function to unregister.
199
188
"""
200
- # Get the set associated with the given hook type...
201
- hooks = self .hooks .get (hook_type , None )
202
-
203
- # Was the given hook type invalid?
204
- if hooks is None :
205
- raise TypeError ('The given hook type is invalid.' )
189
+ # Raise an exception if the given callback isn't registered...
190
+ if callback not in self .hooks :
191
+ raise ValueError ('The given callback is not registered.' )
206
192
207
193
# Unregister the hook...
208
- hooks .remove (callback )
194
+ self . hooks .remove (callback )
209
195
210
- def handle_hook (self , hook_type , temp_entity , recipient_filter ):
196
+ def handle_hook (self , temp_entity , recipient_filter ):
211
197
"""Call the registered callbacks.
212
198
213
- :param HookType hook_type:
214
- The type of the hook to handle.
215
199
:param TempEntity temp_entity:
216
200
The TempEntity instance.
217
201
:param RecipientFilter recipient_filter:
@@ -223,16 +207,16 @@ def handle_hook(self, hook_type, temp_entity, recipient_filter):
223
207
return_value = None
224
208
225
209
# Loop through all registered hooks for this temp entity...
226
- for callback in self .hooks [ hook_type ] :
210
+ for callback in self .hooks :
227
211
228
212
# Call the callback and store the value it returned...
229
- ret = callback (temp_entity , recipient_filter )
213
+ returned_value = callback (temp_entity , recipient_filter )
230
214
231
215
# Did the callback return anything?
232
- if ret is not None :
216
+ if returned_value is not None :
233
217
234
218
# Yes, so override the return value...
235
- return_value = ret
219
+ return_value = returned_value
236
220
237
221
# Return the return value...
238
222
return return_value
0 commit comments