From 7acb68d2eea2fce9e742538e15f976f3bd92c13c Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 26 May 2016 15:38:19 -0700 Subject: [PATCH] allow WelcomeError to interrupt input_code() --- src/wormhole/wormhole.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wormhole/wormhole.py b/src/wormhole/wormhole.py index ec47cbf..31d7c4e 100644 --- a/src/wormhole/wormhole.py +++ b/src/wormhole/wormhole.py @@ -228,6 +228,7 @@ class _Wormhole: self._started_get_code = False self._get_code = None self._started_input_code = False + self._input_code_waiter = None self._code = None self._nameplate_id = None self._nameplate_state = CLOSED @@ -450,8 +451,11 @@ class _Wormhole: ic = _InputCode(self._reactor, prompt, code_length, self._ws_send_command, self._timing) self._response_handle_nameplates = ic._response_handle_nameplates - # TODO: signal_error - code = yield ic.go() + # we reveal the Deferred we're waiting on, so _signal_error can + # wake us up if something goes wrong (like a welcome error) + self._input_code_waiter = ic.go() + code = yield self._input_code_waiter + self._input_code_waiter = None self._event_learned_code(code) returnValue(None) @@ -800,6 +804,8 @@ class _Wormhole: # now errback all API deferreds except close(): get_code, # input_code, verify, get + if self._input_code_waiter and not self._input_code_waiter.called: + self._input_code_waiter.errback(error) for d in self._connection_waiters: # input_code, get_code (early) if self.DEBUG: print("EB cw") d.errback(error)