from metasqlobject.eventhub import Signal class ClassCreateSignal(Signal): """ Signal raised after class creation. The sender is the superclass (in case of multiple superclasses, the first superclass). The arguments are ``(new_class_name, bases, new_attrs, post_funcs, early_funcs)``. ``new_attrs`` is a dictionary and may be modified (but ``new_class_name`` and ``bases`` are immutable). ``post_funcs`` is an initially-empty list that can have callbacks appended to it. Note: at the time this event is called, the new class has not yet been created. The functions in ``post_funcs`` will be called after the class is created, with the single arguments of ``(new_class)``. Also, ``early_funcs`` will be called at the soonest possible time after class creation (``post_funcs`` is called after the class's ``__classinit__``). """ # @@: Should there be a class reload event? This would allow modules # to be reloaded, possibly. Or it could even be folded into # ClassCreateSignal, since anything that listens to that needs to pay # attention to reloads (or else it is probably buggy). class RowCreateSignal(Signal): """ Called before an instance is created, with the class as the sender. Called with the arguments ``(kwargs, post_funcs)``. There may be a ``connection`` argument. ``kwargs`` may be usefully modified. ``post_funcs`` is a list of callbacks, intended to have functions appended to it, and are called with the arguments ``(new_instance)``. Note: this is not called when an instance is created from an existing database row. """ # @@: An event for getting a row? But for each row, when doing a # select? For .sync, .syncUpdate, .expire? class RowDestroySignal(Signal): """ Called before an instance is deleted. Sender is the instance's class. Arguments are ``(instance, post_funcs)``. You cannot cancel the delete, but you can raise an exception (which will probably cancel the delete, but also cause an uncaught exception if not expected). Note: this is not called when an instance is destroyed through garbage collection. post_funcs are called like post_func(soclass, id_that_was_deleted) @@: Should this allow ``instance`` to be a primary key, so that a row can be deleted without first fetching it? """ class RowUpdateSignal(Signal): """ Called when an instance is updated through a call to ``.set()``. The arguments are ``(instance, kwargs)``. ``kwargs`` can be modified. This is run *before* the instance is updated; if you want to look at the current values, simply look at ``instance``. """ class AddColumnSignal(Signal): """ Called when a column is added to a class, with arguments ``(cls, connection, column_name, column_definition, changeSchema, post_funcs)``. This is called *after* the column has been added, and is called for each column after class creation. post_funcs are called with ``(cls, so_column_obj)`` """ class DeleteColumnSignal(Signal): """ Called when a column is removed from a class, with the arguments ``(cls, connection, column_name, so_column_obj, post_funcs)``. Like ``AddColumnSignal`` this is called after the action has been performed, and is called for subclassing (when a column is implicitly removed by setting it to ``None``). post_funcs are called with ``(cls, so_column_obj)`` """ # @@: Signals for indexes and joins? These are mostly event consumers, # though. class TableSQLSignal(Signal): """ Called when the SQL for a table is generated. If ``if_not_exists==True`` and the table exists, this event is not called. Called with ``(cls, connection, create_sql, lazy_sql, create_context)``. Each of the ``*_sql`` values is a list that can be appended to, and contains the SQL already being sent. ``create_context`` is a dictionary object or None, which is a place to store information that will be accessible to *all* events in a single create sequence (this can be used to detect if a table *will* be created, even if it has not yet been created). """ class DropTableSignal(Signal): """ Called when a table is dropped. If ``ifExists==True`` and the table doesn't exist, this event is not called. Called with ``(cls, connection, cascade, post_funcs)``. ``post_funcs`` functions are called with ``(cls, connection)`` after the table has been dropped. """ __all__ = [] for name, value in globals().items(): if isinstance(value, type) and issubclass(value, Signal): __all__.append(name)