def view_or_basicauth(view, request, test_func, realm='', *args, **kwargs):
    "\n    This is a helper function used by both 'logged_in_or_basicauth' and\n    'has_perm_or_basicauth' that does the nitty of determining if they\n    are already logged in or if they have provided proper http-authorization\n    and returning the view if all goes well, otherwise responding with a 401.\n    "
    if test_func(request.user):
        return view(request, *args, **kwargs)
    if ('HTTP_AUTHORIZATION' in request.META):
        auth = request.META['HTTP_AUTHORIZATION'].split()
        if (len(auth) == 2):
            if (auth[0].lower() == 'basic'):
                (uname, passwd) = base64.b64decode(auth[1]).split(':')
                user = authenticate(username=uname, password=passwd)
                if (user is not None):
                    if user.is_active:
                        login(request, user)
                        request.user = user
                        return view(request, *args, **kwargs)
    response = HttpResponse()
    response.status_code = 401
    response['WWW-Authenticate'] = ('Basic realm="%s"' % realm)
    return response
This is a helper function used by both 'logged_in_or_basicauth' and
'has_perm_or_basicauth' that does the nitty of determining if they
are already logged in or if they have provided proper http-authorization
and returning the view if all goes well, otherwise responding with a 401.
def view_or_basicauth(view, request, test_func, realm=, *args, **kwargs):
    "\n    This is a helper function used by both 'logged_in_or_basicauth' and\n    'has_perm_or_basicauth' that does the nitty of determining if they\n    are already logged in or if they have provided proper http-authorization\n    and returning the view if all goes well, otherwise responding with a 401.\n    "
    if test_func(request.user):
        return view(request, *args, **kwargs)
    if ('HTTP_AUTHORIZATION' in request.META):
        auth = request.META['HTTP_AUTHORIZATION'].split()
        if (len(auth) == 2):
            if (auth[0].lower() == 'basic'):
                (uname, passwd) = base64.b64decode(auth[1]).split(':')
                user = authenticate(username=uname, password=passwd)
                if (user is not None):
                    if user.is_active:
                        login(request, user)
                        request.user = user
                        return view(request, *args, **kwargs)
    response = HttpResponse()
    response.status_code = 401
    response['WWW-Authenticate'] = ('Basic realm="%s"' % realm)
    return response