apparmor/libraries/libapparmor/swig
Arkadiusz Miśkiewicz 757cc25163 libapparmor: raise exception in python bindings when something fails
Current libapparmor python bindings are very "unpythonic". Also lack
ability to access "why" information in case of failure.

In python when something fail the normal behaviour is exception
to occur. In case of apparmor functions die silently and require
user to verify returned value.

And here comes second problem. In C api when return value is -1
(and the same value is returned in python API) we can access errno
to get information why this occured. Unfortunately in python there
is no way to access the same information.  Pythonic way of accessing
errno is via exception (which is never raised in python bindings
currently).

So the patch adds exceptions on failures. First %exception creates
a wrapper that swig adds to each function listed below. Empty %exception
causes that the rest of code (beside listed functions) won't be wrapped.

How this works? Example on apparmor disabled system:

Before:
>>> LibAppArmor.aa_change_hat(hat, random.randint(1, sys.maxint))
-1

After:
>>> LibAppArmor.aa_change_hat(hat, random.randint(1, sys.maxint))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 22] Invalid argument

so pythonic way of accessing "why":
>>> try:
...     LibAppArmor.aa_change_hat(hat, random.randint(1, sys.maxint))
... except OSError, e:
...     print e.errno
...
22

Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl>
Acked-by: Steve Beattie <steve@nxnw.org>
2014-03-07 11:54:12 -08:00
..
java move libapparmor into the libraries directory 2008-05-19 22:48:31 +00:00
perl libapparmor: move public headers to separate directory 2014-01-06 14:08:55 -08:00
python libapparmor: move public headers to separate directory 2014-01-06 14:08:55 -08:00
ruby libapparmor: move public headers to separate directory 2014-01-06 14:08:55 -08:00
SWIG libapparmor: raise exception in python bindings when something fails 2014-03-07 11:54:12 -08:00
Makefile.am move libapparmor into the libraries directory 2008-05-19 22:48:31 +00:00