def compat(context, attr):
    """ Backwards compatible widget attribute access.

    In tw1, all template attributes looked like:
        ${some_attribute}

    Whereas in tw2 they look like:
        ${w.some_attribute}

    This is a *nuisance* if you want to reuse a template between tw1 and tw2
    widgets.  With this function you can write:
        <%namespace name="tw" module="tw2.core.mako_util"/>
        ${tw.compat(attr='some_attribute')}
    or
        ${tw._('some_attribute')}

    Nice, right? :)
    """
    if not 'w' in context.keys():
        return context.get(attr)
    else:
        return getattr(context.get('w'), attr)
