class IRecipe(IBravoPlugin): """ Recipe for crafting materials from other materials. """ invariant(recipe_invariant) dimensions = Attribute(""" Tuple representing the size of the recipe. """) recipe = Attribute(""" Tuple representing the items of the recipe. Recipes need to be filled out left-to-right, top-to-bottom, with one of two things: * A tuple (slot, count) for the item/block that needs to be present; * None, if the slot needs to be empty. """) provides = Attribute(""" Tuple representing the yield of this recipe. This tuple must be of the format (slot, count). """)
class IConnection(IIndexableWrapper): entity_id = Attribute( 'Unique Id of entity for which connections are described') connected_to = Attribute( 'Ids of entities to which this entity is connected') layers = Attribute('Names of layers for which this connections exists') invariant(check_connection)
class ICommand(IBravoPlugin): """ A command. Commands must be documented, as an invariant. The documentation for a command will be displayed for clients upon request, via internal help commands. """ invariant(command_invariant) aliases = Attribute(""" Additional keywords which may be used to alias this command. """) usage = Attribute(""" String explaining how to use this command. """)
class ISortedPlugin(IBravoPlugin): """ Parent interface for sorted plugins. Sorted plugins have an innate and automatic ordering inside lists thanks to the ability to advertise their dependencies. """ invariant(sorted_invariant) before = Attribute(""" Plugins which must come before this plugin in the pipeline. Should be a tuple, list, or some other iterable. """) after = Attribute(""" Plugins which must come after this plugin in the pipeline. Should be a tuple, list, or some other iterable. """)
class IWorker(Interface): """ Provided by worker objects that can have tasks assigned to them for processing. All worker objects are considered qualified to run tasks of the default C{None} series. To indicate that subclasses or subclass instances are qualified to run tasks of user-defined series in addition to the default, the hashable object that identifies the additional series must be listed in the C{cQualified} or C{iQualified} class or instance attributes, respectively. """ cQualified = Attribute( """ A class-attribute list containing all series for which all instances of the subclass are qualified to run tasks. """) iQualified = Attribute( """ An instance-attribute list containing all series for which the subclass instance is qualified to run tasks. """) def _check_qualifications(ob): """ Qualification attributes must be present as lists. """ for attrName in ('cQualified', 'iQualified'): x = getattr(ob, attrName, None) if not isinstance(x, list): raise errors.InvariantError(ob) invariant(_check_qualifications) def setResignator(callableObject): """ Registers the supplied I{callableObject} to be called if the worker deems it necessary to resign, e.g., a remote connection has been lost. """ def run(task): """ Adds the task represented by the specified I{task} object to the list of tasks pending for this worker, to be run however and whenever the worker sees fit. However, workers are expected to run highest-priority tasks before anything else they have lined up in their mini-queues. Unless the worker is constructed with a C{raw=True} keyword or the task includes C{raw=True}, an iterator resulting from the task is converted into an instance of L{iteration.Deferator}. The underlying iteration (possibly across a pipe or wire) must be handled transparently to the user. If the task has a I{consumer} keyword set to an implementor of C{IConsumer}, an L{iteration.IterationProducer} coupled to that consumer will be the end result instead. Make sure that any callbacks you add to the task's internal deferred object C{task.d} return the callback argument. Otherwise, the result of your task will be lost in the callback chain. @return: A C{Deferred} that fires when the worker is ready to be assigned another task. """ def stop(): """ Attempts to gracefully shut down the worker, returning a C{Deferred} that fires when the worker is done with all assigned tasks and will not cause any errors if the reactor is stopped or its object is deleted. The C{Deferred} returned by your implementation of this method must not fire until B{after} the results of all pending tasks have been obtained. Thus the deferred must be chained to each C{task.d} somehow. Make sure that any callbacks you add to the task's internal deferred object C{task.d} return the callback argument. Otherwise, the result of your task will be lost in the callback chain. """ def crash(): """
class IWorker(Interface): """ Provided by worker objects that can have tasks assigned to them for processing. All worker objects are considered qualified to run tasks of the default C{None} series. To indicate that subclasses or subclass instances are qualified to run tasks of user-defined series in addition to the default, the hashable object that identifies the additional series must be listed in the C{cQualified} or C{iQualified} class or instance attributes, respectively. """ cQualified = Attribute( """ A class-attribute list containing all series for which all instances of the subclass are qualified to run tasks. """) iQualified = Attribute( """ An instance-attribute list containing all series for which the subclass instance is qualified to run tasks. """) def _check_qualifications(ob): """ Qualification attributes must be present as lists. """ for attrName in ('cQualified', 'iQualified'): x = getattr(ob, attrName, None) if not isinstance(x, list): raise errors.InvariantError(ob) invariant(_check_qualifications) def setResignator(callableObject): """ Registers the supplied I{callableObject} to be called if the worker deems it necessary to resign, e.g., a remote connection has been lost. """ def run(task): """ Adds the task represented by the specified I{task} object to the list of tasks pending for this worker, to be run however and whenever the worker sees fit. Make sure that any callbacks you add to the task's internal deferred object C{task.d} return the callback argument. Otherwise, the result of your task will be lost in the callback chain. @return: A deferred that fires when the worker is ready to be assigned another task. """ def stop(): """ Attempts to gracefully shut down the worker, returning a deferred that fires when the worker is done with all assigned tasks and will not cause any errors if the reactor is stopped or its object is deleted. The deferred returned by your implementation of this method must not fire until B{after} the results of all pending tasks have been obtained. Thus the deferred must be chained to each C{task.d} somehow. Make sure that any callbacks you add to the task's internal deferred object C{task.d} return the callback argument. Otherwise, the result of your task will be lost in the callback chain. """ def crash(): """
class ISubInvariant(IInvariant): invariant(BarGreaterThanFoo)
class IInvariant(Interface): foo = Attribute('foo') bar = Attribute('bar; must eval to Boolean True if foo does') invariant(ifFooThenBar)
class ICollidable(Interface): bounding_box = Attribute("Object's bounding box") invariant(lambda self: verifyObject(IBBox, self.bounding_box))