public inbox for gentoo-keys@lists.gentoo.org
 help / color / mirror / Atom feed
From: Ashish Gupta <ashmew2@gmail.com>
To: gentoo-keys@lists.gentoo.org
Subject: [gentoo-keys] [PATCH 3/3] status.py-Fix-process_colon_listing-function-for-all
Date: Fri, 27 May 2016 14:01:02 +0000	[thread overview]
Message-ID: <CABH6M7+xrQ65E=GSJ5EZcTNJBbC4SDT1_SKiVvduamXz_vJOyg@mail.gmail.com> (raw)

[-- 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


                 reply	other threads:[~2016-05-27 14:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABH6M7+xrQ65E=GSJ5EZcTNJBbC4SDT1_SKiVvduamXz_vJOyg@mail.gmail.com' \
    --to=ashmew2@gmail.com \
    --cc=gentoo-keys@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox