Audit events¶
py-capellambse fires sys.audit()
events for certain calls in the
high-level API. These events can be inspected by a callable registered with
sys.addaudithook()
.
Warning
System audit hooks cannot be removed once they were registered. When storing a reference to a model in an audit hook, make sure that the reference is destroyed properly to avoid unnecessary memory consumption.
Also refer to the capellambse.auditing.AttributeAuditor
for an
example class that records read access to all attributes in a model using the
capellambse.getattr
audit event.
For programmatic use, a set of all events that signify changes to the model is
available as the events
class variable on the
WriteProtector
.
List of audit events fired by py-capellambse¶
The following table shows all audit events that are fired by capellambse
.
Note
For some calls, multiple events may be fired. For example, a
capellambse.create
event is always followed by another event (such as
capellambse.insert
) when adding the newly created object to the model
tree.
Event |
Description |
---|---|
Added in version 0.5.11. |
An attribute is accessed for reading. Arguments:
Note This event will also be fired for internal read accesses, for example when searching the model for references to another object. Currently there is no reliable way to distinguish between explicit (user) access and these internal calls. |
Added in version pre-0.5. Deprecated since version 0.5.11: Use the |
Deprecated alias of
|
Added in version 0.5.11. |
An attribute is about to be changed. Arguments:
|
Added in version 0.5.11. |
An object or a list of objects is about to be deleted from the model. This is also fired when purging left-over references while deleting another object. Arguments:
|
Added in version 0.5.11. |
An item is about to be inserted into a
coupled Arguments:
|
Added in version 0.5.11. |
A new object was just created, but is not yet part of the model. Arguments:
|
Implementation notes¶
Audit events are generally fired from these locations:
Read access events (i.e.
capellambse.getattr
) are fired by each Accessor subclass, just before returning the final value from__get__()
.Events that signify modifications to a list are fired by the overridden methods in
CoupledElementListMixin
(includecreate
), as well as by__setattr__()
ofGenericElement
, before passing the values on to the actual accessor implementation.The
capellambse.delete
event for deleting an entire attribute (i.e. the case where theindex
argument isNone
) is fired by the relevant Accessor’s__delete__()
method.Note that for lists, Accessors may instead fire individual
delete
events for each list item.
In order to prevent audit events from being fired for elements that are still
under construction, GenericElement
keeps track of the construction state in
the _constructed
attribute. It becomes True when construction is finished
and audit events may be fired. Accessors must not fire any audit events if the
object they’re acting on has not been fully constructed.