* configure.ac: Remove PYTHON_VERSIONS subst.
* lang/python/Makefile.am: Use basename of python as builddir prefix.
* lang/python/tests/run-tests.py: Likewise.
--
Two variables needs be at sync PYTHONS and PYTHON_VERSIONS, these may go
out of sync in some cases, for example in Gentoo where default python is
3.4 we get:
PYTHON='/usr/bin/python2'
PYTHONS='/usr/bin/python /usr/bin/python2'
PYTHON_VERSIONS='2.7 3.4'
We can use the basename of the python interpreter to achieve similar
effect without having to sync indexes between these two variables.
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
* lang/python/setup.py.in: Do not parse arguments.
--
The distutils settings can come from either command-line or
configuration file. Parsing parameters is not working in all cases.
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
* lang/python/gpg/version.py.in: Rename to lang/python/version.py.in.
configure.ac: Generate version.py.in in lang/python.
* lang/python/MANIFEST.in: Include version.py explicitly.
* lang/python/gpg: Rename to 'src'.
* lang/python/Makefile.am: Do not copy source files, do not use absolute
directories, support lib64 in uninstall, clean also dist directory, use
symlink for gpg src.
* lang/python/setup.py.in: Use builddir, copy sources into builddir,
copy version.py into module.
--
Simplify build to symlink the gpg sources into builddir instead of
copying. This requires handling of version.py as generated file.
In addition apply some cleanups: Drop the absolution pathes, clean the
dist directory as well, support lib64 for sitelib at uninstall.
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
* lang/python/gpgme-h-clean.py: Delete file.
* lang/python/MANIFEST.in: Adapt accordingly.
* lang/python/Makefile.am (EXTRA_DIST): Likewise.
(COPY_FILES_GPG): Bring variable back.
(copystamp): Copy files.
(clean-local): Delete copied files.
(install-exec-local): Do not create and install list of installed
files.
(uninstall-local): Instead, create some explicit rules to uninstall
the extension.
* lang/python/setup.py.in: Parse arguments. Locate files either in
the source directory, or in the build base directory. Inline the code
from 'gpgme-h-clean.py'. Copy 'helpers.c', add source directory as
include directory.
Fixes-commit: 801d7d8c5d
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/setup.py.in: Generate files within BuildExtFirstHack
adjust build flags at this point instead of global.
* lang/python/Makefile.am: Remove logic of separate source directory per
python version in favor of build directory.
* lang/python/tests/run-tests.py: Adjust build directory location.
--
Generate files into build directory, leaving the source directory clean.
Use the same source directory for multiple python version build. Result
of 'prepare' target is a standard distutil layout that can be used
easily by downstream to build all python targets in-place.
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
* lang/python/Makefile.am: Fix 'prepare' target.
* lang/python/setup.py.in: Use 'abs_top_builddir' instead of guessing
the path.
--
'prepare' will prepare target at PREPAREDIR. The automake integration
will also make use of prepare target. Downstream distributors may
also make use of prepare target.
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
* lang/python/tests/support.py (assert_gpg_version): Fix error
message. Skip all tests when we use GnuPG older than 2.1.12.
GnuPG-bug-id: 3008
Signed-off-by: Justus Winter <justus@g10code.com>
* NEWS: Update.
* lang/python/gpg/core.py (Context.keylist): New keyword argument
'source'. If given, list keys from 'source'.
* lang/python/gpgme.i: Wrap the argument to
'gpgme_op_keylist_from_data_start'.
* lang/python/tests/Makefile.am (py_tests): Add new test.
* lang/python/tests/support.py (EphemeralContext): Do not throw an
error if no agent has been started in the context.
* lang/python/tests/t-keylist-from-data.py: New file.
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/tests/Makefile.am (gpg-agent.conf): Do not hard-code the
option. This breaks gpg-agent from GnuPG 2.0.
* tests/start-stop-agent: Rather, check if the option is supported and
add it to the configuration if it is.
GnuPG-bug-id: 3008
Fixes-commit: bbf19124bb
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/tests/support.py (assert_gpg_version): New function.
* lang/python/tests/t-callbacks.py: Use the new function to skip the
test if GnuPG is too old.
* lang/python/tests/t-edit.py: Likewise.
* lang/python/tests/t-encrypt-sym.py: Likewise.
* lang/python/tests/t-quick-key-creation.py: Likewise.
* lang/python/tests/t-quick-key-manipulation.py: Likewise.
* lang/python/tests/t-quick-key-signing.py: Likewise.
GnuPG-bug-id: 3008
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/tests/run-tests.py: Make the error message shown when we
cannot locate the python module in the build tree more helpful.
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/tests/support.py (TemporaryDirectory): Always use our
own version even if 'tempfile.TemporaryDirectory' is provided, because
we need to use 'shutil.rmtree(..., ignore_errors=True)' to avoid it
tripping over gpg-agent deleting its own sockets.
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/tests/initial.py: Print path of the Python module used
during tests. Useful to detect if by any mistake the wrong module is
picked up.
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/tests/t-quick-key-manipulation.py: Modify the
configuration file in the ephemeral home directory, not the one used
by all the tests.
Fixes-commit: 15fbac9e72
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/tests/support.py (EphemeralContext): New function.
* lang/python/tests/t-quick-key-creation.py: Use the new function to
manage ephemeral contexts.
* lang/python/tests/t-quick-key-manipulation.py: Likewise.
* lang/python/tests/t-quick-subkey-creation.py: Likewise.
--
Previously, there was a problem with cleaning up ephemeral home
directories. shutil.rmtree deleted the agents main socket, gpg-agent
detected that, and deleted the other sockets as well, racing
shutil.rmtree which did not cope will with that.
Fix this by asking the agent nicely to shut down.
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/gpg/core.py (Context.assuan_transact): Fix testing
whether the command is a string on Python2.
* lang/python/tests/t-protocol-assuan.py: Improve the test to detect
this problem.
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/Makefile.am (copystamp): Also copy the setup script, and
link the header files.
(all-local): Use local setup script.
(sdist): Fix Python source distribution creation.
(CLEANFILES): Remove now obsolete files.
(install-exec-local): Use local setup script.
* lang/python/setup.py.in: Adjust relative paths to in-tree files.
Fixes-commit: fe65a26ab5
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/gpgme.i: Added a genericrepr macro and use it for
gpgme_key, gpgme_subkey, and gpgme_key_sig.
--
To look nicer in Python's REPL.
We define a generic __repr__ as a SWIG macro and use that to extend some
defined SWIG objects.
The alternative would have been to write a custom __repr__ function for
each class but that would need to be changed everytime the object's
structure changes. The bindings should be easy to maintain, I guess.
This comes at the expense that the reprs are now relatively long and
contain, for example, both keyid and fingerprint.
Signed-off-by: Tobias Mueller <muelli@cryptobitch.de>
* lang/python/setup.py.in: Call SWIG without the builtin flag.
--
The SWIG documentation
<http://www.swig.org/Doc2.0/Python.html#Python_nn28> leaves the
impression that -builtin is solely for increasing performance:
New in SWIG version 2.0.4: The use of Python proxy classes has
performance implications that may be unacceptable for a high-
performance library. The new -builtin option instructs SWIG to
forego the use of proxy classes, and instead create wrapped types as
new built-in Python types. When this option is used, the following
section ("Proxy classes") does not apply. Details on the use of the
-builtin option are in the Built-in Types section.
While not wasting CPU cycles is good, it also prevents Python code being
written in the wrapper itself. That, however, may be useful to make it
easier to extend the wrapper.
Partially reverts: 856bcfe293
Signed-off-by: Tobias Mueller <muelli@cryptobitch.de>
* lang/python/gpgme.i (pygpgme_wrap_gpgme_data_t): Provide a "self"
variable for SWIG_NewPointerObj and call SWIG_NewPointerObj rather than
SWIG_Python_NewPointerObj.
--
SWIG_Python_NewPointerObj seems to be an implementation detail, because
SWIG's documentation does not mention that function at all. In fact,
SWIG_NewPointerObj is a call to SWIG_Python_NewPointerObj with the first
parameter being either NULL or the "self" variable, depending on whether
SWIG is called with the -builtin flag. So far, the first parameter was
hard-coded to NULL. This change also hard-codes it to NULL but makes
it more explicit. The benefit is that the documented function is being
used and that compilation works regardless of the -builtin flag.
Partially reverts: 856bcfe293
Signed-off-by: Tobias Mueller <muelli@cryptobitch.de>
* lang/python/setup.py.in: Only call with -py3 when we run under python3
or higher.
--
If we ever remove the -builtin flag and leave the the -py3 flag, SWIG
will generate Python code which will be incompatible with Python 2,
because the py3 flag generates python3 code which is incompatible with
python2.
So we conditionally generate SWIG bindings with -py3.
Signed-off-by: Tobias Mueller <muelli@cryptobitch.de>
* lang/python/Makefile.am (copystamp): Create one copy per Python
version.
(all-local): Adapt.
(clean-local): Likewise.
(install-exec-local): Likewise.
* lang/python/tests/run-tests.py: Likewise.
--
Currently, we use one copy of the Python module's source to build for
all Python versions. This is problematic, because SWIG writes a
wrapper file into the source tree. Currently, this file works with
both Python 2 and 3, but this is purely by chance.
Improve the situation by creating one copy per Python version so that
SWIG can write version-specific code into each copy.
Signed-off-by: Justus Winter <justus@g10code.com>
* lang/python/gpgme.i: Added gpgme_op_keylist_start with defaults
* lang/python/tests/t-keylist.py: Added tests for default parameters
--
To increase the ease of use, op_keylist_start
parameters default to sensible values.
The empty string matches all keys.
We assume that the user wants to retrieve public keys most of the time,
so we default to public keys rather than secret keys.
Signed-off-by: Tobias Mueller <muelli@cryptobitch.de>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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.
* 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>
* 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>
* 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>
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>
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>
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>
* 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>
* 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>
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>
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>
* 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>
* 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>
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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
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>
* 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>
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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>
* 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>