aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/pyme/core.py
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2016-09-16 12:56:29 +0000
committerJustus Winter <[email protected]>2016-09-16 12:56:29 +0000
commita458e7fe2006d92bd5a838e2747fb66bbac4b1b8 (patch)
tree7460cc8f3ba21fec51a0a706f17747887ef37d96 /lang/python/pyme/core.py
parentcore: Fix typos. (diff)
downloadgpgme-a458e7fe2006d92bd5a838e2747fb66bbac4b1b8.tar.gz
gpgme-a458e7fe2006d92bd5a838e2747fb66bbac4b1b8.zip
python: Adapt to 'gpgme_op_interact'.
* lang/python/examples/inter-edit.py: Update example. * lang/python/gpgme.i (gpgme_edit_cb_t): Turn into 'gpgme_interact_cb_t'. * lang/python/helpers.c (_pyme_edit_cb): Turn into '_pyme_interact_cb_t'. * lang/python/private.h (_pyme_edit_cb): Likewise. * lang/python/pyme/constants/__init__.py: Replace numeric status codes with the keywords. * lang/python/pyme/constants/status.py: Likewise. * lang/python/pyme/core.py (Context.interact): New method. (Context.op_edit): Deprecate, update docstring, implement using Context.interact. * lang/python/tests/t-edit.py: Test both interfaces. Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'lang/python/pyme/core.py')
-rw-r--r--lang/python/pyme/core.py59
1 files changed, 48 insertions, 11 deletions
diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py
index 55e86872..88a086b1 100644
--- a/lang/python/pyme/core.py
+++ b/lang/python/pyme/core.py
@@ -29,6 +29,7 @@ del absolute_import, print_function, unicode_literals
import re
import os
+import warnings
import weakref
from . import gpgme
from .errors import errorcheck, GPGMEError
@@ -536,6 +537,39 @@ class Context(GpgmeWrapper):
return GPGMEError(status) if status != 0 else None
+ def interact(self, key, func, sink=None, flags=0, fnc_value=None):
+ """Interact with the engine
+
+ This method can be used to edit keys and cards interactively.
+ KEY is the key to edit, FUNC is called repeatedly with two
+ unicode arguments, 'keyword' and 'args'. See the GPGME manual
+ for details.
+
+ Keyword arguments:
+ sink -- if given, additional output is written here
+ flags -- use constants.INTERACT_CARD to edit a card
+
+ Raises:
+ GPGMEError -- as signaled by the underlying library
+
+ """
+ if key == None:
+ raise ValueError("First argument cannot be None")
+
+ if sink == None:
+ sink = Data()
+
+ if fnc_value:
+ opaquedata = (weakref.ref(self), func, fnc_value)
+ else:
+ opaquedata = (weakref.ref(self), func)
+
+ result = gpgme.gpgme_op_interact(self.wrapped, key, flags,
+ opaquedata, sink)
+ if self._callback_excinfo:
+ gpgme.pyme_raise_callback_exception(self)
+ errorcheck(result)
+
@property
def signers(self):
"""Keys used for signing"""
@@ -793,18 +827,21 @@ class Context(GpgmeWrapper):
errorcheck(status)
def op_edit(self, key, func, fnc_value, out):
- """Start key editing using supplied callback function"""
- if key == None:
- raise ValueError("op_edit: First argument cannot be None")
- if fnc_value:
- opaquedata = (weakref.ref(self), func, fnc_value)
- else:
- opaquedata = (weakref.ref(self), func)
+ """Start key editing using supplied callback function
+
+ Note: This interface is deprecated and will be removed with
+ GPGME 1.8. Please use .interact instead. Furthermore, we
+ implement this using gpgme_op_interact, so callbacks will get
+ called with string keywords instead of numeric status
+ messages. Code that is using constants.STATUS_X or
+ constants.status.X will continue to work, whereas code using
+ magic numbers will break as a result.
+
+ """
+ warnings.warn("Call to deprecated method op_edit.",
+ category=DeprecationWarning)
+ return self.interact(key, func, sink=out, fnc_value=fnc_value)
- result = gpgme.gpgme_op_edit(self.wrapped, key, opaquedata, out)
- if self._callback_excinfo:
- gpgme.pyme_raise_callback_exception(self)
- errorcheck(result)
class Data(GpgmeWrapper):
"""Data buffer