cs.app.pilfer.sitemap: make SiteMap promotable from a pilfer sitemap name
1 files changed, 21 insertions(+), 1 deletions(-)

M lib/python/cs/app/pilfer/sitemap.py
M lib/python/cs/app/pilfer/sitemap.py +21 -1
@@ 54,7 54,7 @@ class URLMatcher(Promotable):
     return m.groupdict()
 
 @dataclass
-class SiteMap:
+class SiteMap(Promotable):
   ''' A base class for site maps.
 
       A `Pilfer` instance obtains its site maps from the `[sitemaps]`

          
@@ 72,6 72,26 @@ class SiteMap:
 
   URL_KEY_PATTERNS = ()
 
+  @classmethod
+  def from_str(
+      cls, sitemap_name: str, *, P: Optional["Pilfer"] = None
+  ) -> "SiteMap":
+    ''' Return the `SiteMap` instance known as `sitemap_name` in the ambient `Pilfer` instance.
+    '''
+    if P is None:
+      from .pilfer import Pilfer
+      P = Pilfer.default()
+      if P is None:
+        raise ValueError(
+            f'{cls.__name__}.from_str({sitemap_name!r}): no Pilfer to search for sitemaps'
+        )
+    for name, sitwmap in P.sitemaps:
+      if name == sitemap_name:
+        return sitemap
+    raise ValueError(
+        f'{cls.__name__}.from_str({sitemap_name!r}): unknown sitemap name'
+    )
+
   def matches(
       self,
       url: URL,