callchain / callchain / key /

# -*- coding: utf-8 -*-
'''callchain reset keys'''

from appspace.keys import Attribute

from callchain.key.base import KResetLocal, KCore

class KChain(KResetLocal):

    '''chain key'''

    def chain(call, key=False, *args, **kw):  # @NoSelf
        add `call` or appspaced `call` to call chain, partializing it with any
        passed arguments

        @param call: call or appspaced call label
        @param key: appspace key (default: False)

    def clear():  # @NoSelf
        '''clear things'''

    def tap(call, key=False):  # @NoSelf
        add call

        @param call: callable or appspace label
        @param key: link call chain key (default: False)

    def wrap(call, key=False):  # @NoSelf
        '''build current callable from factory'''

class KEvent(KChain):

    '''event chain key'''

    def on(event, call, key=False, *args, **kw):  # @NoSelf
        bind call to `event`

        @param event: event label
        @param call: label for call or eventspaced thing
        @param key: key label (default: False)

    def off(event):  # @NoSelf
        clear calls bound to `event`

        @param event: event label

    def trigger(*events):  # @NoSelf
        extend primary call chain with partials bound to `events`

        @param *events: event labels

class KCall(KResetLocal):

    '''call key'''

    L = Attribute('local settings extracted')
    Meta = Attribute('local settings')
    port = Attribute('python 2.x <-> python 3.x porting helper')
    space = Attribute('external appspace interface')

    def __enter__():  # @NoSelf
        '''enter execution context'''

    def __exit__(e, t, b):  # @NoSelf
        '''exit execution context'''

    def switch(label, key=False):  # @NoSelf
        overt switch to linked chain configured in external appspace

        @param label: linked chain label
        @param key: linked chain chain key (default: False)

    def commit():  # @NoSelf
        '''consume call chain'''

class KEventCall(KCall):

    '''event call key'''

    def fire(*events):  # @NoSelf
        run calls bound to `events` **NOW**

        @param *events: event labels

    def queues(*events):  # @NoSelf
        ordered mapping of processing queues for `events`

        @param *events: event labels

class KBranch(KCore):

    ''''branch key'''

    G = Attribute('root external global settings')
    M = Attribute('root external appspace manager')
    _G = Attribute('root internal global settings')
    _M = Attribute('root internal appspace manager')
    root = Attribute('root object')

class KEventBranch(KBranch):

    '''event branch key'''

    E = Attribute('local event registry')