From a487b8d9a311928d88fd20489866a5515adff138 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Thu, 26 May 2016 21:41:30 +0000 Subject: [PATCH 3/3] status.py: Fix process_colon_listing function for all gpg versions Remove the UID/UAT [:13] hack to support old and new gpg versions. Add length aware parsing of gpg output and mapping to legend.py classes. Handle cases when gpg output has a different number of fields compared to the COLON_IDENTIFIER based classes in legend.py --- pyGPG/status.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pyGPG/status.py b/pyGPG/status.py index 35be922..5c19984 100644 --- a/pyGPG/status.py +++ b/pyGPG/status.py @@ -236,14 +236,25 @@ class Status(object): @rtype None ''' self.status_msgs.append(msg) - parts = msg.split(':')[:13] + parts = msg.split(':') key = parts.pop(0).upper() #print("STATUS: key", key, ", parts:", parts) + if key in COLON_IDENTIFIERS: status = getattr(legend, key) - if key in ["UID", "UAT"] and len(parts)==10: - parts.extend(['', '']) + length_difference = len(parts) - len(status._fields) + + if length_difference > 0: + # Output has more fields than our library. + # Library needs to be updated with new fields. + parts = parts[:-length_difference] + elif length_difference < 0: + # Output is from an earlier version of gpg. + # We will set as many fields as possible. Rest empty. + parts.extend(-length_difference * ['']) + + # Number of fields in parts is equal to status class now. + # print status._make(parts) self.data.append(status._make(parts)) return None return msg - -- 2.4.10