From f4ba16b31ea282d0787a40be3f37b951584143a1 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 10 May 2016 13:19:26 +0200 Subject: python: Rename bindings. -- Signed-off-by: Justus Winter --- lang/python/examples/t-edit.py | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 lang/python/examples/t-edit.py (limited to 'lang/python/examples/t-edit.py') diff --git a/lang/python/examples/t-edit.py b/lang/python/examples/t-edit.py new file mode 100644 index 00000000..6c533429 --- /dev/null +++ b/lang/python/examples/t-edit.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# $Id$ +# Copyright (C) 2005 Igor Belyi +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import os +from pyme import core +from pyme.core import Data, Context + +core.check_version(None) + +class KeyEditor: + def __init__(self): + self.steps = ["fpr", "expire", "1", "primary", "quit"] + self.step = 0 + + def edit_fnc(self, status, args, out): + print("[-- Response --]") + out.seek(0,0) + print(out.read(), end=' ') + print("[-- Code: %d, %s --]" % (status, args)) + + if args == "keyedit.prompt": + result = self.steps[self.step] + self.step += 1 + elif args == "keyedit.save.okay": + result = "Y" + elif args == "keygen.valid": + result = "0" + else: + result = None + + return result + +if not os.getenv("GNUPGHOME"): + print("Please, set GNUPGHOME env.var. pointing to GPGME's tests/gpg dir") +else: + c = Context() + c.set_passphrase_cb(lambda x,y,z: "abc") + out = Data() + c.op_keylist_start(b"Alpha", 0) + key = c.op_keylist_next() + c.op_edit(key, KeyEditor().edit_fnc, out, out) + print("[-- Last response --]") + out.seek(0,0) + print(out.read(), end=' ') -- cgit v1.2.3 From aade53a12b9716997684b872bc2ac87229f73fb3 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 10 May 2016 13:30:30 +0200 Subject: python: Delete trailing whitespace. -- Signed-off-by: Justus Winter --- lang/python/examples/t-edit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lang/python/examples/t-edit.py') diff --git a/lang/python/examples/t-edit.py b/lang/python/examples/t-edit.py index 6c533429..5553190c 100644 --- a/lang/python/examples/t-edit.py +++ b/lang/python/examples/t-edit.py @@ -32,7 +32,7 @@ class KeyEditor: out.seek(0,0) print(out.read(), end=' ') print("[-- Code: %d, %s --]" % (status, args)) - + if args == "keyedit.prompt": result = self.steps[self.step] self.step += 1 -- cgit v1.2.3 From c89d3a71ad20ff02755539a44f254b1e59054c4a Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 12 May 2016 11:51:21 +0200 Subject: python: Make test case more robust. * lang/python/examples/t-edit.py: Check if key is found. Signed-off-by: Justus Winter --- lang/python/examples/t-edit.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lang/python/examples/t-edit.py') diff --git a/lang/python/examples/t-edit.py b/lang/python/examples/t-edit.py index 5553190c..5e5857a2 100644 --- a/lang/python/examples/t-edit.py +++ b/lang/python/examples/t-edit.py @@ -16,6 +16,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +import sys import os from pyme import core from pyme.core import Data, Context @@ -53,6 +54,9 @@ else: out = Data() c.op_keylist_start(b"Alpha", 0) key = c.op_keylist_next() + if not key: + sys.exit("Key Alpha not found. " + + "Did you point GNUPGHOME to GPGME's tests/gpg dir?") c.op_edit(key, KeyEditor().edit_fnc, out, out) print("[-- Last response --]") out.seek(0,0) -- cgit v1.2.3 From 10328324c8fc9725cd0c885eaebfc80dc32c1ff6 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 17 May 2016 14:15:21 +0200 Subject: python: Clean up examples. * lang/python/examples/delkey.py: Clean up example. * lang/python/examples/encrypt-to-all.py: Likewise. * lang/python/examples/genkey.py: Likewise. * lang/python/examples/inter-edit.py: Likewise. * lang/python/examples/sign.py: Likewise. * lang/python/examples/signverify.py: Likewise. * lang/python/examples/simple.py: Likewise. * lang/python/examples/t-edit.py: Likewise. * lang/python/examples/verifydetails.py: Likewise. * lang/python/pyme/__init__.py: Likewise. Signed-off-by: Justus Winter --- lang/python/examples/t-edit.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lang/python/examples/t-edit.py') diff --git a/lang/python/examples/t-edit.py b/lang/python/examples/t-edit.py index 5e5857a2..5c35f966 100644 --- a/lang/python/examples/t-edit.py +++ b/lang/python/examples/t-edit.py @@ -30,8 +30,8 @@ class KeyEditor: def edit_fnc(self, status, args, out): print("[-- Response --]") - out.seek(0,0) - print(out.read(), end=' ') + out.seek(0, os.SEEK_SET) + sys.stdout.buffer.write(out.read()) print("[-- Code: %d, %s --]" % (status, args)) if args == "keyedit.prompt": @@ -59,5 +59,5 @@ else: "Did you point GNUPGHOME to GPGME's tests/gpg dir?") c.op_edit(key, KeyEditor().edit_fnc, out, out) print("[-- Last response --]") - out.seek(0,0) - print(out.read(), end=' ') + out.seek(0, os.SEEK_SET) + sys.stdout.buffer.write(out.read()) -- cgit v1.2.3