aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/helpers.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2025-02-03python: Remove Python bindingsIngo Klöcker1-1189/+0
* README: Update. * configure.ac: Remove checks, variables and file generations related to the Python bindings. Remove python from available_languages and default_languages. * lang/Makefile.am (DIST_SUBDIRS): Remove python. * lang/python: Remove. * m4/ax_pkg_swig.m4, m4/ax_python_devel.m4, m4/python.m4: Remove. -- The Python bindings have been moved to a separate Git repository: gpgmepy. GnuPG-bug-id: 7262
2023-05-23python: Fix wrong use of write.Werner Koch1-5/+5
* lang/python/helpers.c (pyPassphraseCb): Use gpgme_io_writen. (_gpg_interact_cb): Ditto. * lang/python/helpers.h (write) [W32]: Remove bad write macro. -- GnuPG-bug-id: T6501 Using write(2) without checking for EINTR is a not a good idea. Futher gpgme_io_writen is the correct way to send data from a callback. This also fixed the wrong use of a simple macro for Windows.
2018-11-08spelling: fix misspellingsDaniel Kahn Gillmor1-1/+1
Signed-off-by: Daniel Kahn Gillmor <[email protected]>
2017-02-16python: Fix passphrase callback wrapping.Justus Winter1-1/+15
* lang/python/helpers.c (pyPassphraseCb): Cope with 'passphrase_info' being NULL. Signed-off-by: Justus Winter <[email protected]>
2016-12-05python: Try to be more helpful when given a string to encrypt().Tobias Mueller1-2/+4
* 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 <[email protected]>
2016-10-31python: Rename Python module from PyME to gpg.Daniel Kahn Gillmor1-62/+62
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 <[email protected]>
2016-09-26python: Include 'config.h'.Justus Winter1-0/+4
* 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 <[email protected]>
2016-09-16python: Release the GIL during calls into GPGME.Justus Winter1-0/+37
* 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 <[email protected]> Signed-off-by: Justus Winter <[email protected]>
2016-09-16python: Adapt to 'gpgme_op_interact'.Justus Winter1-4/+19
* 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 <[email protected]>
2016-09-13python: Handle slight differences between Python 2 and 3.Justus Winter1-14/+22
* 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 <[email protected]>
2016-09-13python: Fix types and error handling.Justus Winter1-11/+26
* lang/python/helpers.c (_pyme_edit_cb): Drop the const. (_pyme_assuan_{data,inquire,status}_cb): Fix error handling. Signed-off-by: Justus Winter <[email protected]>
2016-09-12python: Make type translation compatible with Python 2.7.Justus Winter1-4/+34
* lang/python/gpgme.i: Avoid functions not available in Python 2.7. * lang/python/helpers.c: Likewise. Signed-off-by: Justus Winter <[email protected]>
2016-08-02python: Add a flag identifying in-tree builds.Justus Winter1-0/+9
* 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 <[email protected]>
2016-07-28python: Rename exported functions.Justus Winter1-7/+7
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 <[email protected]>
2016-07-28python: Rename private functions.Justus Winter1-47/+47
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 <[email protected]>
2016-07-28python: Support the Assuan engine.Justus Winter1-0/+116
* 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 <[email protected]>
2016-07-28python: Expose less functions to the Python world.Justus Winter1-0/+2
* 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 <[email protected]>
2016-07-11python: Do not depend on access to internal data structures.Justus Winter1-0/+1
* 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 <[email protected]>
2016-07-08python: Fix raising stashed exceptions.Justus Winter1-1/+7
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 <[email protected]>
2016-06-16python: Make result objects more robust.Justus Winter1-0/+32
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 <[email protected]>
2016-06-16python: Simplify wrapping glue.Justus Winter1-2/+2
* 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 <[email protected]>
2016-06-16python: Rework callbacks.Justus Winter1-27/+129
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 <[email protected]>
2016-06-16python: Wrap objects implementing the buffer protocol.Justus Winter1-46/+54
* 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 <[email protected]>
2016-06-16python: Fix exception leak.Justus Winter1-0/+1
* lang/python/helpers.c (pygpgme_stash_callback_exception): Fix leak. Signed-off-by: Justus Winter <[email protected]>
2016-06-08python: Improve error handling.Justus Winter1-6/+23
* lang/python/helpers.c (pyPassphraseCb): Handle write errors. (pyEditCb): Likewise. Signed-off-by: Justus Winter <[email protected]>
2016-06-08python: Add function to raise exceptions from c.Justus Winter1-0/+20
* lang/python/helpers.c (pygpgme_raise_exception): New function. Signed-off-by: Justus Winter <[email protected]>
2016-06-06python: Wrap file-like objects on demand.Justus Winter1-0/+65
* 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 <[email protected]>
2016-06-06python: Move helper function.Justus Winter1-0/+36
* 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 <[email protected]>
2016-06-06python: Drop obsolete VCS keywords.Justus Winter1-1/+0
-- Signed-off-by: Justus Winter <[email protected]>
2016-06-01python: Improve build system integration, fix warnings.Justus Winter1-2/+6
* 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 <[email protected]>
2016-05-27python: Implement data callbacks.Justus Winter1-0/+242
* 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 <[email protected]>
2016-05-27python: Fix object deallocation.Justus Winter1-3/+19
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 <[email protected]>
2016-05-24python: Support status callbacks.Justus Winter1-0/+65
* 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 <[email protected]>
2016-05-24python: Improve support for edit callbacks.Justus Winter1-4/+8
* 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 <[email protected]>
2016-05-23python: Fix hook.Justus Winter1-1/+1
* lang/python/helpers.c (pyProgressCb): Fix getting hook data. * lang/python/tests/t-callbacks.py: Show that this works. Signed-off-by: Justus Winter <[email protected]>
2016-05-23python: Move edit callback function.Justus Winter1-0/+45
* lang/python/gpgme.i (pyEditCb): Move... * lang/python/helpers.c: ... here. * lang/python/helpers.h (pyEditCb): New prototype. Signed-off-by: Justus Winter <[email protected]>
2016-05-19python: Improve progress callbacks.Justus Winter1-4/+14
* 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 <[email protected]>
2016-05-19python: Robust exception handling in callbacks.Justus Winter1-5/+90
* 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 <[email protected]>
2016-05-19python: More type conversion fixes.Justus Winter1-2/+24
* 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 <[email protected]>
2016-05-19python: Fix import.Justus Winter1-1/+4
* lang/python/helpers.c (pygpgme_exception_init): Make module import relative. Signed-off-by: Justus Winter <[email protected]>
2016-05-10python: Delete trailing whitespace.Justus Winter1-3/+3
-- Signed-off-by: Justus Winter <[email protected]>
2016-05-10python: Rename bindings.Justus Winter1-0/+0
-- Signed-off-by: Justus Winter <[email protected]>
2015-05-05Python 3 port of PyMEBen McGinnes1-0/+154
* The entirety of the Python 3 port of PyME up to commit 2145348ec54c6027f2ea20f695de0277e2871405 * The old commit log has been saved as lang/py3-pyme/docs/old-commits.log * Can be viewed as a normal (separate) git repository at https://github.com/adversary-org/pyme3 * Utilising the submodule feature of git was deliberately skipped on humanitarian grounds (in order to prevent pain and suffering on the part of anyone having to manage this repository).