[Freeipa-devel] [PATCH] radius work, please review

Karl MacMillan kmacmill at redhat.com
Thu Nov 29 23:11:33 UTC 2007


On Thu, 2007-11-29 at 17:58 -0500, 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.
> 

And there is no reason that "main" functions in the scripts couldn't be
decorated.

Karl




More information about the Freeipa-devel mailing list