aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/examples/howto/groups.py
diff options
context:
space:
mode:
authorBen McGinnes <[email protected]>2018-09-15 02:10:05 +0000
committerBen McGinnes <[email protected]>2018-09-15 02:10:05 +0000
commit864ef9b40f5f9d0c66a458b6033277938d7d1d50 (patch)
treec012ddff266f729946baea90c2338ec3d9c9716e /lang/python/examples/howto/groups.py
parentjs: Fix errorDetails of GPGME_Signature (diff)
downloadgpgme-864ef9b40f5f9d0c66a458b6033277938d7d1d50.tar.gz
gpgme-864ef9b40f5f9d0c66a458b6033277938d7d1d50.zip
Python examples: backwards compatibility
* lang/python/examples/howto/groups.py: subprocess update * lang/python/examples/howto/export-secret-keys.py: subprocess update Both of these try the nice and easy method of getting the subprocess output available in Python 3, but will fall back to the older Popen method if it doesn't work. Essentially this is to be a little nicer to Python 2.7.15 (even though the examples are filled with warnings that py2 support is not guaranteed with the examples).
Diffstat (limited to 'lang/python/examples/howto/groups.py')
-rw-r--r--lang/python/examples/howto/groups.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/lang/python/examples/howto/groups.py b/lang/python/examples/howto/groups.py
index b8317b69..154961b1 100644
--- a/lang/python/examples/howto/groups.py
+++ b/lang/python/examples/howto/groups.py
@@ -37,7 +37,12 @@ if sys.platform == "win32":
else:
gpgconfcmd = "gpgconf --list-options gpg"
-lines = subprocess.getoutput(gpgconfcmd).splitlines()
+try:
+ lines = subprocess.getoutput(gpgconfcmd).splitlines()
+except:
+ process = subprocess.Popen(gpgconfcmd.split(), stdout=subprocess.PIPE)
+ procom = process.communicate()
+ lines = procom[0].decode().splitlines()
for i in range(len(lines)):
if lines[i].startswith("group") is True: