Commits

Lynn Rees committed 3ac063e

- consolidate

Comments (0)

Files changed (8)

 Copyright (c) 2006-2012 L. C. Rees.  All rights reserved.
 Copyright (c) 2010-2011 Benjamin Peterson
 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+1.  Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+2.  Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+3.  Neither the name of the Portable Site Information Project nor the names
+of its contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.

appspace/__init__.py

 # -*- coding: utf-8 -*-
-'''appspace'''
+'''appspace, easy application construction with easy building blocks'''
 
-from appspace.managers import Manager
-from appspace.registry import Registry
+from appspace.registry import Registry, Manager
 from appspace.builders import patterns, class_patterns
-from appspace.spaces import (
-    Branch, Namespace, Patterns, include, space_patterns)
+from appspace.spaces import Branch, Patterns, include, space_patterns
 from appspace.keys import (
     NoAppError, AppLookupError, AppspaceKey, Attribute, appifies)
 

appspace/builders.py

 # -*- coding: utf-8 -*-
 '''appspace builder'''
 
-from appspace.spaces import space_patterns
-from appspace.keys import AAppspace, appifies, AppLookupError, NoAppError
+from functools import partial
+from itertools import starmap
 
-__all__ = ['patterns', 'class_patterns']
+from stuf.six import strings
+from stuf.utils import selfname, exhaust, exhaustmap, twoway
+
+from appspace.utils import lazyimport
+from appspace.registry import Manager, StrictManager
+from appspace.keys import (
+    AAppspace, AppLookupError, NoAppError, ABranch, ANamespace, AApp, appifies)
+
+
+class _Filter(object):
+
+    @classmethod
+    def _filter(self, x):
+        return not x[0].startswith('_')
+
+
+class Patterns(_Filter):
+
+    '''patterns for manager configured by class'''
+
+    key = AApp
+    strict = False
+
+    @twoway
+    def _manager(self):
+        '''manager class'''
+        return StrictManager if self.strict else Manager
+
+    @classmethod
+    def build(cls):
+        '''build manager configuration from class'''
+        l = selfname(cls)
+        # set key
+        key = cls.key
+        if isinstance(key, strings):
+            # load key if string
+            key = lazyimport(key)
+        manager = cls._manager(l, key)  # pylint: disable-msg=e1121
+        b = partial(manager.keyed, ABranch)
+        m, n = manager.set, partial(manager.keyed, ANamespace)
+        t = lambda x, y: y.build(manager) if (n(y) or b(y)) else m(y, x, l)
+        exhaustmap(vars(cls), t, cls._filter)
+        return manager
+
+    @staticmethod
+    def factory(label, manager, *args):
+        '''
+        factory for manager
+
+        @param label: label for manager
+        '''
+        # build manager
+        manager = manager(label)
+        # register things in manager
+        exhaust(starmap(lambda x, y: manager.set(y, x), iter(args)))
+        return manager
+
+    @classmethod
+    def patterns(cls, label, *args):
+        '''
+        configure appspace
+
+        @param label: name of branch appspace
+        @param *args: tuple of module paths or component inclusions
+        '''
+        return cls.factory(label, cls._manager, *args)
+
+
+@appifies(ANamespace)
+class Branch(object):
+
+    '''branch configuration'''
+    
+    @classmethod
+    def _key(cls, label, manager):
+        try:
+            # lazily load key
+            key = cls.key
+            if isinstance(key, strings):
+                key = lazyimport(key)
+            # register class key
+            manager.ez_register(ANamespace, label, key)
+        except AttributeError:
+            key = manager.key(ANamespace, label)
+
+    @classmethod
+    def build(cls, manager):
+        '''gather branch configuration'''
+        cls._key(selfname(cls), manager)
+        i, m = cls.include, manager.set
+        t = lambda x: not x[0].startswith('_') or isinstance(x[1], strings)
+        exhaustmap(vars(cls), lambda x, y: m(i(y), x), t)
+
+    @staticmethod
+    def include(module):
+        '''
+        configure branch appspace
+
+        @param module: module import path
+        '''
+        return ('include', module)
 
 
 @appifies(AAppspace)
             return result
 
 
+factory = Patterns.factory
+include = Branch.include
+space_patterns = Patterns.patterns
+
 def patterns(label, *args, **kw):
     '''
     factory for manager
 
 class appifies(implementer):
 
+    '''appifier'''
+
     def __init__(self, key, **metadata):
         exhaustmap(metadata, key.setTaggedValue)
         super(appifies, self).__init__(key)

appspace/managers.py

-# -*- coding: utf-8 -*-
-'''appspace management'''
-
-import re
-from unicodedata import normalize
-
-from stuf.six import u
-
-from appspace.registry import Registry, StrictRegistry
-from appspace.keys import AManager, ANamespace, AppLookupError, appifies
-
-__all__ = ('Manager', 'StrictManager')
-
-
-class ManagerMixin(object):
-
-    '''state manager'''
-
-    _first = staticmethod(re.compile('[^\w\s-]').sub)
-    _second = staticmethod(re.compile('[-\s]+').sub)
-
-    def apply(self, label, key=False, *args, **kw):
-        '''
-        invoke appspaced call
-
-        @param label: appspaced call
-        @param key: key label (default: False)
-        '''
-        return self.get(label, key)(*args, **kw)
-
-    def get(self, label, key=False):
-        '''
-        get thing from appspace
-
-        @param label: appspaced thing label
-        @param key: `appspace` key (default: False)
-        '''
-        # use internal key if key label == internal key
-        key = self._key if key == self._root else self.namespace(key)
-        app = self.lookup1(key, key, label)
-        if app is None:
-            raise AppLookupError(app, label)
-        return self.load(label, key, app)
-
-    def namespace(self, label):
-        '''
-        fetch key
-
-        @param label: `appspace` key label
-        '''
-        this = self.lookup1(ANamespace, ANamespace, label)
-        if this is None:
-            raise AppLookupError(this, label)
-        return this
-
-    def set(self, thing=False, label=False, key=False):
-        '''
-        add thing to `appspace`
-
-        @param thing: new `appspace` thing (default: False)
-        @param label: new `appspace` thing label (default: False)
-        @param key: key label (default: False)
-        '''
-        thing = self._lazy(thing)
-        key = self.namespace(key) if key else self._key
-        self.register([key], key, self.safename(label), thing)
-        return thing
-
-    @classmethod
-    def slugify(cls, value):
-        '''
-        normalizes string, converts to lowercase, removes non-alpha characters,
-        and converts spaces to hyphens
-        '''
-        return cls._second('-', u(cls._first(
-            '', normalize('NFKD', value).encode('ascii', 'ignore')
-        ).strip().lower()))
-
-
-@appifies(AManager)
-class Manager(ManagerMixin, Registry):
-
-    '''state manager'''
-
-    __slots__ = ('_current', '_root', '_key')
-
-
-@appifies(AManager)
-class StrictManager(ManagerMixin, StrictRegistry):
-
-    '''strict manager'''
-
-    __slots__ = ('_current', '_root', '_key')
-
-
-keyed = Manager.keyed

appspace/registry.py

 # -*- coding: utf-8 -*-
 '''appspace registries'''
 
+import re
 import uuid
 import hashlib
 from inspect import isclass
+from unicodedata import normalize
 
 from stuf.six import u, strings
 from stuf.utils import exhaustmap
 from appspace.utils import lazyimport, checkname
 from appspace.keys import (
     ALazyLoad, AppStore, InterfaceClass, AApp, StrictAppStore, ANamespace,
-    AManager, appifies, keys)
+    AManager, AppLookupError, appifies, keys)
 
 
 @appifies(ALazyLoad)
         exhaustmap(vars(labels), self.pack, lambda x: not x[0].startswith('_'))
 
 
+class ManagerMixin(object):
+
+    '''state manager'''
+
+    _first = staticmethod(re.compile('[^\w\s-]').sub)
+    _second = staticmethod(re.compile('[-\s]+').sub)
+
+    def apply(self, label, key=False, *args, **kw):
+        '''
+        invoke appspaced call
+
+        @param label: appspaced call
+        @param key: key label (default: False)
+        '''
+        return self.get(label, key)(*args, **kw)
+
+    def get(self, label, key=False):
+        '''
+        get thing from appspace
+
+        @param label: appspaced thing label
+        @param key: `appspace` key (default: False)
+        '''
+        # use internal key if key label == internal key
+        key = self._key if key == self._root else self.namespace(key)
+        app = self.lookup1(key, key, label)
+        if app is None:
+            raise AppLookupError(app, label)
+        return self.load(label, key, app)
+
+    def namespace(self, label):
+        '''
+        fetch key
+
+        @param label: `appspace` key label
+        '''
+        this = self.lookup1(ANamespace, ANamespace, label)
+        if this is None:
+            raise AppLookupError(this, label)
+        return this
+
+    def set(self, thing=False, label=False, key=False):
+        '''
+        add thing to `appspace`
+
+        @param thing: new `appspace` thing (default: False)
+        @param label: new `appspace` thing label (default: False)
+        @param key: key label (default: False)
+        '''
+        thing = self._lazy(thing)
+        key = self.namespace(key) if key else self._key
+        self.register([key], key, self.safename(label), thing)
+        return thing
+
+    @classmethod
+    def slugify(cls, value):
+        '''
+        normalizes string, converts to lowercase, removes non-alpha characters,
+        and converts spaces to hyphens
+        '''
+        return cls._second('-', u(cls._first(
+            '', normalize('NFKD', value).encode('ascii', 'ignore')
+        ).strip().lower()))
+
+
 class Registry(RegistryMixin, AppStore):
 
     '''easy registry'''
     '''strict registry'''
 
     __slots__ = ('_current', '_root', '_key')
+
+
+@appifies(AManager)
+class Manager(ManagerMixin, Registry):
+
+    '''state manager'''
+
+    __slots__ = ('_current', '_root', '_key')
+
+
+@appifies(AManager)
+class StrictManager(ManagerMixin, StrictRegistry):
+
+    '''strict manager'''
+
+    __slots__ = ('_current', '_root', '_key')
+
+keyed = Manager.keyed

appspace/spaces.py

-# -*- coding: utf-8 -*-
-'''appspace spaces'''
-
-from functools import partial
-from itertools import starmap
-
-from stuf.six import strings
-from stuf.utils import selfname, exhaust, exhaustmap, twoway
-
-from appspace.utils import lazyimport
-from appspace.managers import Manager, StrictManager
-from appspace.keys import ABranch, ANamespace, AApp, appifies
-
-__all__ = ('Branch', 'Namespace', 'Patterns', 'include', 'patterns')
-
-
-class _Filter(object):
-
-    @classmethod
-    def _filter(self, x):
-        return not x[0].startswith('_')
-
-
-class Patterns(_Filter):
-
-    '''patterns for manager configured by class'''
-
-    key = AApp
-    strict = False
-
-    @twoway
-    def _manager(self):
-        '''manager class'''
-        return StrictManager if self.strict else Manager
-
-    @classmethod
-    def build(cls):
-        '''build manager configuration from class'''
-        l = selfname(cls)
-        # set key
-        key = cls.key
-        if isinstance(key, strings):
-            # load key if string
-            key = lazyimport(key)
-        manager = cls._manager(l, key)  # pylint: disable-msg=e1121
-        b = partial(manager.keyed, ABranch)
-        m, n = manager.set, partial(manager.keyed, ANamespace)
-        t = lambda x, y: y.build(manager) if (n(y) or b(y)) else m(y, x, l)
-        exhaustmap(vars(cls), t, cls._filter)
-        return manager
-
-    @staticmethod
-    def factory(label, manager, *args):
-        '''
-        factory for manager
-
-        @param label: label for manager
-        '''
-        # build manager
-        manager = manager(label)
-        # register things in manager
-        exhaust(starmap(lambda x, y: manager.set(y, x), iter(args)))
-        return manager
-
-    @classmethod
-    def patterns(cls, label, *args):
-        '''
-        configure appspace
-
-        @param label: name of branch appspace
-        @param *args: tuple of module paths or component inclusions
-        '''
-        return cls.factory(label, cls._manager, *args)
-
-
-class _PatternMixin(_Filter):
-
-    @classmethod
-    def _key(cls, label, manager):
-        try:
-            # lazily load key
-            key = cls.key
-            if isinstance(key, strings):
-                key = lazyimport(key)
-            # register class key
-            manager.ez_register(ANamespace, label, key)
-        except AttributeError:
-            key = manager.key(ANamespace, label)
-
-
-@appifies(ANamespace)
-class Branch(_PatternMixin):
-
-    '''branch configuration'''
-
-    @classmethod
-    def build(cls, manager):
-        '''gather branch configuration'''
-        cls._key(selfname(cls), manager)
-        i, m = cls.include, manager.set
-        t = lambda x: not x[0].startswith('_') or isinstance(x[1], strings)
-        exhaustmap(vars(cls), lambda x, y: m(i(y), x), t)
-
-    @staticmethod
-    def include(module):
-        '''
-        configure branch appspace
-
-        @param module: module import path
-        '''
-        return ('include', module)
-
-
-@appifies(ANamespace)
-class Namespace(_PatternMixin):
-
-    '''configuration namespace'''
-
-    @classmethod
-    def build(cls, manager):
-        '''gather namespace configuration'''
-        label = selfname(cls)
-        cls._key(label, manager)
-        m, n = manager.set, partial(manager.keyed, ANamespace)
-        t = lambda k, v: v.build(manager) if n(v) else m(v, k, label)
-        exhaustmap(vars(cls), t, cls._filter)
-
-
-factory = Patterns.factory
-include = Branch.include
-space_patterns = Patterns.patterns

appspace/utils.py

 
 from stuf.six import strings
 
-__all__ = ('checkname', 'lazyimport')
-
 
 def lazyimport(path, attribute=None):
     '''