[Tutor] How to wrap ctype functions
Jan Jansen
knacktus at googlemail.com
Wed Mar 3 18:43:28 CET 2010
Hi there,
I wonder what's the best way to wrap given function calls (in this case
ctype function calls but more generally built-in functions and those kinds).
I have a huge c library and almost all functions return an error code. The
library also contains a function, that returns the corresponding error
message to the error code. So, what I need to do for every call to one of
the libraries functions looks like this:
error_code = my_c_library.SOME_FUNCTION_
CALL(argument)
if error_code != 0:
error_message = my_c_library.GET_ERROR_TEXT(error_code)
print "error in function call SOME_FUNCTION_CALL"
print error_message
my_c_library.EXIT_AND_CLEAN_UP()
Also, for some function calls I would need to do some preperations like:
error_code = my_c_library.LOG_IN_AS_ADMINISTRATOR(admin_user,
admin_password)
error_code = my_c_library.SOME_FUNCTION_CALL(argument)
I like the decorator idea, but I can't figure out if it's applicable here.
To be able to call the function in a manner like this would be great, e.g.
@change_user(admin_user, admin_password)
@error_handling
my_c_library.SOME_FUNCTION_CALL(argument)
Best regards,
Jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100303/c4c621be/attachment.html>
More information about the Tutor
mailing list