Source

graphalchemy / graphalchemy / tests / core.py

Full commit
# -*- coding: utf-8 -*-
'''spine core keys'''

from appspace.keys import AppspaceKey

__all__ = ('KManager', 'KThing', 'KSession', 'KWorker')

###############################################################################
## descriptor keys ############################################################
###############################################################################


class KDefer(AppspaceKey):

    '''defer key'''


class KDirect(AppspaceKey):

    '''direct key'''


class KRefactory(AppspaceKey):

    '''factory key'''


class KFactory(AppspaceKey):

    '''factory key'''


class KCall(AppspaceKey):

    '''call key'''


class KMethod(AppspaceKey):

    '''method key'''


class KExtend(AppspaceKey):

    '''extension key'''


class KReextend(AppspaceKey):

    '''extension key'''


class KJoin(AppspaceKey):

    '''extension key'''


###############################################################################
## constants ##################################################################
###############################################################################


class NoDefault(object):

    '''no default'''

    def generate(self, klass):
        '''generator'''


class Undefined(object):

    '''undefined value'''


NoDefault = NoDefault()
Undefined = Undefined()


class KManager(AppspaceKey):

    '''manager key'''


class KThing(AppspaceKey):

    '''thing key'''


class KSession(AppspaceKey):

    '''session key'''


class KWorker(AppspaceKey):

    '''worker key'''


class KWorkflow(KManager):

    '''traits key'''


class KControl(KSession):

    '''control key'''


class KProcess(KWorker):

    '''control key'''


class KState(KWorker):

    '''activity marker'''


class KTraits(KThing):

    '''traits property key'''


class KTrait(AppspaceKey):

    '''trait property key'''


class TraitError(Exception):

    '''trait error'''


class ValidationError(Exception):

    '''validation error'''
    
    
# -*- coding: utf-8 -*-
'''spine core'''

from stuf.utils import lazy

from callchain import inside

from spine.apps import spine
from spine.config import Required
from callchain.lazy_auto.chainlet import chainlet
from callchain.lazy_auto.chain import callchain

__all__ = ['Spine']


class Spinelet(chainlet):

    '''appspace spinelet'''

    @property
    def Session(self):
        '''configured session class'''
        return self._configure(self.namespace.session)

    @property
    def Thing(self):
        '''configured thing class'''
        return self._configure(self.namespace.thing)

    @property
    def Worker(self):
        '''configured worker class'''
        return self._configure(self.namespace.worker)


class Descriptor(chainlet):

    '''descriptor services'''

    @lazy
    def app(self):
        '''app descriptor'''
        return self._get(self.namespace.app)

    @lazy
    def call(self):
        '''call descriptor'''
        return self._get(self.namespace.call)

    @lazy
    def factory(self):
        '''factory descriptor'''
        return self._get(self.namespace.factory)

    @lazy
    def extend(self):
        '''extend class descriptor'''
        return self._get(self.namespace.extend)

    @lazy
    def defer(self):
        '''defer method descriptor'''
        return self._get(self.namespace.defer)

    @lazy
    def join(self):
        '''join session descriptor'''
        return self._get(self.namespace.join)

    @lazy
    def method(self):
        '''method descriptor'''
        return self._get(self.namespace.method)

    @lazy
    def refactory(self):
        '''refactory descriptor'''
        return self._get(self.namespace.refactory)

    @lazy
    def reextend(self):
        '''reextend class descriptor'''
        return self._get(self.namespace.reextend)


@inside(spine, Required)
class Spine(callchain):

    '''appspace spine'''

    @lazy
    def context(self):
        '''context services'''
        return Spinelet(self, 'context')

    @lazy
    def event(self):
        '''event services'''
        return Spinelet(self, 'event')

    @lazy
    def process(self):
        '''process services'''
        return Spinelet(self, 'process')

    @lazy
    def workflow(self):
        '''workflow services'''
        return Spinelet(self, 'workflow')

    @lazy
    def descriptor(self):
        '''descriptor services'''
        return Descriptor(self)