Generic class for managing events generated by an application
Project description
GenericEventsManager
Overview
It is a generic class for managing events generated by an application.
Installing GenericEventsManager and Supported Versions
GenericEventsManager is available on PyPI:
$ python -m pip install generic-events-manager
GenericEventsManager officially supports Python 3.8+.
Cloning the repository
$ git clone https://github.com/tatianno/generic-events-manager.git
Example
from events_manager import GenericEventsManager
from events_manager.entities import GenericObserver
class CustomObserver(GenericObserver):
def _exec_routine_update_obj(self, obj_new: GenericEventsManager.EventObject, obj_old: GenericEventsManager.EventObject) -> None:
'''
Method called each time the observed object changes state
'''
print(f'The object {obj_new.key} has been updated with the state {obj_new.state}')
print(f'The previous state was {obj_old.state}')
def _exec_routine_delete_obj(self, obj: GenericEventsManager.EventObject) -> None:
'''
Method called when observed object is deleted
'''
print(f'The object {obj.key} has been deleted')
class CustomEventsManager(GenericEventsManager):
class EventObject(GenericEventsManager.EventObject):
observer_class = CustomObserver
def create(self, entity: EventObject) -> None:
self.perfom_create(entity)
def update(self, entity: EventObject) -> None:
old_entity = self.get(entity.get_key())
self.perfom_update(entity, old_entity)
def delete(self, entity: EventObject) -> None:
self.perfom_destroy(entity)
# Instantiating the Event Handler and Observer
events_manager = CustomEventsManager()
observer = CustomObserver()
# Dictionary containing event data
data = {
'state' : 'ON',
'key' : 'k1'
}
# Updating the object with the received event data
response = events_manager.event_update(data)
# Subscribing observer
obj = events_manager.get('k1')
obj.subscribe(observer)
# Dictionary containing event data
data = {
'state' : 'OFF',
'key' : 'k1'
}
# Updating the object with the received event data
response = events_manager.event_update(data)
# Deleting object
obj = events_manager.get('k1')
events_manager.delete(obj)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file generic_events_manager-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: generic_events_manager-0.0.6-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 448351f2cef0d116015f015fa4dc80cfaebc2d19e5ea51f6a8c2b24465482418 |
|
MD5 | e17820f53d0c2475187949f3358091fe |
|
BLAKE2b-256 | 974bb95e684121e131f883d630f8dd6f197256e4cf088e6f1ce151c8285428f4 |