Commit Graph

314 Commits

Author SHA1 Message Date
Werner Koch
29207bcd3b
tests: Improve portability.
* lang/qt/tests/Makefile.am (clean-local): Avoid non-portable "--"
* lang/python/Makefile.am (copystamp): Use well defined cp -R instead
of cp -r.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-09-20 19:46:04 +02:00
Justus Winter
65f6f68f09 python: Improve metadata and READMEs.
--
Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-19 12:49:14 +02:00
Werner Koch
b615316168
core: Document the version a function has been deprecated.
* src/gpgme.h.in (_GPGME_DEPRECATED): Change to take versio numbers
for documentation.  Change all places.
(_GPGME_DEPRECATED_OUTSIDE_GPGME): Ditto.
* lang/python/gpgme-h-clean.py: Adjust RE.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-09-16 16:00:27 +02:00
Justus Winter
6af7bee076 python: Release the GIL during calls into GPGME.
* lang/python/helpers.c (pyme_raise_callback_exception): Re-acquire
the Global Interpreter Lock.
(pyPassphraseCb, pyme_set_passphrase_cb, pyProgressCb,
pyme_set_progress_cb, pyStatusCb, pyme_set_status_cb,
_pyme_interact_cb, pyDataReadCb, pyDataWriteCb, pyDataSeekCb,
pyDataReleaseCb, pyme_data_new_from_cbs, _pyme_assuan_data_cb,
_pyme_assuan_inquire_cb, _pyme_assuan_status_cb): Likewise.
* lang/python/setup.py.in: Make 'gpgme-config' emit the correct
cflags, and SWIG generate code to release the GIL before calling us.

Co-authored-by: Kai Michaelis <kai@gnupg.org>
Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-16 15:56:47 +02:00
Justus Winter
a458e7fe20 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 <justus@g10code.com>
2016-09-16 14:56:29 +02:00
Justus Winter
594c3b8b05 python: Clarify that we support Python 2.7 too.
* lang/python/README: Use 'Python' instead of 'Python 3'.
* lang/python/pyme/version.py.in: Likewise.
* lang/python/setup.py.in: Add classifier for 2.7, drop 3 only.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-14 14:36:29 +02:00
Justus Winter
4011b2b2a1 python: Trim imports.
* lang/python/examples/encrypt-to-all.py: Drop unused import of 'os'.
* lang/python/examples/signverify.py: Likewise.
* lang/python/examples/simple.py: Likewise.
* lang/python/examples/verifydetails.py: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-14 14:35:00 +02:00
Justus Winter
44d18200d5 python: Improve error handling.
* lang/python/gpgme.i (gpgme_engine_info_t): Improve error handling.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-14 14:34:14 +02:00
Justus Winter
f6cd560ca7 python: Adapt to TOFU changes.
* lang/python/pyme/results.py (TofuInfo): Drop.
(Signature): The TOFU information moved to the key.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-14 14:32:48 +02:00
Justus Winter
24b4162d90 python: Build for both Python2 and Python3.
* NEWS: Update.
* configure.ac: Check for multiple Python versions.
* lang/python/Makefile.am: Build and install for both Python versions.
* lang/python/tests/Makefile.am: Test both versions.
* lang/python/tests/run-tests.py: New test runner.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-14 12:18:15 +02:00
Justus Winter
dc23fdf555 python: Import from __future__ to align behavior of Python 2.7.
--
Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-14 12:15:57 +02:00
Justus Winter
3b37c4efcf python: Use more generic shebang.
--
Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-14 12:15:57 +02:00
Justus Winter
70a3be27a5 python: Handle slight differences between Python 2 and 3.
* lang/python/helpers.c (pyDataWriteCb): Handle Python integers being
returned on Python 2.
(pyDataSeekCb): Likewise.
* lang/python/pyme/core.py (Data.__init__): Fix testing for string
argument.
(Data.new_from_filepart): Likewise.
* lang/python/pyme/util.py (is_a_string): New function.
* lang/python/tests/t-encrypt-large.py (read_cb): Force evaluation of
generator.
* lang/python/tests/t-idiomatic.py: Partly skip test on Python 2.
* lang/python/tests/t-verify.py (check_result): Here, the difference
between 2 and 3 really matters.  We cannot change the char *
conversion in Python 2 without breaking all existing applications, and
using bytestrings in Python 3 would be very inconvenient.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-13 13:29:43 +02:00
Justus Winter
4abff7d750 python: Fix types and error handling.
* lang/python/helpers.c (_pyme_edit_cb): Drop the const.
(_pyme_assuan_{data,inquire,status}_cb): Fix error handling.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-13 13:29:43 +02:00
Justus Winter
c0c50318bd python: Avoid Python3-only form of super().
* lang/python/pyme/core.py (GpgmeWrapper.__repr__): Use more
compatible form of super.
(GpgmeWrapper.__setattr__): Likewise.
(Context.__init__): Likewise.
(Data.__init__): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-12 17:24:18 +02:00
Justus Winter
1d5bbbf118 python: Make type translation compatible with Python 2.7.
* lang/python/gpgme.i: Avoid functions not available in Python 2.7.
* lang/python/helpers.c: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-12 17:11:19 +02:00
Justus Winter
70999d8161 python: Avoid hardcoding the interpreter.
* lang/python/setup.py.in: Avoid hardcoding the interpreter.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-12 16:19:07 +02:00
Justus Winter
b48b852a84 python: Do not rely on subprocess.DEVNULL.
* lang/python/setup.py.in: Do not rely on subprocess.DEVNULL.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-12 16:18:31 +02:00
Justus Winter
a0263ad282 tests: Make signature notation test compatible with older GnuPGs.
* lang/python/tests/t-sig-notation.py: Only check the critical flag
when GnuPG >= 2.1.13 is used.
* tests/gpg/t-sig-notation.c: Likewise.

Fixes-commit: c88c9ef3
Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-12 14:56:07 +02:00
Andre Heinecke
ab6f66d676 Prepend LD_LIBRARY_PATH for python tests
* lang/python/tests/Makefile.am (TESTS_ENVIRONMENT): Prepend path
instead of setting the value.

--
This fixes the case where tools / libararies are needed for
a working GnuPG system that are pointed to by LD_LIBRARY_PATH.
E.g. GnuPG itself is installed in a custom prefix and PATH /
LD_LIBRARY_PATH is set accordingly.
2016-08-08 15:04:01 +02:00
Justus Winter
2a613e8715 python: Clean up and modernize examples.
* lang/python/examples/Examples.rst: Delete file.
* lang/python/examples/t-edit.py: Likewise.  This is actually a test
case and has been moved to 'tests'.
* lang/python/examples/assuan.py: New file.
* lang/python/examples/decryption-filter.py: Likewise.
* lang/python/examples/delkey.py: Modernize.
* lang/python/examples/encrypt-to-all.py: Likewise.
* lang/python/examples/exportimport.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/testCMSgetkey.py: Likewise.
* lang/python/examples/verifydetails.py: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-08-05 14:05:49 +02:00
Justus Winter
56e26b54da python: Add a nicer interface to list keys.
* lang/python/pyme/core.py (Context.keylist): New method.
* lang/python/tests/t-keylist.py: Test new method.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-08-03 16:32:30 +02:00
Justus Winter
4c8265d32d python: Add a flag identifying in-tree builds.
* lang/python/helpers.c (pyme_in_tree_build): New variable.
* lang/python/helpers.h (pyme_in_tree_build): New declaration.
* lang/python/pyme/version.py.in (in_tree_build): New variable.
* lang/python/setup.py.in: Rework macro handling, set 'IN_TREE_BUILD'
as appropriate.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-08-02 18:45:10 +02:00
Justus Winter
0bd7d8c197 python: Fix build system integration.
* lang/python/Makefile.am: Be more careful when cleaning the build
directory, we must not delete the generated file 'pyme/version.py'.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-08-02 18:42:26 +02:00
Justus Winter
4e728de842 python: Fix out-of-tree build.
* lang/python/MANIFEST.in: Add 'private.h'.

Fixes-commit: 3d4dc3f0
Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-28 18:14:08 +02:00
Justus Winter
5a7c7a86f7 python: Improve error handling.
* lang/python/pyme/core.py (Context.protocol): Check that the engine
is usable before setting the protocol.
(Context._errorcheck): Add missing functions.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-28 17:50:07 +02:00
Justus Winter
2ff58fcbd5 python: Drop superfluous imports and trim public interface.
* lang/python/pyme/__init__.py: Avoid leaking low-level 'gpgme', make
sure the main module looks nice and tidy, appease pyflakes.
* lang/python/pyme/errors.py: Appease pyflakes.
* lang/python/pyme/util.py: Avoid leaking low-level 'gpgme' into the
module namespace.
* lang/python/pyme/version.py.in: Likewise.
* lang/python/tests/t-keylist.py: Drop superfluous imports.
* lang/python/tests/t-sig-notation.py: Likewise.
* lang/python/tests/t-sign.py: Likewise.
* lang/python/tests/t-signers.py: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-28 16:50:02 +02:00
Justus Winter
2f754440f2 python: Rename compiled SWIG module.
Avoid the name pygpgme, as this is the name of another popular Python
binding for GPGME.

This commit renames the compiled Python module produced by SWIG.

* lang/python/Makefile.am: Rename the compiled Python module.
* lang/python/gpgme.i: Likewise.
* lang/python/pyme/core.py: Likewise.
* lang/python/pyme/errors.py: Likewise.
* lang/python/pyme/util.py: Likewise.
* lang/python/pyme/version.py.in: Likewise.
* lang/python/setup.py.in: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-28 16:49:50 +02:00
Justus Winter
b5aa05c3b2 python: Rename exported functions.
Avoid the name pygpgme, as this is the name of another popular Python
binding for GPGME.

This commit renames all functions that are exported to the Python
world.

* lang/python/helpers.c: Rename all exported functions.
* lang/python/helpers.h: Likewise.
* lang/python/pyme/core.py: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-28 15:26:43 +02:00
Justus Winter
1d2f22aae6 python: Rename private functions.
Avoid the name pygpgme, as this is the name of another popular Python
binding for GPGME.

This commit renames all functions that are not exported to the Python
world.

* lang/python/gpgme.i: Rename all private functions.
* lang/python/helpers.c: Likewise.
* lang/python/helpers.h: Likewise.
* lang/python/private.h: Likewise.  Also move the SWIG runtime helper
prototypes here.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-28 15:26:43 +02:00
Justus Winter
de69fa496c python: Support the Assuan engine.
* lang/python/gpgme.i: Add typemaps for the Assuan protocol callbacks.
* lang/python/helpers.c (_pyme_assuan_{data,inquire,status}_cb): New
functions.
* lang/python/private.h (_pyme_assuan_{data,inquire,status}_cb): New
prototypes.
* lang/python/pyme/core.py (Context.assuan_transact): New method.
* lang/python/pyme/util.py (percent_escape): New function.
* lang/python/tests/Makefile.am (py_tests): Add new test.
* lang/python/tests/t-protocol-assuan.py: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-28 14:23:07 +02:00
Justus Winter
355d707286 python: Improve engine information handling.
* lang/python/gpgme.i (gpgme_engine_info_t): Wrap engine infos.
* lang/python/pyme/core.py (Context.engine_info): New property.
(Context.{g,s}et_engine_info): Improve docstrings.
* lang/python/pyme/results.py (EngineInfo): New class.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-28 11:16:35 +02:00
Justus Winter
78f7bf4dcf python: Add accessors for the protocol.
* lang/python/pyme/core.py (Context.__init__): Add 'protocol'
parameter.
(Context.protocol): New accessors.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-28 10:59:46 +02:00
Justus Winter
3d4dc3f021 python: Expose less functions to the Python world.
* lang/python/Makefile.am (EXTRA_DIST, COPY_FILES): Add new file.
* lang/python/gpgme.i: Include new file and add comments.
* lang/python/helpers.c: Include new file.
* lang/python/helpers.h: Move functions we do not need to expose...
* lang/python/private.h: ... here.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-28 10:23:32 +02:00
Justus Winter
e545ca3f68 python: Make GPGME's version easily accessible.
* lang/python/pyme/version.py.in (gpgme_versionstr): New variable.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-15 18:28:19 +02:00
Justus Winter
1f318b7aaa python: Add an idiomatic interface.
* configure.ac: Bump required Python version.
* lang/python/pyme/__init__.py: Update docstring.  Import Context and
Data.
* lang/python/pyme/core.py (Context.encrypt): New function.
(Context.decrypt): Likewise.
(Context.sign): Likewise.
(Context.verify): Likewise.
* lang/python/pyme/errors.py: Add new errors.
* lang/python/pyme/util.py (process_constants): Rework and return the
inserted keys.
* lang/python/tests/Makefile.am (EXTRA_DIST): Add new keys.
* lang/python/tests/encrypt-only.asc: New file.
* lang/python/tests/sign-only.asc: Likewise.
* lang/python/tests/initial.py: Mark key 'Alpha' as trusted, import
new keys.
* lang/python/tests/support.py: Add fingerprints of known keys.
(in_srcdir): New function.
(print_data): Handle bytes too.
(mark_key_trusted): New function.
* lang/python/tests/t-decrypt-verify.py: Adjust test.  Test idiomatic
interface.
* lang/python/tests/t-decrypt.py: Test idiomatic interface.
* lang/python/tests/t-encrypt-sign.py: Likewise.
* lang/python/tests/t-encrypt-sym.py: Likewise.
* lang/python/tests/t-encrypt.py: Likewise.
* lang/python/tests/t-idiomatic.py: Simplify.
* lang/python/tests/t-keylist.py: Adjust to newly trusted key.
* lang/python/tests/t-sign.py: Likewise.  Test idiomatic interface.
* lang/python/tests/t-signers.py: Likewise.
* lang/python/tests/t-verify.py: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-15 18:28:09 +02:00
Justus Winter
fddcc62abd python: Fix test.
* lang/python/tests/t-keylist.py: Do not assume key alpha is trusted
yet.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-14 13:34:49 +02:00
Justus Winter
b68700d227 python: Drop bad category.
--
Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-14 13:34:49 +02:00
Justus Winter
1bff47ee58 python: Port more tests.
* lang/python/pyme/core.py (Context.op_keylist_all): Add missing
'op_keylist_end'.
(Context.op_trustlist_all): Fix function. Add missing
'op_trustlist_end'.
* lang/python/tests/Makefile.am (pytests): Add new files.
* lang/python/tests/t-import.py: New file.
* lang/python/tests/t-keylist.py: Likewise.
* lang/python/tests/t-trustlist.py: Check alternate interface.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-12 18:34:12 +02:00
Justus Winter
57b5168552 python: Improve python packaging.
* lang/python/Makefile.am: Sign source releases, and upload them.
* lang/python/setup.py.in: Add categories.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-12 18:34:12 +02:00
Justus Winter
ce66289137 python: Fix distcheck.
* lang/python/Makefile.am (EXTRA_DIST): Add missing files.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-11 19:42:56 +02:00
Justus Winter
007382ce94 python: Enable out-of-tree build of pyme bindings.
* lang/python/MANIFEST.in: Update manifest template.
* lang/python/Makefile.am: Copy more files, move generation of files
to Python build script, add 'sdist' target to build a Python source
distribution.
* lang/python/gpgme-h-clean.py: Add code to build 'errors.i'.
* lang/python/setup.py.in: Generate files, enable out-of-tree builds.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-11 18:09:54 +02:00
Justus Winter
98cba522c9 python: Do not depend on access to internal data structures.
* lang/python/gpgme.i (gpgme_data_t): Rework so that it works without
access to the definition of 'struct gpgme_data'.
* lang/python/helpers.c (object_to_gpgme_data_t): Add assertion.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-11 17:50:58 +02:00
Justus Winter
c53f87c5f9 python: Make result wrapping backwards compatible.
* lang/python/pyme/results.py (Result.__init__): Skip missing fields.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-11 17:50:58 +02:00
Justus Winter
8a93f345b7 python: Fix raising stashed exceptions.
Fixes an issue with newer versions of Python.

* lang/python/helpers.c (pygpgme_raise_callback_exception): Be more
careful when restoring the exception.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-08 11:45:08 +02:00
Justus Winter
52efcf1ee9 python: Fix distcheck.
* lang/python/INSTALL: Drop obsolete file.
* lang/python/Makefile.am (EXTRA_DIST): Add missing files.
(CLEANFILES): Remove generated files.
(clean-local): Fix permissions of copied files.
* lang/python/tests/Makefile.am (TESTS): Use our own setup and
teardown scripts.
(EXTRA_DIST): Add missing files.
* lang/python/tests/final.py: New file.
* lang/python/tests/initial.py: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-07-07 14:10:36 +02:00
Justus Winter
8997d88bf9 python: Improve autmatically generated docstrings.
* lang/python/gpgme.i: Add comment.
* lang/python/pyme/core.py (__getattr__): Rewrite automatically
generated doctrings for the wrapper methods.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-16 14:19:17 +02:00
Justus Winter
a324d0cffe python: Make result objects more robust.
Results returned by the GPGME are fragile, i.e. they are only valid
until the next operation is performed in the context.

We cannot arbitrarily constrain the lifetime of Python objects, we
therefore create deep copies of the results.

* lang/python/gpgme.i (gpgme_tofu_info_t): Turn these into a list.
(gpgme_*_result_t): Create deep copies of these objects.
* lang/python/helpers.c (pygpgme_wrap_fragile_result): New function.
* lang/python/helpers.h (pygpgme_wrap_fragile_result): New prototype.
* lang/python/pyme/results.py: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-16 14:19:17 +02:00
Justus Winter
856bcfe293 python: Avoid creating SWIG proxy classes.
* lang/python/Makefile.am (gpgme_wrap.c): Use '-builtin' to make SWIG
generate builtin types for c types.
* lang/python/gpgme.i (pygpgme_wrap_gpgme_data_t): Adapt slightly.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-16 14:19:17 +02:00
Justus Winter
6641c7814b python: Simplify wrapping glue.
* lang/python/pyme/core.py: Rename '_getctype' to '_ctype' and turn it
  into a string.  Likewise rename '_getnameprepend' to '_cprefix'.
* lang/python/helpers.c: Adapt accordingly.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-16 14:19:17 +02:00
Justus Winter
f3618bc615 python: Rework callbacks.
Simplify how the lifetime of callback arguments is managed.

* lang/python/gpgme.i (gpgme_edit_cb_t): Check arguments.
(PyObject_p_p, void_p_p): Drop rather dangerous interface.
(pygpgme_unwrap_gpgme_ctx_t): New function.
* lang/python/helpers.c (pygpgme_clear_generic_cb): Drop dangerous
function.
(pyPassphraseCb): Assert contract.
(pygpgme_set_passphrase_cb): Use Python's calling convention so that
we can raise exceptions.  Hand in 'self', get the wrapped object, and
simply store the hook data as attribute of the wrapper object.
(pyProgressCb, pygpgme_set_progress_cb): Likewise.
(pygpgme_set_status_cb): Likewise.
(pygpgme_data_new_from_cbs): Likewise.
* lang/python/helpers.h (pygpgme_clear_generic_cb): Drop prototype.
(pygpgme_set_passphrase_cb): Update prototype.
(pygpgme_set_progress_cb): Likewise.
(pygpgme_set_status_cb): Likewise.
(pygpgme_data_new_from_cbs): Likewise.
(pygpgme_unwrap_gpgme_ctx_t): New prottotype.
* lang/python/pyme/core.py (Context, Data): Update callsites.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-16 14:19:17 +02:00
Justus Winter
616929b6ed python: Wrap objects implementing the buffer protocol.
* lang/python/Makefile.am: Add the toplevel source directory to CFLAGS
when compiling the bindings so that we can use private header files.
* lang/python/gpgme.i (gpgme_data_t): Rework the object wrapping.  Do
not create a Python wrapper object, merely a gpgme_data_t object, and
keep references to buffer objects, if any.  If necessary, update the
buffer after the function call.
(pygpgme_wrap_gpgme_data_t): New function.
* lang/python/helpers.c (object_to_gpgme_data_t): Rework object
wrapping.  Also wrap objects implementing the buffer protocol.
* lang/python/helpers.h (object_to_gpgme_data_t): Update prototype.
(pygpgme_wrap_gpgme_data_t): New prototype.
* lang/python/tests/t-idiomatic.py: Demonstrate this.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-16 14:19:17 +02:00
Justus Winter
5464060bae python: Add properties to wrapped object.
* lang/python/pyme/core.py (GpgmeWrapper.__repr__): Saner
representation.
(GpgmeWrapper.__str__): Construct a nicer human readable string.
(GpgmeWrapper._boolean_properties): New field.
(GpgmeWrapper.__wrap_boolean_property): New function.
(GpgmeWrapper.__getattr__): Wrap functions using properties.
(GpgmeWrapper.__setattr__): New method.  Likewise wrap functions.
(Context.signers): New property.
(Context.pinentry_mode): Likewise.
(Context._boolean_properties): List boolean properties.
(Context.__init__): Add keyword arguments for properties and apply
them.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-16 14:19:17 +02:00
Justus Winter
5492853d7b python: Improve the documentation.
* lang/python/Makefile.am: Copy the README file.
* lang/python/README: Rename, convert to org, and update.
* lang/python/pyme/__init__.py: Move license out of the docstring,
update docstring.
* lang/python/pyme/core.py: Add and update docstrings.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-16 14:07:41 +02:00
Justus Winter
7eef399d89 python: Get version information from the build system.
* configure.ac: Generate 'setup.py' and 'version.py'.
* lang/python/Makefile.am: Use generated setup script.
* lang/python/pyme/version.py: Turn it into a template, and get
version information from the build system.  Also drop some variables.
* lang/python/setup.py: Likewise.  This way we can avoid importing the
version module, which is frowned upon and actually caused a problem.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-16 14:07:41 +02:00
Justus Winter
a852f99a0a python: Fix exception leak.
* lang/python/helpers.c (pygpgme_stash_callback_exception): Fix leak.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-16 14:07:41 +02:00
Justus Winter
3bacce03e6 python: Fix license.
Other parts of the build system are also LGPLed.

* lang/python/Makefile.am: Fix license.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-16 14:07:41 +02:00
Justus Winter
77d149e861 python: Improve error handling.
* lang/python/helpers.c (pyPassphraseCb): Handle write errors.
(pyEditCb): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-08 18:12:35 +02:00
Justus Winter
5ebc205439 python: Add function to raise exceptions from c.
* lang/python/helpers.c (pygpgme_raise_exception): New function.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-08 17:54:45 +02:00
Justus Winter
8426304b67 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@g10code.com>
2016-06-08 17:12:00 +02:00
Justus Winter
990492ea4f python: Fix type.
* lang/python/gpgme.i: Use correct Python type for size.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-08 17:12:00 +02:00
Justus Winter
e3c5913a33 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@g10code.com>
2016-06-08 13:44:09 +02:00
Justus Winter
f8f9bf06bc python: Fix error handling.
* lang/python/gpgme.i: Fix freeing an uninitialized pointer in the
error handling of generated wrapper functions by explicitly storing
the pointer in a local variable which can be initialized.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-07 19:34:51 +02:00
Justus Winter
8196edf9ca python: Wrap file-like objects on demand.
* lang/python/gpgme.i (gpgme_data_t): Use new function to create
wrapper objects if necessary, and deallocate them after the function
call.
* lang/python/helpers.c (object_to_gpgme_data_t): New function.
* lang/python/helpers.h (object_to_gpgme_data_t): New prototype.
* lang/python/tests/Makefile.am (pytests): Add new test.
* lang/python/tests/t-idiomatic.py: New file.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-06 14:16:04 +02:00
Justus Winter
26c3accc95 python: Move helper function.
* lang/python/gpgme.i (object_to_gpgme_t): Move...
* lang/python/helpers.c: ... here.
* lang/python/helpers.h (object_to_gpgme_t): New prototype.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-06 14:16:04 +02:00
Justus Winter
89eb0cd4d6 python: Fix error handling.
* lang/python/gpgme.i (object_to_gpgme_t): Properly propagate
exceptions.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-06 14:16:04 +02:00
Justus Winter
ae06f7c2fe python: Initialize GPGME for the user.
* lang/python/pyme/core.py: Call 'check_version' and explain why.
* lang/python/tests/support.py (init_gpgme): Drop call here.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-06 14:16:04 +02:00
Justus Winter
2055a63605 python: Drop obsolete VCS keywords.
--
Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-06 14:16:01 +02:00
Justus Winter
bbf19124bb python: Fix test suite with GnuPG prior to 2.1.12.
* lang/python/tests/Makefile.am (gpg-agent.conf): Use
'allow-loopback-pinentry'.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-01 15:40:49 +02:00
Justus Winter
73c47535b6 python: Improve build system integration, fix warnings.
* lang/python/Makefile.am: Pass CFLAGS to python build system.
* lang/python/helpers.c (pyPassphraseCb): Use correct type for length.
(pygpgme_data_new_from_cbs): Drop unused variable.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-06-01 14:18:45 +02:00
Justus Winter
c88c9ef384 tests: Fix notation tests.
* lang/python/tests/t-sig-notation.py (check_result): Check critical
flag.
* tests/gpg/t-sig-notation.c (check_result): Likewise.

Fixes-commit: 1cacd7d0
Signed-off-by: Justus Winter <justus@gnupg.org>
2016-06-01 12:50:32 +02:00
Tobias Mueller
8ad17f402f python: use GPG_ERROR_CONFIG variable
instead of calling gpg-error-config.
This is useful when configuring with --with-gpgerror-prefix
because then GPG_ERROR_CONFIG contains the correct
/path/to/bin/gpg-error-config whereas calling gpg-error-config
directly would look in the user's PATH (and not in the prefix
where gpg-error-config was installed).

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-31 16:35:59 +02:00
Justus Winter
afa0dd56e1 python: Port more tests.
* lang/python/gpgme.i: Hide length fields of notations.
* lang/python/tests/Makefile.am (pytests): Add new tests.
* lang/python/tests/t-decrypt-verify.py: New file.
* lang/python/tests/t-sig-notation.py: Likewise.
* lang/python/tests/t-verify.py: Likewise.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-31 16:22:31 +02:00
Justus Winter
3915842657 python: Port more tests.
* lang/python/pyme/core.py (Data._error_check): Add
'gpgme_data_get_file_name' to the list of functions not returning an
error code.
* lang/python/tests/Makefile.am (pytests): Add new tests.
* lang/python/tests/support.py (verbose): New variable.
* lang/python/tests/t-data.py: Test setting and getting the filename.
* lang/python/tests/t-encrypt-large.py: New file.
* lang/python/tests/t-file-name.py: Likewise.
* lang/python/tests/t-trustlist.py: Likewise.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-27 17:24:12 +02:00
Justus Winter
2ae847c027 python: Implement data callbacks.
* lang/python/gpgme.i (object_to_gpgme_t): Set exception on error.
* lang/python/helpers.c (pyDataReadCb): New function.
(pyDataWriteCb): Likewise.
(pyDataSeekCb): Likewise.
(pyDataReleaseCb): Likewise.
(pygpgme_data_new_from_cbs): Likewise.
* lang/python/helpers.h (pygpgme_data_new_from_cbs): New prototype.
* lang/python/pyme/core.py (Data.__init__): Fix docstring, fix read
callbacks.
(Data.__del__): Fix read callbacks.
(Data._free_readcb): Drop function.
(Data._free_datacbs): New function.
(Data.new_from_cbs): Fix setting the callbacks.
(Data.write): Raise stashed exceptions.
(Data.read): Likewise.
* lang/python/tests/t-callbacks.py: Test new functionality.
* lang/python/tests/t-data.py: Likewise.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-27 14:04:28 +02:00
Justus Winter
ebfe2300c3 python: Fix object deallocation.
Handing a reference to the wrapper object created a non-trivial
circular reference that Pythons garbage collector is unable to break.
Explicitly break it by using a weak reference.

* lang/python/helpers.c (pygpgme_stash_callback_exception): Retrieve
object from weak reference.
* lang/python/pyme/core.py (Context.__del__): Free status callback.
(Context.set_passphrase_cb): Use a weak reference.
(Context.set_progress_cb): Likewise.
(Context.set_status_cb): Likewise.
(Context.op_edit): Likewise.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-27 12:25:59 +02:00
Justus Winter
bf188e280b python: Fix reading data from existing files.
* lang/python/pyme/core.py (Data.__init__): Add 'copy' kwargument, and
pass it to functions supporting it.  PEP8 fix.
(Data.new_from_fd): PEP8 fix.
(Data.new_from_file): Give a more helpful error message if copy is
False.  PEP8 fix.
(Data.new_from_fd): Hand the file descriptor to
'gpgme_data_new_from_fd', not a stream.  Fix docstring.
* lang/python/tests/t-data.py: Add tests for this.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-27 12:18:29 +02:00
Justus Winter
00ff6d0733 python: Improve and test Context.wait.
* lang/python/pyme/core.py (Context.wait): Improve docstring.  As the
context passed to 'gpgme_wait' is never NULL, it is pointless to look
at the returned context.  Always raise exceptions.
* lang/python/tests/Makefile.am (pytests): Add new test.
* lang/python/tests/t-wait.py: New file.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-24 18:00:16 +02:00
Justus Winter
7bc9cc717e python: Make all GnuPG errors available.
* lang/python/Makefile.am (errors.i): Generate file.
* lang/python/gpgme.i: Include generated file.
* lang/python/pyme/errors.py: Pull in all errors and error sources.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-24 18:00:16 +02:00
Justus Winter
0ebd6a1b43 python: Move the base wrapper class.
* python/lang/pyme/util.py (GpgmeWrapper): Move...
* python/lang/pyme/core.py: ... here.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-24 18:00:16 +02:00
Justus Winter
8b57f06e0c python: Support status callbacks.
* lang/python/helpers.c (pyStatusCb): New function.
(pygpgme_set_status_cb): Likewise.
* lang/python/helpers.h (pygpgme_set_status_cb): New prototype.
* lang/python/pyme/core.py (Context.__init__): Initialize
'last_statuscb'.
(Context._free_statuscb): New function.
(Context.set_status_cb): Likewise.
* lang/python/tests/t-callbacks.py: Test status callbacks.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-24 18:00:16 +02:00
Justus Winter
72afb68f8c python: Improve docstring.
* lang/python/pyme/core.py (Context.set_progress_cb): Improve
docstring.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-24 18:00:16 +02:00
Justus Winter
09803c4a81 python: Improve support for edit callbacks.
* lang/python/helpers.c (pyEditCb): Stash exceptions.
* lang/python/pyme/core.py (Context.op_edit): Hand in 'self'.
* lang/python/tests/Makefile.am (py_tests): Add new test.
* lang/python/tests/t-callbacks.py: Test edit callbacks.
* lang/python/tests/t-edit.py: New file.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-24 13:13:35 +02:00
Justus Winter
283f0bdc3d python: Fix hook.
* lang/python/helpers.c (pyProgressCb): Fix getting hook data.
* lang/python/tests/t-callbacks.py: Show that this works.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-23 18:23:34 +02:00
Justus Winter
5476ca6813 python: Move edit callback function.
* lang/python/gpgme.i (pyEditCb): Move...
* lang/python/helpers.c: ... here.
* lang/python/helpers.h (pyEditCb): New prototype.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-23 18:09:22 +02:00
Justus Winter
a42d814a65 python: Port more tests.
* lang/python/tests/Makefile.am (TESTS_ENVIRONMENT): Set
LD_LIBRARY_PATH.
(pytests): Add new tests.
* lang/python/tests/t-callbacks.py: Trim imports.
* lang/python/tests/t-encrypt-sign.py: New file.
* lang/python/tests/t-export.py: Likewise.
* lang/python/tests/t-signers.py: Likewise.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-23 15:43:55 +02:00
Justus Winter
c9cc0412e9 python: Translate list of strings.
* lang/python/gpgme.i: Add typemap translating list of strings.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-23 15:41:06 +02:00
Justus Winter
0d4e95621e python: Improve progress callbacks.
* lang/python/helpers.c (pyProgressCb): Stash python errors, convert
'what' to Unicode object.
* lang/python/pyme/core.py (Context.set_progress_cb): Hand in 'self'.
* lang/python/tests/t-callbacks.py: Test progress callbacks.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-19 16:08:33 +02:00
Justus Winter
d90857a08c python: Robust exception handling in callbacks.
* lang/python/helpers.c (pygpgme_stash_callback_exception): New
function.
(pygpgme_raise_callback_exception): Likewise.
(pyPassphraseCb): Stash python errors.
* lang/python/helpers.h (pygpgme_raise_callback_exception): New
prototype.
* lang/python/pyme/core.py ({Context,Data}.__init__): Move common
initialization to superclass.
(Context.set_progress_cb): Hand in 'self'.
* lang/python/pyme/util.py (GpgmeWrapper.__init__): New function.
(GpgmeWrapper.__getattr__): Raise stashed exceptions.
* lang/python/tests/Makefile.am (py_tests): Add new test.
* lang/python/tests/t-callbacks.py: New file.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-19 15:58:45 +02:00
Justus Winter
464d404c88 python: Add more tests.
* lang/python/tests/Makefile.am (py_tests): Add new tests.
* lang/python/tests/support.py (print_data): New function.
* lang/python/tests/t-decrypt.py: Use new function.
* lang/python/tests/t-encrypt.py: Likewise.
* lang/python/tests/t-sign.py: New file.
* lang/python/tests/t-encrypt-sym.py: Likewise.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-19 11:09:45 +02:00
Justus Winter
c1c893e338 python: More type conversion fixes.
* lang/python/helpers.c (pyPassphraseCb): Cope with 'uid_hint' being
NULL, convert it to an Unicode object, and cope with the callback
returning both Unicode and bytes objects.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-19 11:09:45 +02:00
Justus Winter
07f71cd177 python: Fix import.
* lang/python/helpers.c (pygpgme_exception_init): Make module import
relative.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-19 11:09:45 +02:00
Justus Winter
2c3a5d93e7 python: Various fixes.
* configure.ac: Fix SWIG detection, bump required Python version.
* lang/python/Makefile.am: Portability fix.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-18 15:37:38 +02:00
Werner Koch
9f14a24076
python: Delete duplicated license texts/
--
2016-05-17 16:57:11 +02:00
Justus Winter
db34332535 Merge branch 'justus/pyme3' 2016-05-17 15:10:28 +02:00
Justus Winter
10328324c8 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 <justus@gnupg.org>
2016-05-17 14:22:22 +02:00
Justus Winter
64e5fe767f python: Import GPGMEError.
* pyme/core.py: Import GPGMEError.

Fixes c5d118b2.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-17 14:18:21 +02:00
Justus Winter
9ceaec2591 python: Port more tests.
* lang/python/Makefile.am: Add bits from the c test suite.
* lang/python/support.py: New file.
* lang/python/t-decrypt.py: Likewise.
* lang/python/t-encrypt.py: Likewise.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-17 14:18:21 +02:00
Justus Winter
11314f0db6 python: Share generated methods between objects.
* lang/python/pyme/util.py (GpgmeWrapper.__getattr__): Monkey-patch
the class.
* lang/python/tests/t-wrapper.py: Demonstrate the sharing.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-12 18:29:04 +02:00
Justus Winter
c5d118b2a7 python: Raise exceptions on write errors.
* lang/python/pyme/core.py (Data.write): Handle errors.
* lang/python/pyme/errors.py (GPGMEError.fromSyserror): New function.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-12 18:01:24 +02:00
Justus Winter
f7094d8358 python: Fix writing to data buffers.
* lang/python/gpgme.i: Add typemap for buffers.
* lang/python/pyme/core.py (Data.write): Fix function.
* lang/python/tests/Makefile.am: Add new test.
* lang/python/tests/t-data.py: New file.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-12 17:59:21 +02:00
Justus Winter
e64bffe030 python: Add a test suite.
* configure.ac: Add new Makefile.
* lang/python/Makefile.am: Add subdirectory.
* lang/python/tests/Makefile.am: New file.
* lang/python/tests/t-wrapper.py: Likewise.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-12 15:37:00 +02:00
Justus Winter
ed0ce84fbd python: Cache generated wrapper functions.
* lang/python/util.py (GpgmeWrap.__getattr__): Cache generated wrapper
functions.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-12 14:57:42 +02:00
Justus Winter
e3d3d366bd python: Fix function invocation.
* lang/python/pyme/core.py (Data.new_from_fd): Fix function
invocation.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-12 12:59:05 +02:00
Justus Winter
af9371eb63 python: Fix name of exception, make slot methods explicit.
* lang/python/pyme/util.py (GpgmeWrapper._getctype): Fix exception,
add docstring.
(GpgmeWrapper._getnameprepend): New function.
(GpgmeWrapper._errorcheck): Likewise.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-12 12:59:05 +02:00
Justus Winter
ce5121ad53 python: Handle interpreter shutdown.
* lang/python/pyme/core.py: Avoid races at interpreter shutdown.  This
silences the most annoying occurrences, however this problem also
affects the SWIG generated code, which might indicate that the real
problem is somewhere else.  If so, this change can be easily reverted.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-12 11:53:43 +02:00
Justus Winter
c89d3a71ad python: Make test case more robust.
* lang/python/examples/t-edit.py: Check if key is found.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-12 11:51:21 +02:00
Justus Winter
d60deb8a12 python: Fix type translation.
* lang/python/gpgme.i: Adjust to Python3's string type being
'Unicode', not 'bytes'.  Fix type checking.
* lang/python/core.py (Data.write): Add docstring mentioning the
expected type of parameter 'buffer'.
(Data.read): Adjust read loop.  Also, use a saner chunk size, and join
all chunks at the end instead of adding them.
* lang/python/examples/simple.py: Adjust example.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-12 11:49:17 +02:00
Justus Winter
bbeee5e1a0 python: Fix simple example.
* lang/python/examples/simple.py: Flush stdout, encode name as
UTF-8 before passing it to GPGME.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-11 13:51:40 +02:00
Justus Winter
a29babd07c python: Integrate into the build system.
* configure.ac: Make Python bindings configurable, add new Makefile.
* lang/python/Makefile.am: New file.
* lang/python/setup.py: Integrate into the build system.
* m4/ax_pkg_swig.m4: New file from the autoconf archive.
* m4/m4_ax_swig_python.m4: Likewise.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-11 13:33:05 +02:00
Justus Winter
11392a80d9 python: PEP8 fixes.
Cherry picked from 0267c151.

Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-10 14:45:44 +02:00
Justus Winter
aade53a12b python: Delete trailing whitespace.
--
Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-10 13:30:30 +02:00
Justus Winter
000dbb5b9a python: Drop Debian packaging.
--
Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-10 13:21:34 +02:00
Justus Winter
f4ba16b31e python: Rename bindings.
--
Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-10 13:19:26 +02:00