[Freeipa-devel] [PATCH] radius work, please review
John Dennis
jdennis at redhat.com
Thu Nov 29 23:56:30 UTC 2007
Karl MacMillan wrote:
> On Thu, 2007-11-29 at 17:53 -0500, John Dennis wrote:
>> Karl MacMillan wrote:
>>> On Thu, 2007-11-29 at 16:15 -0500, Rob Crittenden wrote:
>>>> John Dennis wrote:
>>> [...]
>>>
>>>> 4. As you can see in each tool there is a bunch of duplicated code (all
>>>> the error catching at the end for example). Do you know of a way we can
>>>> generalize that in Python and put it into a client library?
>>> Decorators? (I think that is in python 2.4)
>> I'm pretty familiar with decorators, it's a nice feature, but I don't
>> think it has application in this context. Decorators can be used to add
>> meta-data to functions and/or alias the function to a specific use by
>> returning a runtime generated function which end up being a "proxy" for
>> the decorated function. This feature makes it wonderful for implementing
>> RPC. But perhaps I'm not following your vision of how a decorator might
>> be used to reduce the code duplication.
> Much of the error checking (especially for generic things like
> connection errors) could be added to functions through a decorator. So,
> for example, a function to add a user *would* check for duplicate users
> to generate nice error messages but would let generic errors bubble up
> and let them be caught by the decorator wrapper.
Thank you Karl for expanding my thinking, yes I see how this might work.
Here is a good article that explains the technique:
Python 2.4 Decorators
Reducing code duplication and consolidating knowledge
http://www.ddj.com/web-development/184406073
--
John Dennis <jdennis at redhat.com>
More information about the Freeipa-devel
mailing list