* [gentoo-keys] [PATCH 3/3] status.py-Fix-process_colon_listing-function-for-all
@ 2016-05-27 14:01 Ashish Gupta
0 siblings, 0 replies; only message in thread
From: Ashish Gupta @ 2016-05-27 14:01 UTC (permalink / raw
To: gentoo-keys
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 0003-status.py-Fix-process_colon_listing-function-for-all.patch --]
[-- Type: text/x-patch, Size: 1912 bytes --]
From a487b8d9a311928d88fd20489866a5515adff138 Mon Sep 17 00:00:00 2001
From: Ashish Gupta <ashmew2@gmail.com>
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-05-27 14:01 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-27 14:01 [gentoo-keys] [PATCH 3/3] status.py-Fix-process_colon_listing-function-for-all Ashish Gupta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox