@@ -75,7 +75,7 @@ def __init__(self, temp_entity):
7575 self ._add_properties (prop .data_table )
7676
7777 # Get a dictionary to store our hooks...
78- self ._hooks = {HookType .PRE : set (), HookType .POST : set ()}
78+ self ._hooks = {HookType .PRE : list (), HookType .POST : list ()}
7979
8080 # Initialize the base class...
8181 super ()._copy_base (temp_entity , self .size )
@@ -182,8 +182,12 @@ def add_hook(self, hook_type, callback):
182182 if not callable (callback ):
183183 raise TypeError ('The given callback is not callable.' )
184184
185+ # Is the callback already registered?
186+ if callback in hooks :
187+ raise ValueError ('The given callback is already registered.' )
188+
185189 # Register the hook...
186- self . hooks [ hook_type ]. add (callback )
190+ hooks . append (callback )
187191
188192 def remove_hook (self , hook_type , callback ):
189193 """Unregister a hook for this temp entity.
@@ -201,7 +205,7 @@ def remove_hook(self, hook_type, callback):
201205 raise TypeError ('The given hook type is invalid.' )
202206
203207 # Unregister the hook...
204- self . hooks [ hook_type ]. discard (callback )
208+ hooks . remove (callback )
205209
206210 def handle_hook (self , hook_type , temp_entity , recipient_filter ):
207211 """Call the registered callbacks.
@@ -215,27 +219,23 @@ def handle_hook(self, hook_type, temp_entity, recipient_filter):
215219
216220 :rtype: bool
217221 """
218- # Flag variable to determine whether or not any callback wants to
219- # block the original call...
220- block = False
222+ # Set the default return value to None...
223+ return_value = None
221224
222225 # Loop through all registered hooks for this temp entity...
223226 for callback in self .hooks [hook_type ]:
224227
225228 # Call the callback and store the value it returned...
226229 ret = callback (temp_entity , recipient_filter )
227230
228- # Is the returned value not None and evaluate to False?
229- if ret is not None and not ret :
230-
231- # This callback wants to block the original call...
232- block = True
231+ # Did the callback return anything?
232+ if ret is not None :
233233
234- # Does any callback wanted to block the original call?
235- if block :
234+ # Yes, so override the return value...
235+ return_value = ret
236236
237- # Yes, so block it ...
238- return False
237+ # Return the return value ...
238+ return return_value
239239
240240 @property
241241 def aliases (self ):
0 commit comments