@@ -205,7 +205,7 @@ def _get_item_or_section(self, key, handle_not_found=True):
205205 resolution = self ._tree [key ]
206206 else :
207207 if handle_not_found :
208- result = self ._trigger_event (self .hooks .not_found , name = key , section = self )
208+ result = self .dispatch_event (self .hooks .not_found , name = key , section = self )
209209 if result is not None :
210210 resolution = result
211211 else :
@@ -314,7 +314,7 @@ def add_item(self, alias, item):
314314
315315 item ._section = self
316316
317- self ._trigger_event (self .hooks .item_added_to_section , alias = alias , section = self , subject = item )
317+ self .dispatch_event (self .hooks .item_added_to_section , alias = alias , section = self , subject = item )
318318
319319 def add_section (self , alias , section ):
320320 """
@@ -334,7 +334,7 @@ def add_section(self, alias, section):
334334 section ._section = self
335335 section ._section_alias = alias
336336
337- self ._trigger_event (self .hooks .section_added_to_section , alias = alias , section = self , subject = section )
337+ self .dispatch_event (self .hooks .section_added_to_section , alias = alias , section = self , subject = section )
338338
339339 def _get_str_path_separator (self , override = None ):
340340 if override is None or override is not_set :
@@ -695,28 +695,32 @@ def _hook_registered(self):
695695 if self .settings .hooks_enabled is None :
696696 self .settings .hooks_enabled = True
697697
698- def _trigger_event (self , event_ , ** kwargs ):
698+ def dispatch_event (self , event_ , ** kwargs ):
699699 """
700+ Dispatch section event.
701+
700702 Notes:
701- If hooks are disabled in a high-in-the-tree Config, and enabled
702- in one of its descendant Configs, events will still be handled in
703- the lower Config .
703+ You MUST NOT call event.trigger() directly because
704+ it will circumvent the section settings as well
705+ as ignore the section tree .
704706
707+ If hooks are disabled somewhere up in the tree, and enabled
708+ down below, events will still be dispatched down below because
709+ that's where they originate.
705710 """
706-
707711 if self .settings .hooks_enabled :
708- result = self .hooks .handle (event_ , ** kwargs )
712+ result = self .hooks .dispatch_event (event_ , ** kwargs )
709713 if result is not None :
710714 return result
711715
712- # Must also call hooks in parent section
716+ # Must also dispatch the event in parent section
713717 if self .section :
714- return self .section ._trigger_event (event_ , ** kwargs )
718+ return self .section .dispatch_event (event_ , ** kwargs )
715719
716720 elif self .section :
717- # Settings only apply to one section, so must still let
718- # parent sections trigger the event
719- self .section ._trigger_event (event_ , ** kwargs )
721+ # Settings only apply to one section, so must still
722+ # dispatch the event in parent sections recursively.
723+ self .section .dispatch_event (event_ , ** kwargs )
720724
721725
722726class PathProxy (object ):
@@ -730,4 +734,4 @@ def _get_real_object(self):
730734 return self .__path_target
731735
732736 def __getattr__ (self , name ):
733- return getattr (self ._get_real_object (), name )
737+ return getattr (self ._get_real_object (), name )
0 commit comments