Commit Graph

23 Commits

Author SHA1 Message Date
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
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
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
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
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
db34332535 Merge branch 'justus/pyme3' 2016-05-17 15:10:28 +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
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
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
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
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
aade53a12b python: Delete trailing whitespace.
--
Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-10 13:30:30 +02:00
Justus Winter
f4ba16b31e python: Rename bindings.
--
Signed-off-by: Justus Winter <justus@gnupg.org>
2016-05-10 13:19:26 +02:00