Do basic authentication, parse HTTP_AUTHORIZATION and set remote_user
    variable to request

def basic_auth_tween_factory(handler, registry):
    """Do basic authentication, parse HTTP_AUTHORIZATION and set remote_user
    variable to request

    """
    def basic_auth_tween(request):
        remote_user = get_remote_user(request)
        if remote_user is not None:
            request.environ['REMOTE_USER'] = remote_user[0]
        return handler(request)
    return basic_auth_tween