mirror of https://github.com/aewens/ircevents
Added basis of events engine and infinitedict helper
This commit is contained in:
parent
d648487f38
commit
cb61dbd1ec
|
@ -0,0 +1,30 @@
|
|||
from .helpers import infinitedict
|
||||
|
||||
from collections import namedtuple
|
||||
from threading import Thread, Event
|
||||
from queue import Queue, Empty
|
||||
|
||||
def noop(source):
|
||||
return None
|
||||
|
||||
class Engine:
|
||||
def __init__(self, source):
|
||||
self._source = source
|
||||
self._using = list()
|
||||
self._mutations = infinitedict()
|
||||
|
||||
self._recv_callback = noop
|
||||
|
||||
self._events = Queue()
|
||||
self._actions = Queue()
|
||||
|
||||
def use(self, name, callback):
|
||||
Mutation = namedtuple("Mutation", ["name", "callback"])
|
||||
self._using.append(Mutation(name, callback))
|
||||
|
||||
def recv_with(self, callback):
|
||||
assert callable(callback), f"Expected function but got: {callback}"
|
||||
self._recv_callback = callback
|
||||
|
||||
def run(self):
|
||||
NotImplemented
|
|
@ -3,6 +3,7 @@ from datetime import datetime, timezone
|
|||
from json import dump, dumps, load, loads
|
||||
from functools import wraps
|
||||
from traceback import format_exc
|
||||
from collections import defaultdict
|
||||
|
||||
# Output to stderr instead of stdout
|
||||
def eprint(*args, **kwargs):
|
||||
|
@ -87,3 +88,7 @@ def trap(callback):
|
|||
return wrapper_trap
|
||||
|
||||
return decorator_trap
|
||||
|
||||
# Arbitrary depth dict that returns an empty dict if key is not set
|
||||
def infinitedict():
|
||||
return defaultdict(infinitedict)
|
||||
|
|
Loading…
Reference in New Issue