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>
This commit is contained in:
parent
a324d0cffe
commit
8997d88bf9
@ -21,11 +21,21 @@
|
|||||||
%include "cpointer.i"
|
%include "cpointer.i"
|
||||||
%include "cstring.i"
|
%include "cstring.i"
|
||||||
|
|
||||||
// Generate doc strings for all methods.
|
/* Generate doc strings for all methods.
|
||||||
|
|
||||||
|
This will generate docstrings of the form
|
||||||
|
|
||||||
|
gpgme_op_encrypt(ctx, recp, flags, plain, cipher) -> gpgme_error_t
|
||||||
|
|
||||||
|
which we transform into
|
||||||
|
|
||||||
|
ctx.op_encrypt(recp, flags, plain, cipher) -> gpgme_error_t
|
||||||
|
|
||||||
|
for automagically wrapped functions. */
|
||||||
%feature("autodoc", "0");
|
%feature("autodoc", "0");
|
||||||
|
|
||||||
/* Allow use of Unicode objects, bytes, and None for strings. */
|
|
||||||
|
|
||||||
|
/* Allow use of Unicode objects, bytes, and None for strings. */
|
||||||
%typemap(in) const char * {
|
%typemap(in) const char * {
|
||||||
if ($input == Py_None)
|
if ($input == Py_None)
|
||||||
$1 = NULL;
|
$1 = NULL;
|
||||||
|
@ -24,6 +24,7 @@ and the 'Data' class describing buffers of data.
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
import weakref
|
import weakref
|
||||||
from . import pygpgme
|
from . import pygpgme
|
||||||
from .errors import errorcheck, GPGMEError
|
from .errors import errorcheck, GPGMEError
|
||||||
@ -107,6 +108,7 @@ class GpgmeWrapper(object):
|
|||||||
else:
|
else:
|
||||||
return get(self)
|
return get(self)
|
||||||
|
|
||||||
|
_munge_docstring = re.compile(r'gpgme_([^(]*)\(([^,]*), (.*\) -> .*)')
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
"""On-the-fly generation of wrapper methods and properties"""
|
"""On-the-fly generation of wrapper methods and properties"""
|
||||||
if key[0] == '_' or self._cprefix == None:
|
if key[0] == '_' or self._cprefix == None:
|
||||||
@ -119,27 +121,28 @@ class GpgmeWrapper(object):
|
|||||||
func = getattr(pygpgme, name)
|
func = getattr(pygpgme, name)
|
||||||
|
|
||||||
if self._errorcheck(name):
|
if self._errorcheck(name):
|
||||||
def _funcwrap(slf, *args, **kwargs):
|
def _funcwrap(slf, *args):
|
||||||
result = func(slf.wrapped, *args, **kwargs)
|
result = func(slf.wrapped, *args)
|
||||||
if slf._callback_excinfo:
|
if slf._callback_excinfo:
|
||||||
pygpgme.pygpgme_raise_callback_exception(slf)
|
pygpgme.pygpgme_raise_callback_exception(slf)
|
||||||
return errorcheck(result, "Invocation of " + name)
|
return errorcheck(result, "Invocation of " + name)
|
||||||
else:
|
else:
|
||||||
def _funcwrap(slf, *args, **kwargs):
|
def _funcwrap(slf, *args):
|
||||||
result = func(slf.wrapped, *args, **kwargs)
|
result = func(slf.wrapped, *args)
|
||||||
if slf._callback_excinfo:
|
if slf._callback_excinfo:
|
||||||
pygpgme.pygpgme_raise_callback_exception(slf)
|
pygpgme.pygpgme_raise_callback_exception(slf)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
_funcwrap.__doc__ = getattr(func, "__doc__")
|
doc = self._munge_docstring.sub(r'\2.\1(\3', getattr(func, "__doc__"))
|
||||||
|
_funcwrap.__doc__ = doc
|
||||||
|
|
||||||
# Monkey-patch the class.
|
# Monkey-patch the class.
|
||||||
setattr(self.__class__, key, _funcwrap)
|
setattr(self.__class__, key, _funcwrap)
|
||||||
|
|
||||||
# Bind the method to 'self'.
|
# Bind the method to 'self'.
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args):
|
||||||
return _funcwrap(self, *args, **kwargs)
|
return _funcwrap(self, *args)
|
||||||
_funcwrap.__doc__ = getattr(func, "__doc__")
|
wrapper.__doc__ = doc
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user