Fix cmdhandler regression related to earlier fix. Resolves #2190
This commit is contained in:
parent
68f4e9041a
commit
5b9154d15c
1 changed files with 38 additions and 37 deletions
|
|
@ -174,6 +174,27 @@ def _msg_err(receiver, stringtuple):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _process_input(caller, prompt, result, cmd, generator):
|
||||||
|
"""
|
||||||
|
Specifically handle the get_input value to send to _progressive_cmd_run as
|
||||||
|
part of yielding from a Command's `func`.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
caller (Character, Account or Session): the caller.
|
||||||
|
prompt (str): The sent prompt.
|
||||||
|
result (str): The unprocessed answer.
|
||||||
|
cmd (Command): The command itself.
|
||||||
|
generator (GeneratorType): The generator.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
result (bool): Always `False` (stop processing).
|
||||||
|
|
||||||
|
"""
|
||||||
|
# We call it using a Twisted deferLater to make sure the input is properly closed.
|
||||||
|
deferLater(reactor, 0, _progressive_cmd_run, cmd, generator, response=result)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _progressive_cmd_run(cmd, generator, response=None):
|
def _progressive_cmd_run(cmd, generator, response=None):
|
||||||
"""
|
"""
|
||||||
Progressively call the command that was given in argument. Used
|
Progressively call the command that was given in argument. Used
|
||||||
|
|
@ -206,7 +227,15 @@ def _progressive_cmd_run(cmd, generator, response=None):
|
||||||
else:
|
else:
|
||||||
value = generator.send(response)
|
value = generator.send(response)
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
raise
|
# duplicated from cmdhandler._run_command, to have these
|
||||||
|
# run in the right order while staying inside the deferred
|
||||||
|
cmd.at_post_cmd()
|
||||||
|
if cmd.save_for_next:
|
||||||
|
# store a reference to this command, possibly
|
||||||
|
# accessible by the next command.
|
||||||
|
cmd.caller.ndb.last_cmd = copy(cmd)
|
||||||
|
else:
|
||||||
|
cmd.caller.ndb.last_cmd = None
|
||||||
else:
|
else:
|
||||||
if isinstance(value, (int, float)):
|
if isinstance(value, (int, float)):
|
||||||
utils.delay(value, _progressive_cmd_run, cmd, generator)
|
utils.delay(value, _progressive_cmd_run, cmd, generator)
|
||||||
|
|
@ -216,27 +245,6 @@ def _progressive_cmd_run(cmd, generator, response=None):
|
||||||
raise ValueError("unknown type for a yielded value in command: {}".format(type(value)))
|
raise ValueError("unknown type for a yielded value in command: {}".format(type(value)))
|
||||||
|
|
||||||
|
|
||||||
def _process_input(caller, prompt, result, cmd, generator):
|
|
||||||
"""
|
|
||||||
Specifically handle the get_input value to send to _progressive_cmd_run as
|
|
||||||
part of yielding from a Command's `func`.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
caller (Character, Account or Session): the caller.
|
|
||||||
prompt (str): The sent prompt.
|
|
||||||
result (str): The unprocessed answer.
|
|
||||||
cmd (Command): The command itself.
|
|
||||||
generator (GeneratorType): The generator.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
result (bool): Always `False` (stop processing).
|
|
||||||
|
|
||||||
"""
|
|
||||||
# We call it using a Twisted deferLater to make sure the input is properly closed.
|
|
||||||
deferLater(reactor, 0, _progressive_cmd_run, cmd, generator, response=result)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
# custom Exceptions
|
# custom Exceptions
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -631,22 +639,15 @@ def cmdhandler(
|
||||||
ret = cmd.func()
|
ret = cmd.func()
|
||||||
if isinstance(ret, types.GeneratorType):
|
if isinstance(ret, types.GeneratorType):
|
||||||
# cmd.func() is a generator, execute progressively
|
# cmd.func() is a generator, execute progressively
|
||||||
in_generator = True
|
_progressive_cmd_run(cmd, ret)
|
||||||
try:
|
ret = yield ret
|
||||||
_progressive_cmd_run(cmd, ret)
|
# note that the _progressive_cmd_run will itself run
|
||||||
except StopIteration:
|
# the at_post_cmd etc as it finishes; this is a bit of
|
||||||
# this means func() has run its course
|
# code duplication but there seems to be no way to
|
||||||
in_generator = False
|
# catch the StopIteration here (it's not in the same
|
||||||
yield None
|
# frame since this is in a deferred chain)
|
||||||
else:
|
else:
|
||||||
in_generator = False
|
|
||||||
ret = yield ret
|
ret = yield ret
|
||||||
|
|
||||||
if not in_generator:
|
|
||||||
# this will only run if we are out of the generator for this
|
|
||||||
# cmd, otherwise we would have at_post_cmd run before a delayed
|
|
||||||
# func() finished
|
|
||||||
|
|
||||||
# post-command hook
|
# post-command hook
|
||||||
yield cmd.at_post_cmd()
|
yield cmd.at_post_cmd()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue