Commit Graph

143 Commits

Author SHA1 Message Date
Justus Winter
d0e91d28f6 python: Add a switch '--quiet' to the test runner.
* lang/python/tests/run-tests.py: Add and honor a switch '--quiet'.
This way we can use this script to run Python tests one by one without
the noise, and the script will setup the necessary environment for us.

Signed-off-by: Justus Winter <justus@g10code.com>
2017-01-03 15:28:36 +01:00
Tobias Mueller
05896c210f python: Try to be more helpful when given a string to encrypt().
* lang/python/helpers.c (_gpg_obj2gpgme_data_t): Extended error
message.
* lang/python/tests/t-encrypt.py: Test for "encode" in error message.
--
The motivation is to help the user when encrypting fails. I claim that
it is not obvious to not being able to encrypt a string directly.  To
nudge the user into encoding it to bytes, the error message is a bit
extended.

Signed-off-by: Tobias Mueller <muelli@cryptobitch.de>
2016-12-05 12:44:20 +01:00
Tobias Mueller
fb7f4cb973 python: Define a macro for wrapping fragile result objects.
* lang/python/gpgme.i (wrapresult): New Macro.
--

This reduces the amount of copy and pasted code at the expense of a
slightly more complicated logic with a macro.

Signed-off-by: Tobias Mueller <muelli@cryptobitch.de>
2016-12-05 12:41:45 +01:00
Tobias Mueller
ae21d2705f python: Check "buffer" when writing to sys.stdout for python2 compat.
* lang/python/tests/support.py (print_data): Add check for buffer.
--

When running with something like make -C lang/python check verbose=2 the
test would fail under python2, because the file objects do not have a
buffer property.

Signed-off-by: Tobias Mueller <muelli@cryptobitch.de>
2016-12-01 17:39:38 +01:00
Tobias Mueller
154389f2a5 python: Make Context have a repr method.
* lang/python/gpg/core.py (Context.__repr__): New function.
--

This makes Context objects look nicer in a REPL.

Signed-off-by: Tobias Mueller <muelli@cryptobitch.de>
2016-12-01 17:37:15 +01:00
Tobias Mueller
db2f6c1ca3 python: Make Results have a nicer __repr__.
* lang/python/gpg/results.py (Result.__str__): Renamed to '__repr__'
...
* lang/python/gpg/results.py (Result.__repr__): ... and added fields.
--

So that it looks a bit nicer in the Python REPL.

It looked like this before:

In [2]: gpg.core.get_engine_info()[0]
Out[2]:
<gpg.results.EngineInfo at 0x7fb23509a240>

Now the output is

In [2]: gpg.core.get_engine_info()[0]
Out[2]:
EngineInfo(file_name='/usr/bin/gpg2', home_dir=None,
protocol=0, req_version='1.4.0', version='2.1.11')

This also applies to other results, e.g. the ImportResult.

Note that the format now changed from "<Class >" to "Class()". The
Python documentation on repr states: "For many object types, including
most builtins, eval(repr(obj)) == obj."

Signed-off-by: Tobias Mueller <muelli@cryptobitch.de>
2016-12-01 17:28:39 +01:00
Justus Winter
fd4d476214 python: Fix removing the TOFU database.
* lang/python/Makefile.am (CLEANFILES): Move 'tofu.db'...
* lang/python/tests/Makefile.am (CLEANFILES): ... here.

Fixes-commit: 9b22f82afc
Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-25 09:55:42 +01:00
Justus Winter
9b22f82afc tests: Remove tofu.db.
* lang/python/Makefile.am (CLEANFILES): Add 'tofu.db'.
* tests/gpg/Makefile.am (CLEANFILES): Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-25 09:13:01 +01:00
Alon Bar-Lev
41d8c7e51a
tests,python: Atomic directory creation
* lang/python/tests/Makefile.am:  Use MIDIR_P.
* tests/gpg/Makefile.am: Ditto.
* tests/gpgsm/Makefile.am: Ditto.

--
Solves race in parallel build when mkdir fails if directory exists.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>

- Tweaked the ChangeLog

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-11-11 09:09:40 +01:00
Justus Winter
f1f341062e python: Require at least GPGME 1.7 for out-of-tree builds.
* lang/python/setup.py.in: Bump required version to 1.7.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-11-09 13:57:05 +01:00
Justus Winter
4b32643450 python: Use vanity modules for constants in tests and examples.
* lang/python/gpg/constants/sig/notation.py: New file.
* lang/python/gpg/constants/sig/__init__.py: Import new module.

* lang/python/examples/assuan.py: Use more specific module for
constants, e.g. 'protocol.ASSUAN' instead of 'PROTOCOL_ASSUAN'.
* lang/python/examples/testCMSgetkey.py: Likewise.
* lang/python/tests/initial.py: Likewise.
* lang/python/tests/t-callbacks.py: Likewise.
* lang/python/tests/t-decrypt-verify.py: Likewise.
* lang/python/tests/t-decrypt.py: Likewise.
* lang/python/tests/t-edit.py: Likewise.
* lang/python/tests/t-encrypt-large.py: Likewise.
* 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-export.py: Likewise.
* lang/python/tests/t-file-name.py: Likewise.
* lang/python/tests/t-idiomatic.py: Likewise.
* lang/python/tests/t-import.py: Likewise.
* lang/python/tests/t-keylist.py: Likewise.
* lang/python/tests/t-protocol-assuan.py: Likewise.
* lang/python/tests/t-sig-notation.py: Likewise.
* lang/python/tests/t-sign.py: Likewise.
* lang/python/tests/t-signers.py: Likewise.
* lang/python/tests/t-trustlist.py: Likewise.
* lang/python/tests/t-verify.py: Likewise.
* lang/python/tests/t-wait.py: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-31 15:42:35 +01:00
Justus Winter
20dc37a0e7 python: Import the topmost module in tests and examples.
* examples/verifydetails.py: Only import the topmost module 'gpg' and
update the code accordingly.
* tests/support.py: Likewise.
* tests/t-callbacks.py: Likewise.
* tests/t-data.py: Likewise.
* tests/t-decrypt-verify.py: Likewise.
* tests/t-decrypt.py: Likewise.
* tests/t-edit.py: Likewise.
* tests/t-encrypt-large.py: Likewise.
* tests/t-encrypt-sign.py: Likewise.
* tests/t-encrypt-sym.py: Likewise.
* tests/t-encrypt.py: Likewise.
* tests/t-export.py: Likewise.
* tests/t-file-name.py: Likewise.
* tests/t-import.py: Likewise.
* tests/t-keylist.py: Likewise.
* tests/t-sig-notation.py: Likewise.
* tests/t-sign.py: Likewise.
* tests/t-signers.py: Likewise.
* tests/t-trustlist.py: Likewise.
* tests/t-verify.py: Likewise.
* tests/t-wait.py: Likewise.
* tests/t-wrapper.py: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-31 15:42:35 +01:00
Justus Winter
70b7064e5c python: Improve constants module.
* lang/python/gpg/constants/__init__.py: Import all modules below
'constants/'.  Interface hygiene: delete 'util'.
* lang/python/gpg/constants/data/encoding.py: Delete 'util'.
* lang/python/gpg/constants/event.py: Likewise.
* lang/python/gpg/constants/import.py: Likewise.
* lang/python/gpg/constants/keylist/mode.py: Likewise.
* lang/python/gpg/constants/md.py: Likewise.
* lang/python/gpg/constants/pk.py: Likewise.
* lang/python/gpg/constants/protocol.py: Likewise.
* lang/python/gpg/constants/sig/mode.py: Likewise.
* lang/python/gpg/constants/sigsum.py: Likewise.
* lang/python/gpg/constants/validity.py: Likewise.
* lang/python/gpg/errors.py: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-31 15:42:35 +01:00
Daniel Kahn Gillmor
2fac017618 python: Rename Python module from PyME to gpg.
This follows weeks of discussion on the gnupg-devel mailing list.
Hopefully it will make it easier for people using Python to use GnuPG
in the future.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2016-10-31 15:42:27 +01:00
Werner Koch
c6cab5a2bd
python: Call ln(1) in a portable way.
* lang/python/Makefile.am: Specify target dir for ln.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-10-14 16:32:59 +02:00
Justus Winter
f526d0e22e
python: Make 'get_key' more idiomatic.
* lang/python/pyme/core.py (Context.get_key): Raise errors.KeyNotFound
if the key is not found.  This error is both a KeyError for idiomatic
error handling as well as a GPGMEError so we don't break existing
code.
* lang/python/pyme/errors.py (KeyNotFound): New class.
* lang/python/tests/support.py (no_such_key): New variable.
* lang/python/tests/t-keylist.py: Test the new behavior.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-13 13:19:49 +02:00
Justus Winter
1e6073ffa9
python: Return public keys by default.
* lang/python/pyme/core.py (Core.get_key): Return public keys by
default, improve docstring.
* lang/python/examples/testCMSgetkey.py: Update example.
* lang/python/examples/verifydetails.py: Likewise.

GnuPG-bug-id: 2751
Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-13 13:19:47 +02:00
Justus Winter
cabd4c74e5
python: Fix example.
* lang/python/examples/inter-edit.py: Fix example.

Fixes-commit: a458e7fe
Signed-off-by: Justus Winter <justus@g10code.com>
2016-10-13 13:19:46 +02:00
Alon Bar-Lev
453ab9d24c python: Link 'data.h' and 'config.h' into the builddir.
* lang/python/Makefile.am: Link to the files.
* lang/python/gpgme.i: Update path.
* lang/python/setup.py.in: Do not add the top builddir to the include
path.
--
To make it easy to build the subpackage using standard tools without
altering environment or CFLAGS, symlink the required artifacts from
source tree into subpackage directory when preparing sources.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
2016-09-30 14:47:26 +02:00
Alon Bar-Lev
68fb8371a1 python: Add 'prepare' target.
* lang/python/Makefile.am: Add 'prepare' target.
--
This enables preparing the package using autoconf then build using
distutils as separate stage.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
2016-09-30 14:46:28 +02:00
Justus Winter
a6e9eefb23 tests: Fix blunder.
--
Fixes-commit: a423603f
Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-27 12:49:24 +02:00
Justus Winter
a423603f80 tests: Fix check for gpg versions not reporting the critical flag.
* lang/python/tests/t-sig-notation.py: Also blacklist 2.0.x.
* tests/gpg/t-sig-notation.c: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-27 12:31:18 +02:00
Justus Winter
c9934bb1ee python: Get rid of the last C++-style comments.
--
Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-26 16:54:58 +02:00
Justus Winter
c38fabfea0 python: Correctly translate to size_t.
* lang/python/gpgme.i: Correctly translate Python number to size_t.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-26 16:54:58 +02:00
Justus Winter
1d80e7374a python: Correctly translate off_t.
* lang/python/gpgme.i: Improve int/long translations, correctly handle
off_t with large file support.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-26 16:54:58 +02:00
Justus Winter
3703a47238 python: Include 'config.h'.
* lang/python/Makefile.am: Pass 'top_builddir' to 'setup.py'.
* lang/python/gpgme.i: Include 'config.h'.
* lang/python/helpers.c: Likewise.
* lang/python/helpers.h: Likewise.
* lang/python/setup.py.in: Make sure that 'config.h' can be found.
--
Fixes build on 32 bit platforms with large file support.

Signed-off-by: Justus Winter <justus@g10code.com>
2016-09-26 16:54:57 +02:00
Werner Koch
936928632b
python: Create install dir.
* lang/python/Makefile.am (install-exec-local): Create dir.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-09-21 09:18:00 +02:00
Werner Koch
0763357e39
tests: Make "make -j distcheck" work in Python.
* lang/python/Makefile.am (SUBDIRS): Make current dir fist.
* lang/python/tests/Makefile.am (xcheck): Depend on pubring-stamp.
(CLEANFILES): Remove private-keys-v1.d/gpg-sample.stamp.
(check-local): Remove.
(initial.py): Remove dependency.
(./pubring-stamp): Depend on conf files and the
private-keys-v1.d/gpg-sample.stamp file.  Also replace use of
basename.

--

This addresses the problem that two rules might run the private keys
copy rule and due to the files being chmod -w during make discheck the
second process running that rule's cp would get a permission error.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-09-20 19:58:00 +02:00
Werner Koch
bfb6890ded
tests: Use --batch for gpg import.
* lang/python/tests/Makefile.am (./pubring-stamp): Use --batch with
GPG to avoid Pinentries during import when using GnuPG >= 2.1.
Replace touch by echo.
* tests/gpg/Makefile.am (./pubring-stamp): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
2016-09-20 19:51:02 +02:00
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