[git] GPGME - branch, master, updated. gpgme-1.6.0-164-g8426304

by Justus Winter cvs at cvs.gnupg.org
Wed Jun 8 17:26:13 CEST 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".

The branch, master has been updated
       via  8426304b67a0b0a5630db500abf740b0e0b9e43c (commit)
       via  990492ea4f7dafbb75de15ea91c30cbf090034b5 (commit)
       via  e3c5913a33edcbd7329b8d154c669f95ce782038 (commit)
      from  f8f9bf06bc3190968ba6613032d60a3bf2c8a6d9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8426304b67a0b0a5630db500abf740b0e0b9e43c
Author: Justus Winter <justus at g10code.com>
Date:   Wed Jun 8 16:51:35 2016 +0200

    python: Fix stripping deprecated functionality.
    
    * lang/python/Makefile.am (gpgme.h): Add script as input.
    * lang/python/gpgme-h-clean.py (deprec_func): Also match struct
    members.
    (line_break): Fix matching on struct members.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/lang/python/Makefile.am b/lang/python/Makefile.am
index 18f77bb..a9b39e7 100644
--- a/lang/python/Makefile.am
+++ b/lang/python/Makefile.am
@@ -20,7 +20,7 @@ EXTRA_DIST = README.rst
 SUBDIRS = tests
 
 # Cleanup gpgme.h from deprecated functions and typedefs.
-gpgme.h: ../../src/gpgme.h
+gpgme.h: ../../src/gpgme.h $(srcdir)/gpgme-h-clean.py
 	$(PYTHON) $(srcdir)/gpgme-h-clean.py $< >$@
 
 # For VPATH builds we need to copy some files because Python's
diff --git a/lang/python/gpgme-h-clean.py b/lang/python/gpgme-h-clean.py
index 261e7b6..b7052ff 100755
--- a/lang/python/gpgme-h-clean.py
+++ b/lang/python/gpgme-h-clean.py
@@ -1,4 +1,6 @@
 #!/usr/bin/env python3
+
+# Copyright (C) 2016 g10 Code GmbH
 # Copyright (C) 2004,2008 Igor Belyi <belyi at users.sourceforge.net>
 #
 #    This library is free software; you can redistribute it and/or
@@ -21,8 +23,11 @@ if len(sys.argv) < 2:
     sys.stderr.write("Usage: %s gpgme.h\n" % sys.argv[0])
     sys.exit(1)
 
-deprec_func=re.compile('^(.*typedef.*|.*\(.*\))\s*_GPGME_DEPRECATED;\s*',re.S)
-line_break=re.compile(';|\\$|\\x0c|^\s*#');
+deprec_func = re.compile(r'^(.*typedef.*|.*\(.*\)|[^#]+\s+.+)'
+                         + r'\s*_GPGME_DEPRECATED(_OUTSIDE_GPGME)?;\s*',
+                         re.S)
+line_break = re.compile(';|\\$|\\x0c|^\s*#|{');
+
 try:
     gpgme = open(sys.argv[1])
     tmp = gpgme.readline()

commit 990492ea4f7dafbb75de15ea91c30cbf090034b5
Author: Justus Winter <justus at g10code.com>
Date:   Wed Jun 8 17:04:02 2016 +0200

    python: Fix type.
    
    * lang/python/gpgme.i: Use correct Python type for size.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i
index f466a87..98f30d5 100644
--- a/lang/python/gpgme.i
+++ b/lang/python/gpgme.i
@@ -183,18 +183,28 @@
 
 /* For gpgme_data_write, but should be universal.  */
 %typemap(in) (const void *buffer, size_t size) {
+  Py_ssize_t ssize;
+
   if ($input == Py_None)
     $1 = NULL, $2 = 0;
   else if (PyUnicode_Check($input))
-    $1 = PyUnicode_AsUTF8AndSize($input, (size_t *) &$2);
+    $1 = PyUnicode_AsUTF8AndSize($input, &ssize);
   else if (PyBytes_Check($input))
-    PyBytes_AsStringAndSize($input, (char **) &$1, (size_t *) &$2);
+    PyBytes_AsStringAndSize($input, (char **) &$1, &ssize);
   else {
     PyErr_Format(PyExc_TypeError,
                  "arg %d: expected str, bytes, or None, got %s",
 		 $argnum, $input->ob_type->tp_name);
     return NULL;
   }
+
+  if (! $1)
+    $2 = 0;
+  else
+    {
+      assert (ssize >= 0);
+      $2 = (size_t) ssize;
+    }
 }
 %typemap(freearg) (const void *buffer, size_t size) "";
 

commit e3c5913a33edcbd7329b8d154c669f95ce782038
Author: Justus Winter <justus at g10code.com>
Date:   Tue Jun 7 19:31:10 2016 +0200

    python: Implement the context manager protocol.
    
    * lang/python/pyme/core.py (Context.__del__): Make function
    idemptotent.
    (Context.{__enter__,__exit__}): Implement the context manager
    protocol.
    (Data.__del__): Make function idemptotent, drop debug print.
    (Data.{__enter__,__exit__}): Implement the context manager
    protocol.
    * lang/python/tests/t-idiomatic.py: Demonstrate this.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/lang/python/pyme/core.py b/lang/python/pyme/core.py
index 71c6828..4b3e08a 100644
--- a/lang/python/pyme/core.py
+++ b/lang/python/pyme/core.py
@@ -147,8 +147,15 @@ class Context(GpgmeWrapper):
         self._free_passcb()
         self._free_progresscb()
         self._free_statuscb()
-        if self.own and pygpgme.gpgme_release:
+        if self.own and self.wrapped and pygpgme.gpgme_release:
             pygpgme.gpgme_release(self.wrapped)
+            self.wrapped = None
+
+    # Implement the context manager protocol.
+    def __enter__(self):
+        return self
+    def __exit__(self, type, value, tb):
+        self.__del__()
 
     def _free_passcb(self):
         if self.last_passcb != None:
@@ -420,10 +427,16 @@ class Data(GpgmeWrapper):
         if self.wrapped != None and pygpgme.gpgme_data_release:
             pygpgme.gpgme_data_release(self.wrapped)
             if self._callback_excinfo:
-                print(self._callback_excinfo)
                 pygpgme.pygpgme_raise_callback_exception(self)
+            self.wrapped = None
         self._free_datacbs()
 
+    # Implement the context manager protocol.
+    def __enter__(self):
+        return self
+    def __exit__(self, type, value, tb):
+        self.__del__()
+
     def _free_datacbs(self):
         if self.data_cbs != None:
             if pygpgme.pygpgme_clear_generic_cb:
diff --git a/lang/python/tests/t-idiomatic.py b/lang/python/tests/t-idiomatic.py
index 05a377e..37cfb64 100755
--- a/lang/python/tests/t-idiomatic.py
+++ b/lang/python/tests/t-idiomatic.py
@@ -23,7 +23,15 @@ from pyme import core, constants, errors
 import support
 
 support.init_gpgme(constants.PROTOCOL_OpenPGP)
-c = core.Context()
+
+# Both Context and Data can be used as context manager:
+with core.Context() as c, core.Data() as d:
+    c.get_engine_info()
+    d.write(b"Halloechen")
+    leak_c = c
+    leak_d = d
+assert leak_c.wrapped == None
+assert leak_d.wrapped == None
 
 # Demonstrate automatic wrapping of file-like objects with 'fileno'
 # method.
@@ -33,10 +41,11 @@ with tempfile.TemporaryFile() as source, \
     source.write(b"Hallo Leute\n")
     source.seek(0, os.SEEK_SET)
 
-    c.op_sign(source, signed, constants.SIG_MODE_NORMAL)
-    signed.seek(0, os.SEEK_SET)
-    c.op_verify(signed, None, sink)
-    result = c.op_verify_result()
+    with core.Context() as c:
+        c.op_sign(source, signed, constants.SIG_MODE_NORMAL)
+        signed.seek(0, os.SEEK_SET)
+        c.op_verify(signed, None, sink)
+        result = c.op_verify_result()
 
     assert len(result.signatures) == 1, "Unexpected number of signatures"
     sig = result.signatures[0]

-----------------------------------------------------------------------

Summary of changes:
 lang/python/Makefile.am          |  2 +-
 lang/python/gpgme-h-clean.py     |  9 +++++++--
 lang/python/gpgme.i              | 14 ++++++++++++--
 lang/python/pyme/core.py         | 17 +++++++++++++++--
 lang/python/tests/t-idiomatic.py | 19 ++++++++++++++-----
 5 files changed, 49 insertions(+), 12 deletions(-)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list