Hey Arkadiusz, On Fri, Mar 07, 2014 at 01:02:32PM +0100, Arkadiusz Miśkiewicz wrote: > 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 <[email protected]>
Very nice, applying to trunk. Acked-by: Steve Beattie <[email protected]>. If anyone wants to dig into swig more, the handling of function arguments around aa_getcon/aa_getpeercon and probably others could use some love. -- Steve Beattie <[email protected]> http://NxNW.org/~steve/
signature.asc
Description: Digital signature
-- AppArmor mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
