11import asyncio
22import logging
3- from typing import Protocol , cast
3+ from typing import Final , Protocol , cast
44
55from aiohttp import web
66from models_library .api_schemas_webserver .permalinks import ProjectPermalink
1010from .exceptions import PermalinkFactoryError , PermalinkNotAllowedError
1111from .models import ProjectDict
1212
13- _PROJECT_PERMALINK = f"{ __name__ } "
1413_logger = logging .getLogger (__name__ )
1514
1615
@@ -24,15 +23,20 @@ async def __call__(
2423 ) -> ProjectPermalink : ...
2524
2625
26+ _PROJECT_PERMALINK_FACTORY_APPKEY : Final = web .AppKey (
27+ "PROJECT_PERMALINK_FACTORY" , CreateLinkCoroutine
28+ )
29+
30+
2731def register_factory (app : web .Application , factory_coro : CreateLinkCoroutine ):
28- if _create := app .get (_PROJECT_PERMALINK ):
32+ if _create := app .get (_PROJECT_PERMALINK_FACTORY_APPKEY ):
2933 msg = f"Permalink factory can only be set once: registered { _create } "
3034 raise PermalinkFactoryError (msg )
31- app [_PROJECT_PERMALINK ] = factory_coro
35+ app [_PROJECT_PERMALINK_FACTORY_APPKEY ] = factory_coro
3236
3337
3438def _get_factory (app : web .Application ) -> CreateLinkCoroutine :
35- if _create := app .get (_PROJECT_PERMALINK ):
39+ if _create := app .get (_PROJECT_PERMALINK_FACTORY_APPKEY ):
3640 return cast (CreateLinkCoroutine , _create )
3741
3842 msg = "Undefined permalink factory. Check plugin initialization."
0 commit comments