| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent abb6362 commit f9e1c22
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,7 +75,7 @@ def __init__(self, temp_entity): | |||
| 75 | 75 | self._add_properties(prop.data_table) | |
| 76 | 76 | ||
| 77 | 77 | # 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()} | ||
| 79 | 79 | ||
| 80 | 80 | # Initialize the base class... | |
| 81 | 81 | super()._copy_base(temp_entity, self.size) | |
@@ -182,8 +182,12 @@ def add_hook(self, hook_type, callback): | |||
| 182 | 182 | if not callable(callback): | |
| 183 | 183 | raise TypeError('The given callback is not callable.') | |
| 184 | 184 | ||
| 185 | + # Is the callback already registered? | ||
| 186 | + if callback in hooks: | ||
| 187 | + raise ValueError('The given callback is already registered.') | ||
| 188 | + | ||
| 185 | 189 | # Register the hook... | |
| 186 | - self.hooks[hook_type].add(callback) | ||
| 190 | + hooks.append(callback) | ||
| 187 | 191 | ||
| 188 | 192 | def remove_hook(self, hook_type, callback): | |
| 189 | 193 | """Unregister a hook for this temp entity. | |
@@ -201,7 +205,7 @@ def remove_hook(self, hook_type, callback): | |||
| 201 | 205 | raise TypeError('The given hook type is invalid.') | |
| 202 | 206 | ||
| 203 | 207 | # Unregister the hook... | |
| 204 | - self.hooks[hook_type].discard(callback) | ||
| 208 | + hooks.remove(callback) | ||
| 205 | 209 | ||
| 206 | 210 | def handle_hook(self, hook_type, temp_entity, recipient_filter): | |
| 207 | 211 | """Call the registered callbacks. | |
@@ -215,27 +219,23 @@ def handle_hook(self, hook_type, temp_entity, recipient_filter): | |||
| 215 | 219 | ||
| 216 | 220 | :rtype: bool | |
| 217 | 221 | """ | |
| 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 | ||
| 221 | 224 | ||
| 222 | 225 | # Loop through all registered hooks for this temp entity... | |
| 223 | 226 | for callback in self.hooks[hook_type]: | |
| 224 | 227 | ||
| 225 | 228 | # Call the callback and store the value it returned... | |
| 226 | 229 | ret = callback(temp_entity, recipient_filter) | |
| 227 | 230 | ||
| 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: | ||
| 233 | 233 | ||
| 234 | - # Does any callback wanted to block the original call? | ||
| 235 | - if block: | ||
| 234 | + # Yes, so override the return value... | ||
| 235 | + return_value = ret | ||
| 236 | 236 | ||
| 237 | - # Yes, so block it... | ||
| 238 | - return False | ||
| 237 | + # Return the return value... | ||
| 238 | + return return_value | ||
| 239 | 239 | ||
| 240 | 240 | @property | |
| 241 | 241 | def aliases(self): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments