add deferred_read.py, to defer parsing of *some* lines until after 001

This commit is contained in:
jesopo 2019-06-22 22:22:50 +01:00
parent 6e93b1e990
commit 29f5b7caf2

23
modules/deferred_read.py Normal file
View file

@ -0,0 +1,23 @@
from src import EventManager, ModuleManager, utils
# postpone parsing SOME lines until after 001
class Module(ModuleManager.BaseModule):
@utils.hook("new.server")
def new_server(self, event):
event["server"]._deferred_read = []
@utils.hook("raw.received.001", priority=EventManager.PRIORITY_LOW)
def on_001(self, event):
lines = event["server"]._deferred_read[:]
event["server"]._deferred_read.clear()
for line in lines:
self.events.on("raw.received").call(line=line,
server=event["server"])
@utils.hook("raw.received.mode", priority=EventManager.PRIORITY_HIGH)
def defer(self, event):
if not event["server"].connected:
event.eat()
event["server"]._deferred_read.append(event["line"])