Coverage for fastblocks/adapters/sitemap/asgi.py: 0%

32 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-21 04:50 -0700

1"""FastBlocks ASGI Sitemap Adapter (Legacy). 

2 

3This adapter now uses FastBlocks native sitemap implementation 

4instead of the external asgi-sitemaps dependency. 

5 

6For new projects, consider using the native adapter directly. 

7""" 

8 

9from contextlib import suppress 

10from uuid import UUID 

11 

12from acb.adapters import AdapterStatus 

13from acb.depends import depends 

14 

15from ._base import SitemapBase, SitemapBaseSettings 

16from .core import BaseSitemap as NativeSitemap 

17from .core import SitemapApp 

18 

19 

20class SitemapSettings(SitemapBaseSettings): 

21 pass 

22 

23 

24class Sitemap(NativeSitemap[str], SitemapBase): 

25 sitemap: SitemapApp | None = None 

26 

27 @depends.inject 

28 def items(self) -> list[str]: 

29 try: 

30 routes_adapter = depends.get("routes") 

31 if hasattr(routes_adapter, "routes"): 

32 return [r.path for r in routes_adapter.routes] 

33 return [] 

34 except Exception: 

35 return [] 

36 

37 def location(self, item: str) -> str: 

38 return item 

39 

40 def changefreq(self, item: str) -> str: 

41 return self.config.change_freq 

42 

43 async def init(self) -> None: 

44 if not self.config.app.domain: 

45 msg = "`domain` must be set in AppSettings" 

46 raise ValueError(msg) 

47 self.sitemap = SitemapApp( 

48 self, 

49 domain=self.config.app.domain, 

50 cache_ttl=getattr(self.config, "cache_ttl", 3600), 

51 ) 

52 

53 

54MODULE_ID = UUID("01937d86-eff0-7410-5786-a01234567890") 

55MODULE_STATUS = AdapterStatus.STABLE 

56 

57with suppress(Exception): 

58 depends.set(Sitemap)