def __init__(self, broadcast_instance: "Broadcast") -> None: self.broadcast = broadcast_instance self.execution_contexts = [ExecutionContext([])] self.parameter_contexts = [ ParameterContext( None, None, None, [], [ [], ], ) ] self.track_logs = [TrackLog()]
async def lookup_by_directly(self, dispatcher: T_Dispatcher, name: str, annotation: Any, default: Any) -> Any: self.parameter_contexts.append( ParameterContext(name, annotation, default, [])) dispatcher_callable = self.dispatcher_callable_detector(dispatcher) try: result = await self.execute_dispatcher_callable(dispatcher_callable ) if result.__class__ is Force: return result.target return result finally: self.parameter_contexts.pop()
async def lookup_param( self, name: str, annotation: Any, default: Any, using_path: List[List["T_Dispatcher"]] = None, ) -> Any: self.parameter_contexts.append( ParameterContext( name, annotation, default, [], using_path or self.init_dispatch_path() ) ) track_log = self.track_log.log track_log.append((TrackLogType.LookupStart, name, annotation, default)) try: for dispatcher in self.current_path: result = await run_always_await_safely( self.dispatcher_callable_detector(dispatcher), self ) if result is None: self.track_log.fluent_success = False track_log.append((TrackLogType.Continue, name, dispatcher)) continue if result.__class__ is Force: result = result.target track_log.append((TrackLogType.Result, name, dispatcher)) self.execution_contexts[-1]._index = 0 return result else: track_log.append((TrackLogType.RequirementCrashed, name)) raise RequirementCrashed( "the dispatching requirement crashed: ", self.name, self.annotation, self.default, ) finally: track_log.append((TrackLogType.LookupEnd, name)) self.parameter_contexts.pop()
async def lookup_param_without_log( self, name: str, annotation: Any, default: Any, using_path: List[List["T_Dispatcher"]] = None, ) -> Any: self.parameter_contexts.append( ParameterContext( name, annotation, default, [], using_path or self.init_dispatch_path() ) ) result = None try: for dispatcher in self.current_path: result = await run_always_await_safely( self.dispatcher_callable_detector(dispatcher), self ) if result is None: continue if result.__class__ is Force: result = result.target self.execution_contexts[-1]._index = 0 return result else: raise RequirementCrashed( "the dispatching requirement crashed: ", self.name, self.annotation, self.default, ) finally: self.parameter_contexts.pop()
async def lookup_by_directly( self, dispatcher: T_Dispatcher, name: str, annotation: Any, default: Any, using_path: List[List["T_Dispatcher"]] = None, ) -> Any: self.parameter_contexts.append( ParameterContext( name, annotation, default, [], using_path or self.init_dispatch_path() ) ) dispatcher_callable = self.dispatcher_callable_detector(dispatcher) try: result = await run_always_await_safely(dispatcher_callable, self) if result.__class__ is Force: return result.target return result finally: self.parameter_contexts.pop()
def __init__(self, broadcast_instance: "Broadcast") -> None: self.broadcast = broadcast_instance self.alive_generator_dispatcher = [[]] self.execution_contexts = [ExecutionContext([], EmptyEvent())] self.parameter_contexts = [ParameterContext(None, None, None, [])]
async def lookup_by( self, dispatcher: T_Dispatcher, name: str, annotation: Any, default: Any, enable_extra_return: bool = False, ) -> Union[Any, Tuple[Any, T_Dispatcher, DispatcherSource, List[T_Dispatcher]]]: self.parameter_contexts.append( ParameterContext(name, annotation, default, [])) result = None try: start_offset = self._index + int(bool(self._index)) for self.execution_contexts[-1]._index, ( dispatcher, dispatcher_callable, source, ) in enumerate( itertools.islice( self.dispatcher_generator( lambda x: [DispatcherSource([dispatcher])]), start_offset, None, None, ), start=start_offset, ): result = await self.execute_dispatcher_callable( dispatcher_callable) if result is None: continue if result.__class__ is Force: result = result.target self.execution_contexts[-1]._index = 0 return (( result, weakref.ref(dispatcher), source, list( map( lambda x: weakref.ref(x), itertools.islice( self.dispatcher_generator(), start_offset, self._index, ), )), ) if enable_extra_return else result) else: raise RequirementCrashed( "the dispatching requirement crashed: ", self.name, self.annotation, self.default, ) finally: for dispatcher, dispatcher_callable, source in self.dispatcher_generator( lambda x: [ DispatcherSource(self.execution_contexts[-1]. always_dispatchers) ], using_always=False, ): await self.execute_dispatcher_callable(dispatcher_callable) self.parameter_contexts.pop()