'Redirect to the /auth/ or a /setup/* endpoint'

def redirect_to_auth_or_setup(self, method, path, query_data, setup=True):

    from mailpile.plugins.setup_magic import Setup
    if (method.lower() == 'get'):
        qd = [(k, v) for (k, vl) in query_data.iteritems() for v in vl]
        if ('_path' not in query_data):
            qd.append(('_path', path))
    else:
        qd = []
    if setup:
        nxt = Setup.Next(self.session.config, mailpile.auth.Authenticate)
        if (nxt.HTTP_AUTH_REQUIRED is True):
            nxt = mailpile.auth.Authenticate
        path = ('/%s/' % nxt.SYNOPSIS[2])
    else:
        path = ('/%s/' % mailpile.auth.Authenticate.SYNOPSIS[2])
    raise UrlRedirectException(self._url(path, qs=urlencode(qd)))
