Added cmd.funcpart as a way of adding multiple-part commands, each with a possibility to yield with a deferred. This allows for flexible implementation of delayed commands and other asynchronous goodies.

This commit is contained in:
Griatch 2013-02-19 23:30:33 +01:00
parent 47356ca632
commit 0121f36ac0
2 changed files with 9 additions and 4 deletions

View file

@ -43,7 +43,7 @@ from src.comms.channelhandler import CHANNELHANDLER
from src.utils import logger, utils
from src.commands.cmdset import CmdSet
from src.commands.cmdparser import at_multimatch_cmd
from src.utils.utils import string_suggestions
from src.utils.utils import string_suggestions, make_iter
from django.utils.translation import ugettext as _
@ -254,7 +254,7 @@ def cmdhandler(caller, raw_string, testing=False):
cmd.raw_string = unformatted_raw_string
if hasattr(cmd, 'obj') and hasattr(cmd.obj, 'scripts'):
# cmd.obj are automatically made available.
# cmd.obj is automatically made available.
# we make sure to validate its scripts.
yield cmd.obj.scripts.validate()
@ -270,6 +270,11 @@ def cmdhandler(caller, raw_string, testing=False):
# (return value is normally None)
ret = yield cmd.func()
if hasattr(cmd, "funcparts"):
# yield on command parts (for multi-part delayed commands)
for funcpart in make_iter(cmd.funcparts):
yield funcpart()
# post-command hook
yield cmd.at_post_cmd()