python: Cache generated wrapper functions.

* lang/python/util.py (GpgmeWrap.__getattr__): Cache generated wrapper
functions.

Signed-off-by: Justus Winter <justus@gnupg.org>
This commit is contained in:
Justus Winter 2016-05-12 14:57:42 +02:00
parent e3d3d366bd
commit ed0ce84fbd

View File

@ -69,11 +69,11 @@ class GpgmeWrapper(object):
returning gpgme_error_t."""
raise NotImplementedError()
def __getattr__(self, name):
def __getattr__(self, key):
"""On-the-fly function generation."""
if name[0] == '_' or self._getnameprepend() == None:
if key[0] == '_' or self._getnameprepend() == None:
return None
name = self._getnameprepend() + name
name = self._getnameprepend() + key
if self._errorcheck(name):
def _funcwrap(*args, **kwargs):
args = [self.wrapped] + list(args)
@ -85,5 +85,8 @@ class GpgmeWrapper(object):
return getattr(pygpgme, name)(*args, **kwargs)
_funcwrap.__doc__ = getattr(getattr(pygpgme, name), "__doc__")
# Cache the wrapper function.
setattr(self, key, _funcwrap)
return _funcwrap