how to find the last decorator of a chain

Aahz aahz at
Tue Jun 2 22:23:50 EDT 2009

In article <mailman.939.1243725387.8015.python-list at>,
Gabriel  <gabriel at> wrote:
>I have something like this:
>def view(format, data):
>  return data
>Each render will do something with 'data' if format match, and nothing
>if not.
>But if there is no more renders to eval, the last one is the default,
>and must run even if the format doesn't match.

My inclination would be to make this explicit with something like this:

def make_render(func, format_list):
    def tmp(format, data):
        for f in format_list:
            if MATCH(format, f):
    return tmp

def view(format, data):
    return data
view = make_render(view, ['a', 'b'])

IOW, just because we have decorators doesn't mean that they're the best
solution for all function-wrapping problems.
Aahz (aahz at           <*>

    on-a-new-machine-ly y'rs  - tim

More information about the Python-list mailing list