@@ -74,8 +74,8 @@ def __init__(self, temp_entity):
7474 # Add the current table to the properties...
7575 self ._add_properties (prop .data_table )
7676
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 ()
7979
8080 # Initialize the base class...
8181 super ()._copy_base (temp_entity , self .size )
@@ -163,55 +163,39 @@ def _get_type_size(type_name):
163163 # Raise an exception...
164164 raise ValueError ('"{}" is not a supported type.' .format (type_name ))
165165
166- def add_hook (self , hook_type , callback ):
166+ def add_hook (self , callback ):
167167 """Register a hook for this temp entity.
168168
169- :param HookType hook_type:
170- The type of the hook to register.
171169 :param function callback:
172170 The callback function to register.
173171 """
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-
181172 # Is the given callback not callable?
182173 if not callable (callback ):
183174 raise TypeError ('The given callback is not callable.' )
184175
185176 # Is the callback already registered?
186- if callback in hooks :
177+ if callback in self . hooks :
187178 raise ValueError ('The given callback is already registered.' )
188179
189180 # Register the hook...
190- hooks .append (callback )
181+ self . hooks .append (callback )
191182
192- def remove_hook (self , hook_type , callback ):
183+ def remove_hook (self , callback ):
193184 """Unregister a hook for this temp entity.
194185
195- :param HookType hook_type:
196- The type of the hook to unregister.
197186 :param function callback:
198187 The callback function to unregister.
199188 """
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.' )
206192
207193 # Unregister the hook...
208- hooks .remove (callback )
194+ self . hooks .remove (callback )
209195
210- def handle_hook (self , hook_type , temp_entity , recipient_filter ):
196+ def handle_hook (self , temp_entity , recipient_filter ):
211197 """Call the registered callbacks.
212198
213- :param HookType hook_type:
214- The type of the hook to handle.
215199 :param TempEntity temp_entity:
216200 The TempEntity instance.
217201 :param RecipientFilter recipient_filter:
@@ -223,16 +207,16 @@ def handle_hook(self, hook_type, temp_entity, recipient_filter):
223207 return_value = None
224208
225209 # Loop through all registered hooks for this temp entity...
226- for callback in self .hooks [ hook_type ] :
210+ for callback in self .hooks :
227211
228212 # Call the callback and store the value it returned...
229- ret = callback (temp_entity , recipient_filter )
213+ returned_value = callback (temp_entity , recipient_filter )
230214
231215 # Did the callback return anything?
232- if ret is not None :
216+ if returned_value is not None :
233217
234218 # Yes, so override the return value...
235- return_value = ret
219+ return_value = returned_value
236220
237221 # Return the return value...
238222 return return_value
0 commit comments