Python bindings: examples
authorBen McGinnes <ben@adversary.org>
Sat, 15 Sep 2018 17:34:36 +0000 (03:34 +1000)
committerBen McGinnes <ben@adversary.org>
Sat, 15 Sep 2018 17:34:36 +0000 (03:34 +1000)
* lang/python/examples/howto/export-secret-keys.py and groups.py:
  Updated the backwards compatibility adjustments to account for
  unicode differences between python 2 and 3.

lang/python/examples/howto/export-secret-keys.py
lang/python/examples/howto/groups.py

index 7203ded..0f4d8ee 100755 (executable)
@@ -90,7 +90,10 @@ else:
             process = subprocess.Popen(gpgconfcmd.split(),
                                        stdout=subprocess.PIPE)
             procom = process.communicate()
-            hd = procom[0].decode().strip()
+            if sys.version_info[0] == 2:
+                hd = procom[0].strip()
+            else:
+                hd = procom[0].decode().strip()
     gpgfile = "{0}/{1}.gpg".format(hd, keyfile)
     ascfile = "{0}/{1}.asc".format(hd, keyfile)
 
index 154961b..7213538 100644 (file)
@@ -42,7 +42,10 @@ try:
 except:
     process = subprocess.Popen(gpgconfcmd.split(), stdout=subprocess.PIPE)
     procom = process.communicate()
-    lines = procom[0].decode().splitlines()
+    if sys.version_info[0] == 2:
+        lines = procom[0].splitlines()
+    else:
+        lines = procom[0].decode().splitlines()
 
 for i in range(len(lines)):
     if lines[i].startswith("group") is True: