Beispiel #1
0
            pass

    def query(self, *args, **kw):
        """Call registered hooks (w/given args), yielding each result"""
        if kw:
            for hook in self:
                yield hook(*args, **kw)
        elif args:
            for hook in self:
                yield hook(*args)
        else:
            for hook in self:
                yield hook()


struct(Hook)
def Hook(group, impl=None):
    """Easy access to a specific entry point or group of entry points"""
    return group, impl





_implementations = {}     # global implementation registry

class PluginManager(context.Service):
    """Manage plugin eggs"""

    def addEntryPoint(self, group, impl, ob):
        """Register an object as a hook"""
Beispiel #2
0
    return action

# Rules management

def abstract(func=None):
    """Declare a function to be abstract"""
    if func is None:
        return decorate_assignment(
            lambda f,n,func,old: Dispatching(func).as_abstract()
        )
    else:
        return Dispatching(func).as_abstract()

next_sequence = itertools.count().next

struct()
def Rule(body, predicate=(), actiontype=None, sequence=None):
    if sequence is None:
        sequence = next_sequence()
    return body, predicate, actiontype, sequence

struct()
def ParseContext(
    body, actiontype=None, localdict=(), globaldict=(), lineno=None, sequence=None
):
    """Hold information needed to parse a predicate"""
    if sequence is None:
        sequence = next_sequence()
    return body, actiontype, dict(localdict), dict(globaldict), lineno, sequence

def parse_rule(engine, predicate, context, cls):
Beispiel #3
0
    
    Note that a Disjunction can never have less than 2 members, as creating a
    Disjunction with only 1 item returns that item, and creating one with no
    items returns ``False`` (as no acceptable conditions means "never true").
    """
    __slots__ = ()

    def __new__(cls, input):
        if cls is Disjunction:
            return DisjunctionSet(input)
        return super(Disjunction, cls).__new__(cls)


when(negate, (Disjunction, ))(lambda c: reduce(intersect, map(negate, c)))

struct()


def Range(lo=(Min, -1), hi=(Max, 1)):
    if hi <= lo: return False
    return lo, hi


struct()


def Value(value, match=True):
    return value, match


when(implies, (Value, Range))(
Beispiel #4
0
                            if dependent.dirty():
                                ctrl.schedule(dependent)

                # process reads in normal fashion
                ctrl._process_reads(self)

            except:
                ctrl.reads.clear()
                ctrl.writes.clear()
                raise           
        finally:
            ctrl.current_listener = None

Pause = symbols.Symbol('Pause', __name__)

decorators.struct()
def Return(value):
    """Wrapper for yielding a value from a task"""
    return value,








def resume():
    """Get the result of a nested task invocation (needed for Python<2.5)"""
    c = trellis.ctrl.current_listener
    if not isinstance(c, TaskCell):
    Note that a Disjunction can never have less than 2 members, as creating a
    Disjunction with only 1 item returns that item, and creating one with no
    items returns ``False`` (as no acceptable conditions means "never true").
    """

    __slots__ = ()

    def __new__(cls, input):
        if cls is Disjunction:
            return DisjunctionSet(input)
        return super(Disjunction, cls).__new__(cls)


when(negate, (Disjunction,))(lambda c: reduce(intersect, map(negate, c)))

struct()


def Range(lo=(Min, -1), hi=(Max, 1)):
    if hi <= lo:
        return False
    return lo, hi


struct()


def Value(value, match=True):
    return value, match

Beispiel #6
0
    return action

# Rules management

def abstract(func=None):
    """Declare a function to be abstract"""
    if func is None:
        return decorate_assignment(
            lambda f,n,func,old: Dispatching(func).as_abstract()
        )
    else:
        return Dispatching(func).as_abstract()

next_sequence = getattr(itertools.count(), NEXT)

struct()
def Rule(body, predicate=(), actiontype=None, sequence=None):
    if sequence is None:
        sequence = next_sequence()
    return body, predicate, actiontype, sequence

struct()
def ParseContext(
    body, actiontype=None, localdict=(), globaldict=(), lineno=None, sequence=None
):
    """Hold information needed to parse a predicate"""
    if sequence is None:
        sequence = next_sequence()
    return body, actiontype, dict(localdict), dict(globaldict), lineno, sequence

def parse_rule(engine, predicate, context, cls):