[Freeipa-devel] [PATCH] 76 Refactor exc_callback invocation

Jan Cholasta jcholast at redhat.com
Mon Apr 23 14:33:32 UTC 2012


Hi,

this patch replaces _call_exc_callbacks with a function wrapper, which 
will automatically call exception callbacks when an exception is raised 
from the function. This removes the need to specify the function and its 
arguments twice (once in the function call itself and once in 
_call_exc_callbacks).

Code like this:

try:
     # original call
     ret = func(arg, kwarg=0)
except ExecutionError, e:
     try:
         # the function and its arguments need to be specified again!
         ret = self._call_exc_callbacks(args, options, e, func, arg, 
kwarg=0)
     except ExecutionErrorSubclass, e:
         handle_error(e)

becomes this:

try:
     ret = self._exc_wrapper(args, options, func)(arg, kwarg=0)
except ExecutionErrorSubclass, e:
     handle_error(e)

As you can see, the resulting code is shorter and you don't have to 
remember to make changes to the arguments in two places.

Honza

-- 
Jan Cholasta
-------------- next part --------------
A non-text attachment was scrubbed...
Name: freeipa-jcholast-76-refactor-exc-callback.patch
Type: text/x-patch
Size: 22314 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20120423/e5b369dd/attachment.bin>


More information about the Freeipa-devel mailing list