4141 Generic ,
4242 Iterable ,
4343 Iterator ,
44+ Mapping ,
4445 NamedTuple ,
4546 Sequence ,
4647 TextIO ,
@@ -3969,12 +3970,17 @@ def escape_to_minimize(self) -> bool:
39693970 )
39703971
39713972 def _parse_action (
3972- self , action : str | ActionParseResult , default_namespace : DOMNode
3973+ self ,
3974+ action : str | ActionParseResult ,
3975+ default_namespace : DOMNode ,
3976+ namespaces : Mapping [str , DOMNode ] | None = None ,
39733977 ) -> tuple [DOMNode , str , tuple [object , ...]]:
39743978 """Parse an action.
39753979
39763980 Args:
39773981 action: An action string.
3982+ default_namespace: Namespace to user when none is supplied in the action.
3983+ namespaces: Mapping of namespaces.
39783984
39793985 Raises:
39803986 ActionError: If there are any errors parsing the action string.
@@ -3987,8 +3993,10 @@ def _parse_action(
39873993 else :
39883994 destination , action_name , params = actions .parse (action )
39893995
3990- action_target : DOMNode | None = None
3991- if destination :
3996+ action_target : DOMNode | None = (
3997+ None if namespaces is None else namespaces .get (destination )
3998+ )
3999+ if destination and action_target is None :
39924000 if destination not in self ._action_targets :
39934001 raise ActionError (f"Action namespace { destination } is not known" )
39944002 action_target = getattr (self , destination , None )
@@ -4021,6 +4029,7 @@ async def run_action(
40214029 self ,
40224030 action : str | ActionParseResult ,
40234031 default_namespace : DOMNode | None = None ,
4032+ namespaces : Mapping [str , DOMNode ] | None = None ,
40244033 ) -> bool :
40254034 """Perform an [action](/guide/actions).
40264035
@@ -4030,12 +4039,13 @@ async def run_action(
40304039 action: Action encoded in a string.
40314040 default_namespace: Namespace to use if not provided in the action,
40324041 or None to use app.
4042+ namespaces: Mapping of namespaces.
40334043
40344044 Returns:
40354045 True if the event has been handled.
40364046 """
40374047 action_target , action_name , params = self ._parse_action (
4038- action , self if default_namespace is None else default_namespace
4048+ action , self if default_namespace is None else default_namespace , namespaces
40394049 )
40404050 if action_target .check_action (action_name , params ):
40414051 return await self ._dispatch_action (action_target , action_name , params )
0 commit comments