Re: multiple callbacks

"David Goodger" <[email protected]> Fri, 27 Jun 2008 10:26:47 -0400
Newsgroups gmane.comp.python.optik.user
Message-ID <[email protected]>
On Thu, Jun 26, 2008 at 20:17,  <[email protected]> wrote:
> So after reading through the docs and looking in the code a bit (gotta love
> open source), it occurred to me that it might be a "nice" feature to be
> able to provide multiple callbacks per option.

This is easy to do from your own code. Just define a closure function:

def multiple_callbacks(*callbacks):
    """Returns a callback that calls multiple callbacks."""
    def call_multiple_callbacks(option, opt, value, parser):
        for callback in callbacks:
            callback(option, opt, value, parser)
    return call_multiple_callbacks

OPTIONS_LIST = [
 make_option('-c', '--chroot', default=None,
     action='callback',
     callback=multiple_callbacks(check_path_exists, check_path_isdir),
     help="specifies the root of the chroot environment to work with"),
...

-- 
David Goodger <http://python.net/~goodger>

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php