human
I wrote the below code

    def wrap(request, *args, **kwargs):
        'Wrap'
        if request.user.is_authenticated():
            user = request.user.profile
            user_modules = user.get_perspective().get_modules()
            all_modules = Module.objects.all()
            active = None
            for module in all_modules:
                try:
                    import_name = ((module.name + '.') + settings.HARDTREE_MODULE_IDENTIFIER)
                    hmodule = __import__(import_name, fromlist=[str(module.name)])
                    urls = hmodule.URL_PATTERNS
                    for regexp in urls:
                        if re.match(regexp, request.path):
                            active = module
                except ImportError:
                    pass
                except AttributeError:
                    pass
            if active:
                if (active in user_modules):
                    if user.has_permission(active):
                        return f(request, *args, **kwargs)
                    else:
                        if (request.path[:3] == '/m/'):
                            return HttpResponseRedirect('/m/user/denied')
                        return HttpResponseRedirect('/user/denied')
                else:
                    if (request.path[:3] == '/m/'):
                        return HttpResponseRedirect('/m/user/denied')
                    return HttpResponseRedirect('/user/denied')
            else:
                return f(request, *args, **kwargs)
        else:
            if (request.path[:3] == '/m/'):
                return HttpResponseRedirect('/m/accounts/login')
            if (('response_format' in kwargs) and (kwargs['response_format'] == 'rss')):
                if (('secret' in request.GET) and verify_secret_key(request)):
                    return f(request, *args, **kwargs)
            return HttpResponseRedirect('/accounts/login')
    wrap.__doc__ = f.__doc__
    wrap.__name__ = f.__name__
    return wrap

What's a good function header?
assistant
#Here's a good function header.

def treeio_login_required(f):