[docs]defregister_lookup_handler(lookup_type:str,handler_or_path:str|type[LookupHandler[Any]])->None:"""Register a lookup handler. Args: lookup_type: Name to register the handler under. handler_or_path: A function or a path to a handler. """handler=handler_or_pathLOGGER.debug("registering CFNgin lookup: %s=%s",lookup_type,handler_or_path)handler=(cast("type",load_object_from_string(handler_or_path))ifisinstance(handler_or_path,str)elsehandler_or_path)try:ifissubclass(handler,LookupHandler):CFNGIN_LOOKUP_HANDLERS[lookup_type]=handlerreturn# Handler is a not a new-style handlerexceptException:# noqa: BLE001LOGGER.debug("failed to validate lookup handler",exc_info=True)LOGGER.error('lookup "%s" uses an unsupported format; to learn how to write '"lookups visit %s/page/cfngin/lookups/index.html#writing-a-custom-lookup",lookup_type,DOC_SITE,)raiseTypeError(f"lookup {handler_or_path} must be a subclass of runway.lookups.handlers.base.LookupHandler")
[docs]defunregister_lookup_handler(lookup_type:str)->None:"""Unregister the specified lookup type. This is useful when testing various lookup types if you want to unregister the lookup type after the test runs. Args: lookup_type: Name of the lookup type to unregister. """CFNGIN_LOOKUP_HANDLERS.pop(lookup_type,None)