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:
parent
47356ca632
commit
0121f36ac0
2 changed files with 9 additions and 4 deletions
|
|
@ -43,7 +43,7 @@ from src.comms.channelhandler import CHANNELHANDLER
|
||||||
from src.utils import logger, utils
|
from src.utils import logger, utils
|
||||||
from src.commands.cmdset import CmdSet
|
from src.commands.cmdset import CmdSet
|
||||||
from src.commands.cmdparser import at_multimatch_cmd
|
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 _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
|
@ -254,7 +254,7 @@ def cmdhandler(caller, raw_string, testing=False):
|
||||||
cmd.raw_string = unformatted_raw_string
|
cmd.raw_string = unformatted_raw_string
|
||||||
|
|
||||||
if hasattr(cmd, 'obj') and hasattr(cmd.obj, 'scripts'):
|
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.
|
# we make sure to validate its scripts.
|
||||||
yield cmd.obj.scripts.validate()
|
yield cmd.obj.scripts.validate()
|
||||||
|
|
||||||
|
|
@ -270,6 +270,11 @@ def cmdhandler(caller, raw_string, testing=False):
|
||||||
# (return value is normally None)
|
# (return value is normally None)
|
||||||
ret = yield cmd.func()
|
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
|
# post-command hook
|
||||||
yield cmd.at_post_cmd()
|
yield cmd.at_post_cmd()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -496,7 +496,7 @@ def uses_database(name="sqlite3"):
|
||||||
engine = settings.DATABASE_ENGINE
|
engine = settings.DATABASE_ENGINE
|
||||||
return engine == "django.db.backends.%s" % name
|
return engine == "django.db.backends.%s" % name
|
||||||
|
|
||||||
def delay(to_return, delay=2, callback=None):
|
def delay(delay=2, retval=None, callback=None):
|
||||||
"""
|
"""
|
||||||
Delay the return of a value.
|
Delay the return of a value.
|
||||||
Inputs:
|
Inputs:
|
||||||
|
|
@ -508,7 +508,7 @@ def delay(to_return, delay=2, callback=None):
|
||||||
"""
|
"""
|
||||||
d = defer.Deferred()
|
d = defer.Deferred()
|
||||||
callb = callback or d.callback
|
callb = callback or d.callback
|
||||||
reactor.callLater(delay, callb, to_return)
|
reactor.callLater(delay, callb, retval)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
_FROM_MODEL_MAP = None
|
_FROM_MODEL_MAP = None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue