[PATCH] python: Add a __repr__ function for a gpgme_user_id.

Tobias Mueller muelli at cryptobitch.de
Tue Nov 29 13:51:42 CET 2016


* lang/python/gpgme.i: Added _gpgme_user_id::__repr__
--

This makes it look a bit nicer in the Python REPL.

Signed-off-by: Tobias Mueller <muelli at cryptobitch.de>
---
 lang/python/gpgme.i | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index 0e2feec..5d61725 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -684,3 +684,13 @@ _gpg_unwrap_gpgme_ctx_t(PyObject *wrapped)
 /* ... but only the public definitions here.  They will be exposed to
    the Python world, so let's be careful.  */
 %include "helpers.h"
+
+%feature("python:slot", "tp_repr", functype="reprfunc") _gpgme_user_id::__repr__;
+
+%extend _gpgme_user_id {
+    PyObject* __repr__ () {
+        return PyUnicode_FromFormat("UID(\"%s\" revoked=%d invalid=%d validity=%d)",
+                    $self->uid,
+                    $self->revoked, $self->invalid, $self->validity);
+    }
+};
-- 
2.7.4



More information about the Gnupg-devel mailing list