Lynn Rees avatar Lynn Rees committed 1f8daeb

- services

Comments (0)

Files changed (3)

appspace/builders.py

 from itertools import starmap
 
 from stuf.six import strings
-from stuf.utils import selfname, exhaust, exhaustmap, twoway
+from stuf.utils import selfname, exhaust, exhaustmap, twoway, imap
 
 from appspace.registry import Manager, StrictManager, lazyimport
 from appspace.keys import (
-    AAppspace, AppLookupError, NoAppError, ABranch, ANamespace, AApp, appifies)
+    AAppspace, AppLookupError, NoAppError, ABranch, ANamespace, AApp, appifies,
+    AService)
 
 
 class _Filter(object):
         '''
         return cls.factory(label, cls._manager, *args)
     
+class _PatternsMixin(object):
+
+    @classmethod
+    def _key(cls, label, manager):
+        try:
+            # lazily load key
+            key = cls.key
+            if isinstance(key, strings):
+                key = lazyimport(key)
+            # register class key
+            ez_register = manager.ez_register
+            ez_register(ANamespace, label, key)
+            exhaust(imap(
+                lambda x: ez_register(AService, x, label),
+                iter(key.names(True)),
+            ))
+        except AttributeError:
+            key = manager.key(ANamespace, label)
+
     
 class _PatternMixin(_Filter):
 
             key = manager.key(ANamespace, label)
 
 
-
 @appifies(ANamespace)
 class Branch(_PatternMixin):
 
 class NoAppError(Exception):
 
     '''mo application found exception'''
+
+
+class AService(ANamespace):
+
+    '''service key'''

appspace/registry.py

 
 from appspace.keys import (
     ALazyLoad, AppStore, InterfaceClass, AApp, StrictAppStore, ANamespace,
-    AManager, AppLookupError, appifies, keys)
+    AManager, AppLookupError, appifies, keys, ConfigurationError)
+from callchain.services.queue import KService
 
 
 def lazyimport(path, attribute=None):
             '', normalize('NFKD', value).encode('ascii', 'ignore')
         ).strip().lower()))
 
+    def service(self, label):
+        '''
+        fetch service
+
+        @param label: service label
+        '''
+        service = self.lookup1(KService, KService, label)
+        if service is None:
+            raise ConfigurationError(label)
+        return service
+
 
 class Registry(RegistryMixin, AppStore):
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.