[gnome-keysign] discover: restructured start function to have a single return
- From: Tobias Mueller <tobiasmue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keysign] discover: restructured start function to have a single return
- Date: Fri, 15 Jun 2018 18:45:29 +0000 (UTC)
commit 67c6813339db4782453d11f0d69ea4de606f85e0
Author: Tobias Mueller <muelli cryptobitch de>
Date: Fri Jun 15 16:50:44 2018 +0200
discover: restructured start function to have a single return
The intention is to make it a bit more readable and thus easier to
comprehend. Now that every branch assigns all required values, we can
arguably follow the flow more easily.
It nicely fixes a weirdly logged statement: We logged "Recived key
successfully" although it wasn't clear yet.
keysign/discover.py | 59 +++++++++++++++++++++++++++++++++--------------------
1 file changed, 37 insertions(+), 22 deletions(-)
---
diff --git a/keysign/discover.py b/keysign/discover.py
index b1f7696..3d22764 100644
--- a/keysign/discover.py
+++ b/keysign/discover.py
@@ -37,37 +37,52 @@ class Discover:
try:
key_data = yield threads.deferToThread(self.discovery.find_key, self.userdata)
- log.debug("Received key successfully")
except ValueError as e:
key_data = None
success = False
message = "Error downloading key, maybe it has been altered in transit"
log.warning(message, exc_info=e)
- returnValue((key_data, success, message))
+ else:
+ # Actually.. key_data can very well be None as an indication of failure. We might change that
API to throw.
+ log.debug("We may have found a key: %r", key_data)
- if key_data and not self.stopped:
- success = True
+ if self.stopped:
+ key_data = None
+ success = False
message = ""
- returnValue((key_data, success, message))
- if self.bt_code and not self.stopped:
- # We try Bluetooth, if we have it
- log.info("Trying to connect to %s with Bluetooth", self.bt_code)
- # We try to see if Bluetooth was imported,
- # else we log an event of missing Pybluez.
- try:
- self.bt = BluetoothReceive(self.bt_port)
- msg_tuple = yield self.bt.find_key(self.bt_code, self.mac)
- key_data, success, message = msg_tuple
- if key_data:
- # If we found the key
- returnValue((key_data, success, message))
- except TypeError as e:
- log.exception("Pybluez may be missing.")
- key_data = None
- success = False
- message = ""
+ else:
+ if key_data:
+ success = True
+ message = ""
+ elif self.bt_code:
+ # We try Bluetooth, if we have it
+ log.info("Trying to connect to %s with Bluetooth", self.bt_code)
+ # We try to see if Bluetooth was imported,
+ # else we log an event of missing Pybluez.
+ try:
+ self.bt = BluetoothReceive(self.bt_port)
+ msg_tuple = yield self.bt.find_key(self.bt_code, self.mac)
+ except TypeError as e:
+ key_data = None
+ success = False
+ message = ""
+ log.exception("Pybluez may be missing.")
+ else:
+ key_data, success, message = msg_tuple
+ if key_data:
+ # If we found the key
+ log.debug("Found the key via bluetooth: %r", key_data[:32])
+ else:
+ message = ""
+ success = False
+ key_data = None
+ log.warning("Neither key_data nor btcode. Weird")
+
+ log.debug("Returning key: %r, succes: %r, message: %r",
+ key_data, success, messages)
returnValue((key_data, success, message))
+
def stop(self):
self.stopped = True
if self.bt:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]