from core.util import
Defines Event and Command classes, as well as additional View and Queue classes that support them in a system able to reload itself at any time.
TIMEOUT_INTERVAL = 30
Base Event data. Because there are no methods to call after the original __init__, the same object can be carried across coreloads. Any methods needed to work with Event objects can be added to the EventView, which always wraps any kind of Event.
__init__(self, Type, TypeView, q=None)
Sets member variables as follows:
self.created = time.time() self.started = None self.handled = False self.finished = None self.result = None self.timeout = time.time() + TIMEOUT_INTERVAL self.error = None self.errored = None self.tracebk = None self.canceled = None self.argv = args self.argc = len(args) self.kwargs = kwargs self.private = None self.session = None
Encapsulates an Event object.
__init__(self, ev)
Pass an event object.
__repr__
Returns a type string that describes the event type and identifies the data in the event.
__str__
Returns a string containing data from the event.
timeout
Returns a float; the UNIX time that this event should "timeout".
created
The time this event was created.
started
The time processing started for this event.
handled
A boolean value indicating whether this event has been handled.
finished
The time this event was finished successfully.
errored
The time a fatal error ended this event's processing.
err
The exception error message.
tracebk
Traceback for the error that stopped processing, as returned by util.tracebk(); That is, as an array of lines.
canceled
The time this event was cance
processed
Returns False if the finished, canceled, and errored properties are all False, else True.
result
Returns the result of event handling, as set by the finish() method.
kwargs
Returns a dict containing a copy of the kwargs as set in the event's constructor.
argc
Returns a count of the arguments provided to the event's constructor.
session
A session value may before calling commands that require authentication.
private
A "private" flag may before calling commands whose data should not be displayed or logged.
arg(self, i, d=None)
Retrieve one item from this event's args, or default value d if no such arg exists.
args(self, i=0)
Returns a copy of this event's arguments as a list starting at offset i.
argi(self, i=0)
Returns an iter of this event's arguments as a list starting at offset i.
argstr(self)
Returns the event's arguments as a string.
kwarg(self, name, default=None)
Returns the named 'kwargs' value, or default if no such name exists in the kwargs dict.
start(self)
Sets 'started' time to now only if not already started.
finish(self, result=None)
Sets finished time to now only if not already finished, canceled, or errored. Sets 'handled' to True. Sets result to the given value.
finish(self, result=None)
Pass a fatal exception's arguments to this method as a list or as individual arguments. NOTE: It's important to pass the exception wrapped in a list. EXAMPLE: try: doSomethingFatal() except Exception as ex: c.error(list(ex))
cancel(self)
Cancel processing of this event.
timeoutAt(self, unixTime)
Pass a float: unix time to time out.
timeoutIn(self, secondsFromNow)
Pass a float: seconds from now to timeout.
Base class for command events. The Command class is based on Event, and so has all it's properties and methods. Commands are effective across threads and, like events, can be maintained across a coreload().
Commands may be dispatched internally without any authentication by passing them directly to onCommand. Commands received from outside the running app should be handled via the core.Object class's dispatcher.
It's also important to remember that commands are events, but with the intention of executing an explicit command. While ignored events may pass silently, unhandled commands should cause an exception.
__init__(self, cmd, *args, **kwargs)
Stores argument 'cmd' in in its command property then call's Event.__init__.
__init__(self, c)
Stores argument 'c' in in its command property then call's Event.__init__.
__repr__(self)
Returns a string representation of commands, but only shows the command data if the command is NOT marked private.
__str__(self)
Returns command arguments as string (unless private).
cmd
Returns the command string.
forward
Handy for forwarding a command to a different onCommand method while retaining the recipient's onComplete(). Sets the event's command to arg(offset) and changes arguments to args[offset+1:]; this has the effect of making a command offer the correct "cmd" and arguments to a different target.
An object specialized for text-related events.
__init__(self, text, *args, **kwargs)
Stores the first (required) argument 'text'
__init__(self, ev)
Pass a TextEvent object.
__str__
Returns the text.
text
Returns the text.
Base class for event and command type queues.
__init__(self, Type, TypeView, q=None)
Pass the event/command Type, it's TypeView type, and, optionally, a Queue contining objects of Type.
Type
The type, Type, provided to the constructor.
View
The type, ViewType, provided to the constructor.
__decore__
Decores this object's queue.
empty
Empties this object's queue.
qsize
Returns the size of this object's queue.
get
Pops and returns the next item in the queue.
put
Creates and adds to the queue a new object of type Type and wraps it inside an object of type TypeView (as provided to the constructor).
create
Creates and returns a new object of type Type wrapped inside an object of type TypeView. (This method is used by the put method.)
put
Creates and adds to the queue a new object of type Type and wraps it inside an object of type TypeView (as provided to the constructor).
putview
Puts an existing object of type TypeView (which should contain an object of type Type) into the queue.
A queue wrapper for working with Event data.
A queue wrapper for working with Command data.
A queue wrapper for working with Command data.